Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade dependencies versions (slf4j, hsqldb, logback-xx) and close PRs #97

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/com/itextpdf/rups/Rups.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void run() {

static void initApplication(JFrame frame, RupsController controller, final int onCloseOperation) {
// title bar
frame.setTitle("iText RUPS " + ITextCoreProductData.getInstance().getVersion());
frame.setTitle("☠️ iText RUPS " + ITextCoreProductData.getInstance().getVersion());
frame.setIconImages(FrameIconUtil.loadFrameIcons());
frame.setDefaultCloseOperation(onCloseOperation);
// the content
Expand Down
26 changes: 22 additions & 4 deletions src/main/java/com/itextpdf/rups/controller/RupsController.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,13 @@ This file is part of the iText (R) project.

import com.itextpdf.kernel.actions.data.ITextCoreProductData;
import com.itextpdf.kernel.exceptions.PdfException;
import com.itextpdf.kernel.pdf.CompressionConstants;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfNumber;
import com.itextpdf.kernel.pdf.PdfObject;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfStream;
import com.itextpdf.kernel.utils.CompareTool;
import com.itextpdf.rups.event.*;
import com.itextpdf.rups.model.*;
Expand Down Expand Up @@ -304,7 +309,7 @@ public void loadRawContent(byte[] contents, String fileName, File directory, boo
startObjectLoader();
if (!pluginMode) {
String directoryPath = directory == null ? "" : directory.getCanonicalPath() + File.separator;
ownedFrame.setTitle("iText RUPS - " + directoryPath + fileName + " - " + ITextCoreProductData.getInstance().getVersion());
ownedFrame.setTitle("☠️ iText RUPS - " + directoryPath + fileName + " - " + ITextCoreProductData.getInstance().getVersion());
}
readerController.getParser().setDocument(pdfFile.getPdfDocument());
} catch (IOException | PdfException | com.itextpdf.io.exceptions.IOException ioe) {
Expand Down Expand Up @@ -406,14 +411,27 @@ public void closeRoutine() {
setChanged();
super.notifyObservers(new CloseDocumentEvent());
if (docToClose != null) {
docToClose.getWriter().setCompressionLevel(0);
uncompressStreams(docToClose);
docToClose.close();
}
if (!pluginMode) {
ownedFrame.setTitle("iText RUPS " + ITextCoreProductData.getInstance().getVersion());
ownedFrame.setTitle("☠️ iText RUPS " + ITextCoreProductData.getInstance().getVersion());
}
readerController.getParser().setDocument(null);
}

private static void uncompressStreams(PdfDocument document) {
PdfNumber num = document.getTrailer().getAsNumber(PdfName.Size);
int xrefSize = num != null ? num.intValue() : 64000;
for (int i = 1; i < xrefSize; i++) {
PdfObject object = document.getPdfObject(i);
if (object != null && object.isStream()) {
((PdfStream) object).setCompressionLevel(CompressionConstants.NO_COMPRESSION);
}
}
}

public CompareTool.CompareResult compareWithDocument(PdfDocument document) {
if (getPdfFile() == null || getPdfFile().getPdfDocument() == null) {
LoggerHelper.warn(LoggerMessages.NO_OPEN_DOCUMENT, getClass());
Expand All @@ -429,7 +447,7 @@ public CompareTool.CompareResult compareWithDocument(PdfDocument document) {
}

public CompareTool.CompareResult compareWithFile(File file) {
try (PdfReader readerPdf = new PdfReader(file.getAbsolutePath());
try (PdfReader readerPdf = new PdfReader(file.getAbsolutePath()).setUnethicalReading(true);
PdfDocument cmpDocument = new PdfDocument(readerPdf)) {
return compareWithDocument(cmpDocument);
} catch (IOException e) {
Expand All @@ -439,7 +457,7 @@ public CompareTool.CompareResult compareWithFile(File file) {
}

public CompareTool.CompareResult compareWithStream(InputStream is) {
try (PdfReader reader = new PdfReader(is);
try (PdfReader reader = new PdfReader(is).setUnethicalReading(true);
PdfDocument cmpDocument = new PdfDocument(reader)) {
reader.setCloseStream(false);
return compareWithDocument(cmpDocument);
Expand Down
22 changes: 17 additions & 5 deletions src/main/java/com/itextpdf/rups/model/PdfFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,25 @@ This file is part of the iText (R) project.

import com.itextpdf.kernel.exceptions.BadPasswordException;
import com.itextpdf.kernel.exceptions.PdfException;
import com.itextpdf.kernel.pdf.CompressionConstants;
import com.itextpdf.kernel.pdf.PdfDocument;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.PdfWriter;
import com.itextpdf.kernel.pdf.ReaderProperties;
import com.itextpdf.kernel.pdf.WriterProperties;

import com.ibm.icu.text.StringPrepParseException;
import com.ibm.icu.text.StringPrep;
import javax.swing.*;
import java.io.*;
import com.ibm.icu.text.StringPrepParseException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
import javax.swing.JOptionPane;
import javax.swing.JPasswordField;

/**
* Wrapper for both iText's PdfReader (referring to a PDF file to read)
Expand Down Expand Up @@ -186,12 +195,15 @@ protected void readFile(InputStream fis, boolean checkPass, boolean readOnly) th
} else {
password = null;
}
reader = new PdfReader(fis, readerProps);
reader = new PdfReader(fis, readerProps).setUnethicalReading(true);
baos = new ByteArrayOutputStream();
if (readOnly) {
document = new PdfDocument(reader);
} else {
writer = new PdfWriter(baos);
//TODO: change writer mechanism
writer = new PdfWriter(baos,
new WriterProperties().setCompressionLevel(CompressionConstants.NO_COMPRESSION)
.setFullCompressionMode(false));
document = new PdfDocument(reader, writer);
}
// we have some extra work to do if the document was encrypted
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/com/itextpdf/rups/view/itext/FormTreeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ This file is part of the iText (R) project.
import com.itextpdf.kernel.pdf.PdfName;
import com.itextpdf.kernel.pdf.PdfObject;
import com.itextpdf.kernel.pdf.PdfReader;
import com.itextpdf.kernel.pdf.ReaderProperties;
import com.itextpdf.rups.controller.PdfReaderController;
import com.itextpdf.rups.model.IndirectObjectFactory;
import com.itextpdf.rups.model.TreeNodeFactory;
Expand All @@ -68,7 +69,7 @@ public class FormTreeTest extends ExtendedITextTest {
public void testLoadXfa() throws IOException {
File inPdf = new File(sourceFolder + "cmp_purchase_order_filled.pdf");

PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf));
PdfDocument pdfDocument = new PdfDocument(new PdfReader(inPdf).setUnethicalReading(true));

IndirectObjectFactory indirectObjectFactory = new IndirectObjectFactory(pdfDocument);
while (indirectObjectFactory.storeNextObject());
Expand Down