Skip to content

Commit 3ff676d

Browse files
authored
upgrade to 2.0.18 pdfbox
upgrade to 2.0.18
2 parents f344a16 + 245f0fa commit 3ff676d

File tree

732 files changed

+40484
-23076
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

732 files changed

+40484
-23076
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ An example app is located in the `sample` directory and includes examples of com
2929
Important notes
3030
==============
3131

32-
-Currently based on PdfBox v1.8.10
32+
-Currently based on PdfBox v2.0.18
3333

3434
-Requires API 19 or greater for full functionality
3535

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ buildscript {
77
google()
88
}
99
dependencies {
10-
classpath 'com.android.tools.build:gradle:3.3.1'
10+
classpath 'com.android.tools.build:gradle:3.3.2'
1111
classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4'
1212
}
1313
}

library/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ dependencies {
9090

9191
// Test dependencies
9292
testImplementation 'junit:junit:4.12'
93+
testImplementation group: 'com.googlecode.java-diff-utils', name: 'diffutils', version: '1.3.0'
9394
androidTestImplementation 'com.android.support.test:runner:1.0.2'
9495
}
9596

library/src/androidTest/java/com/tom_roush/pdfbox/encryption/TestPublicKeyEncryption.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,17 @@
1919
import android.content.Context;
2020
import android.support.test.InstrumentationRegistry;
2121

22+
import java.io.ByteArrayInputStream;
23+
import java.io.ByteArrayOutputStream;
24+
import java.io.IOException;
25+
import java.io.InputStream;
26+
import java.security.NoSuchAlgorithmException;
27+
import java.security.cert.CertificateFactory;
28+
import java.security.cert.X509Certificate;
29+
30+
import javax.crypto.Cipher;
31+
32+
import com.tom_roush.pdfbox.io.MemoryUsageSetting;
2233
import com.tom_roush.pdfbox.pdmodel.PDDocument;
2334
import com.tom_roush.pdfbox.pdmodel.encryption.AccessPermission;
2435
import com.tom_roush.pdfbox.pdmodel.encryption.PublicKeyProtectionPolicy;
@@ -30,16 +41,6 @@
3041
import org.junit.Before;
3142
import org.junit.Test;
3243

33-
import java.io.ByteArrayInputStream;
34-
import java.io.ByteArrayOutputStream;
35-
import java.io.IOException;
36-
import java.io.InputStream;
37-
import java.security.NoSuchAlgorithmException;
38-
import java.security.cert.CertificateFactory;
39-
import java.security.cert.X509Certificate;
40-
41-
import javax.crypto.Cipher;
42-
4344
import static org.junit.Assert.fail;
4445

4546
/**
@@ -77,7 +78,7 @@ public void setUp() throws Exception
7778
if (Cipher.getMaxAllowedKeyLength("AES") != Integer.MAX_VALUE)
7879
{
7980
// we need strong encryption for these tests
80-
// fail("JCE unlimited strength jurisdiction policy files are not installed");
81+
fail("JCE unlimited strength jurisdiction policy files are not installed");
8182
}
8283

8384
testContext = InstrumentationRegistry.getInstrumentation().getContext();
@@ -271,7 +272,7 @@ private PDDocument reload(PDDocument doc, String decryptionPassword, InputStream
271272
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
272273
doc.save(buffer);
273274
return PDDocument.load(new ByteArrayInputStream(buffer.toByteArray()), decryptionPassword,
274-
keyStore, null, false);
275+
keyStore, null, MemoryUsageSetting.setupMainMemoryOnly());
275276
}
276277

277278
/**

library/src/androidTest/java/com/tom_roush/pdfbox/encryption/TestSymmetricKeyEncryption.java

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,19 @@
2121
import android.support.test.InstrumentationRegistry;
2222
import android.util.Log;
2323

24+
import java.io.ByteArrayInputStream;
25+
import java.io.ByteArrayOutputStream;
26+
import java.io.File;
27+
import java.io.FileInputStream;
28+
import java.io.FileOutputStream;
29+
import java.io.IOException;
30+
import java.io.InputStream;
31+
import java.util.ArrayList;
32+
import java.util.List;
33+
import java.util.Map;
34+
35+
import javax.crypto.Cipher;
36+
2437
import com.tom_roush.pdfbox.io.IOUtils;
2538
import com.tom_roush.pdfbox.pdmodel.PDDocument;
2639
import com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog;
@@ -30,26 +43,14 @@
3043
import com.tom_roush.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile;
3144
import com.tom_roush.pdfbox.pdmodel.encryption.AccessPermission;
3245
import com.tom_roush.pdfbox.pdmodel.encryption.StandardProtectionPolicy;
46+
import com.tom_roush.pdfbox.pdmodel.graphics.image.ValidateXImage;
3347
import com.tom_roush.pdfbox.rendering.PDFRenderer;
3448
import com.tom_roush.pdfbox.util.PDFBoxResourceLoader;
3549

3650
import org.junit.Assert;
3751
import org.junit.Before;
3852
import org.junit.Test;
3953

40-
import java.io.ByteArrayInputStream;
41-
import java.io.ByteArrayOutputStream;
42-
import java.io.File;
43-
import java.io.FileInputStream;
44-
import java.io.FileOutputStream;
45-
import java.io.IOException;
46-
import java.io.InputStream;
47-
import java.util.ArrayList;
48-
import java.util.List;
49-
import java.util.Map;
50-
51-
import javax.crypto.Cipher;
52-
5354
import static org.junit.Assert.assertEquals;
5455
import static org.junit.Assert.fail;
5556

@@ -83,7 +84,7 @@ public void setUp() throws Exception
8384
if (Cipher.getMaxAllowedKeyLength("AES") != Integer.MAX_VALUE)
8485
{
8586
// we need strong encryption for these tests
86-
// fail("JCE unlimited strength jurisdiction policy files are not installed");
87+
fail("JCE unlimited strength jurisdiction policy files are not installed");
8788
}
8889

8990
testContext = InstrumentationRegistry.getInstrumentation().getContext();
@@ -151,18 +152,18 @@ public void testPermissions() throws Exception
151152
assertEquals("Cannot decrypt PDF, the password is incorrect", ex.getMessage());
152153
}
153154

154-
// inputFileAsByteArray = getFileResourceAsByteArray("PasswordSample-256bit.pdf");
155-
// checkPerms(inputFileAsByteArray, "owner", fullAP);
156-
// checkPerms(inputFileAsByteArray, "user", restrAP);
157-
// try
158-
// {
159-
// checkPerms(inputFileAsByteArray, "", null);
160-
// fail("wrong password not detected");
161-
// }
162-
// catch (IOException ex)
163-
// {
164-
// assertEquals("Cannot decrypt PDF, the password is incorrect", ex.getMessage());
165-
// } TODO: PdfBox-Android
155+
inputFileAsByteArray = getFileResourceAsByteArray("PasswordSample-256bit.pdf");
156+
checkPerms(inputFileAsByteArray, "owner", fullAP);
157+
checkPerms(inputFileAsByteArray, "user", restrAP);
158+
try
159+
{
160+
checkPerms(inputFileAsByteArray, "", null);
161+
fail("wrong password not detected");
162+
}
163+
catch (IOException ex)
164+
{
165+
assertEquals("Cannot decrypt PDF, the password is incorrect", ex.getMessage());
166+
}
166167
}
167168

168169
private void checkPerms(byte[] inputFileAsByteArray, String password,
@@ -186,7 +187,7 @@ private void checkPerms(byte[] inputFileAsByteArray, String password,
186187
assertEquals(expectedPermissions.canPrint(), currentAccessPermission.canPrint());
187188
assertEquals(expectedPermissions.canPrintDegraded(), currentAccessPermission.canPrintDegraded());
188189

189-
// new PDFRenderer(doc).renderImage(0); TODO: PdfBox-Android
190+
new PDFRenderer(doc).renderImage(0);
190191

191192
doc.close();
192193
}
@@ -209,8 +210,8 @@ public void testProtection() throws Exception
209210
testSymmEncrForKeySize(128, sizePriorToEncryption, inputFileAsByteArray,
210211
USERPASSWORD, OWNERPASSWORD, permission);
211212

212-
// testSymmEncrForKeySize(256, sizePriorToEncryption, inputFileAsByteArray,
213-
// USERPASSWORD, OWNERPASSWORD, permission); TODO: PdfBox-Android
213+
testSymmEncrForKeySize(256, sizePriorToEncryption, inputFileAsByteArray, USERPASSWORD,
214+
OWNERPASSWORD, permission);
214215
}
215216

216217
/**
@@ -236,8 +237,9 @@ public void testProtectionInnerAttachment() throws Exception
236237
testSymmEncrForKeySizeInner(128, sizeOfFileWithEmbeddedFile,
237238
inputFileWithEmbeddedFileAsByteArray, extractedEmbeddedFile, USERPASSWORD, OWNERPASSWORD);
238239

239-
// testSymmEncrForKeySizeInner(256, sizeOfFileWithEmbeddedFile,
240-
// inputFileWithEmbeddedFileAsByteArray, extractedEmbeddedFile, USERPASSWORD, OWNERPASSWORD); TODO: PdfBox-Android
240+
testSymmEncrForKeySizeInner(256, sizeOfFileWithEmbeddedFile,
241+
inputFileWithEmbeddedFileAsByteArray, extractedEmbeddedFile, USERPASSWORD,
242+
OWNERPASSWORD);
241243
}
242244

243245
private void testSymmEncrForKeySize(int keyLength,
@@ -253,7 +255,7 @@ private void testSymmEncrForKeySize(int keyLength,
253255
List<byte[]> srcContentStreamTab = new ArrayList<byte[]>();
254256
for (int i = 0; i < numSrcPages; ++i)
255257
{
256-
// srcImgTab.add(pdfRenderer.renderImage(i)); TODO: PdfBox-Android
258+
srcImgTab.add(pdfRenderer.renderImage(i));
257259
InputStream unfilteredStream = document.getPage(i).getContents();
258260
byte[] bytes = IOUtils.toByteArray(unfilteredStream);
259261
unfilteredStream.close();
@@ -268,8 +270,8 @@ private void testSymmEncrForKeySize(int keyLength,
268270
for (int i = 0; i < encryptedDoc.getNumberOfPages(); ++i)
269271
{
270272
// compare rendering
271-
// Bitmap bim = pdfRenderer.renderImage(i);
272-
// ValidateXImage.checkIdent(bim, srcImgTab.get(i)); TODO: PdfBox-Android
273+
Bitmap bim = pdfRenderer.renderImage(i);
274+
ValidateXImage.checkIdent(bim, srcImgTab.get(i));
273275

274276
// compare content streams
275277
InputStream unfilteredStream = encryptedDoc.getPage(i).getContents();

library/src/androidTest/java/com/tom_roush/pdfbox/multipdf/PDFMergerUtilityTest.java

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.io.File;
2323
import java.io.IOException;
2424

25+
import com.tom_roush.pdfbox.io.MemoryUsageSetting;
2526
import com.tom_roush.pdfbox.pdmodel.PDDocument;
2627
import com.tom_roush.pdfbox.rendering.PDFRenderer;
2728
import com.tom_roush.pdfbox.util.PDFBoxResourceLoader;
@@ -72,14 +73,29 @@ public void testPDFMergerUtility() throws IOException
7273
{
7374
checkMergeIdentical("PDFBox.GlobalResourceMergeTest.Doc01.decoded.pdf",
7475
"PDFBox.GlobalResourceMergeTest.Doc02.decoded.pdf",
75-
"GlobalResourceMergeTestResult.pdf",
76-
false);
76+
"GlobalResourceMergeTestResult.pdf", MemoryUsageSetting.setupMainMemoryOnly());
7777

7878
// once again, with scratch file
7979
checkMergeIdentical("PDFBox.GlobalResourceMergeTest.Doc01.decoded.pdf",
8080
"PDFBox.GlobalResourceMergeTest.Doc02.decoded.pdf",
81-
"GlobalResourceMergeTestResult2.pdf",
82-
true);
81+
"GlobalResourceMergeTestResult2.pdf", MemoryUsageSetting.setupTempFileOnly());
82+
}
83+
84+
/**
85+
* Tests whether the merge of two PDF files with JPEG and CCITT works. A few revisions before
86+
* 1704911 this test failed because the clone utility attempted to decode and re-encode the
87+
* streams, see PDFBOX-2893 on 23.9.2015.
88+
*
89+
* @throws IOException if something goes wrong.
90+
*/
91+
public void testJpegCcitt() throws IOException
92+
{
93+
checkMergeIdentical("jpegrgb.pdf", "multitiff.pdf", "JpegMultiMergeTestResult.pdf",
94+
MemoryUsageSetting.setupMainMemoryOnly());
95+
96+
// once again, with scratch file
97+
checkMergeIdentical("jpegrgb.pdf", "multitiff.pdf", "JpegMultiMergeTestResult.pdf",
98+
MemoryUsageSetting.setupTempFileOnly());
8399
}
84100

85101
// see PDFBOX-2893
@@ -88,21 +104,18 @@ public void testPDFMergerUtility2() throws IOException
88104
{
89105
checkMergeIdentical("PDFBox.GlobalResourceMergeTest.Doc01.pdf",
90106
"PDFBox.GlobalResourceMergeTest.Doc02.pdf",
91-
"GlobalResourceMergeTestResult.pdf",
92-
false);
107+
"GlobalResourceMergeTestResult.pdf", MemoryUsageSetting.setupMainMemoryOnly());
93108

94109
// once again, with scratch file
95110
checkMergeIdentical("PDFBox.GlobalResourceMergeTest.Doc01.pdf",
96111
"PDFBox.GlobalResourceMergeTest.Doc02.pdf",
97-
"GlobalResourceMergeTestResult2.pdf",
98-
true);
112+
"GlobalResourceMergeTestResult2.pdf", MemoryUsageSetting.setupTempFileOnly());
99113
}
100114

101115
// checks that the result file of a merge has the same rendering as the two
102116
// source files
103117
private void checkMergeIdentical(String filename1, String filename2, String mergeFilename,
104-
boolean useScratchFiles)
105-
throws IOException
118+
MemoryUsageSetting memUsageSetting) throws IOException
106119
{
107120
PDDocument srcDoc1 = PDDocument.load(testContext.getAssets().open(SRCDIR + "/" + filename1), (String) null);
108121
int src1PageCount = srcDoc1.getNumberOfPages();
@@ -128,7 +141,7 @@ private void checkMergeIdentical(String filename1, String filename2, String merg
128141
pdfMergerUtility.addSource(testContext.getAssets().open(SRCDIR + "/" + filename1));
129142
pdfMergerUtility.addSource(testContext.getAssets().open(SRCDIR + "/" + filename2));
130143
pdfMergerUtility.setDestinationFileName(TARGETTESTDIR + mergeFilename);
131-
pdfMergerUtility.mergeDocuments(useScratchFiles);
144+
pdfMergerUtility.mergeDocuments(memUsageSetting);
132145

133146
PDDocument mergedDoc
134147
= PDDocument.load(new File(TARGETTESTDIR, mergeFilename), (String) null);

library/src/androidTest/java/com/tom_roush/pdfbox/pdmodel/graphics/image/CCITTFactoryTest.java

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
import android.content.Context;
1919
import android.support.test.InstrumentationRegistry;
2020

21+
import java.io.File;
22+
import java.io.IOException;
23+
2124
import com.tom_roush.pdfbox.io.RandomAccessBuffer;
2225
import com.tom_roush.pdfbox.pdmodel.PDDocument;
2326
import com.tom_roush.pdfbox.pdmodel.PDPage;
@@ -29,9 +32,6 @@
2932
import org.junit.Before;
3033
import org.junit.Test;
3134

32-
import java.io.File;
33-
import java.io.IOException;
34-
3535
import static com.tom_roush.pdfbox.pdmodel.graphics.image.ValidateXImage.validate;
3636
import static org.junit.Assert.assertEquals;
3737

@@ -73,7 +73,8 @@ public void testCreateFromRandomAccessSingle() throws IOException
7373
// checkIdent(bim3, ximage3.getOpaqueImage());
7474
PDPage page = new PDPage(PDRectangle.A4);
7575
document.addPage(page);
76-
PDPageContentStream contentStream = new PDPageContentStream(document, page, true, false);
76+
PDPageContentStream contentStream = new PDPageContentStream(document, page,
77+
PDPageContentStream.AppendMode.APPEND, false);
7778
contentStream.drawImage(ximage3, 0, 0, ximage3.getWidth(), ximage3.getHeight());
7879
contentStream.close();
7980

@@ -84,7 +85,8 @@ public void testCreateFromRandomAccessSingle() throws IOException
8485
// checkIdent(bim4, ximage4.getOpaqueImage());
8586
page = new PDPage(PDRectangle.A4);
8687
document.addPage(page);
87-
contentStream = new PDPageContentStream(document, page, true, false);
88+
contentStream = new PDPageContentStream(document, page,
89+
PDPageContentStream.AppendMode.APPEND, false);
8890
contentStream.drawImage(ximage4, 0, 0);
8991
contentStream.close();
9092

@@ -131,7 +133,8 @@ public void testCreateFromRandomAccessMulti() throws IOException
131133
float fY = ximage.getHeight() / page.getMediaBox().getHeight();
132134
float factor = Math.max(fX, fY);
133135
document.addPage(page);
134-
PDPageContentStream contentStream = new PDPageContentStream(document, page, true, false);
136+
PDPageContentStream contentStream = new PDPageContentStream(document, page,
137+
PDPageContentStream.AppendMode.APPEND, false);
135138
contentStream.drawImage(ximage, 0, 0, ximage.getWidth() / factor, ximage.getHeight() / factor);
136139
contentStream.close();
137140
++pdfPageNum;

0 commit comments

Comments
 (0)