Skip to content

Commit 4d20593

Browse files
committed
PDFBOX-6036: rename test to reference the correct ticket, add test for writing without compression
git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1930699 13f79535-47bb-0310-9956-ffa450edef68
1 parent 37f5daa commit 4d20593

File tree

1 file changed

+28
-4
lines changed

1 file changed

+28
-4
lines changed

pdfbox/src/test/java/org/apache/pdfbox/pdfwriter/COSWriterTest.java

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,14 @@ private static byte[] edit(byte[] input) throws IOException
152152
}
153153
}
154154

155+
/**
156+
* Test if overlapping object numbers are eliminated when merging pdfs.
157+
*
158+
* @throws IOException
159+
* @throws URISyntaxException
160+
*/
155161
@Test
156-
void testPDFBox5752() throws IOException, URISyntaxException
162+
void testPDFBox6036() throws IOException, URISyntaxException
157163
{
158164
URL emptyURL = new URI(
159165
"https://issues.apache.org/jira/secure/attachment/13066015/empty.pdf").toURL();
@@ -166,21 +172,39 @@ void testPDFBox5752() throws IOException, URISyntaxException
166172
emptyPDF = isEmpty.readAllBytes();
167173
roboPDF = isRobo.readAllBytes();
168174
}
169-
ByteArrayOutputStream baos = new ByteArrayOutputStream();
175+
// write merge result using compressed streams
176+
ByteArrayOutputStream baosCompressed = new ByteArrayOutputStream();
170177
try (PDDocument targetDoc = Loader.loadPDF(emptyPDF);
171178
PDDocument doc2 = Loader.loadPDF(roboPDF))
172179
{
173180
PDPage sourcePage = doc2.getPage(0);
174181
targetDoc.importPage(sourcePage);
175-
targetDoc.save(baos);
182+
targetDoc.save(baosCompressed);
176183
}
177-
try (PDDocument targetDoc = Loader.loadPDF(baos.toByteArray()))
184+
try (PDDocument targetDoc = Loader.loadPDF(baosCompressed.toByteArray()))
178185
{
179186
assertNotNull(targetDoc.getDocumentCatalog().getStructureTreeRoot());
180187
PDResources res = targetDoc.getPage(1).getResources();
181188
assertEquals("BCDEEE+Roboto-Regular", res.getFont(COSName.getPDFName("F1")).getName());
182189
assertEquals("BCDFEE+Roboto-Regular", res.getFont(COSName.getPDFName("F2")).getName());
183190
}
191+
// write merge result without compressed streams
192+
ByteArrayOutputStream baosUncompressed = new ByteArrayOutputStream();
193+
try (PDDocument targetDoc = Loader.loadPDF(emptyPDF);
194+
PDDocument doc2 = Loader.loadPDF(roboPDF))
195+
{
196+
PDPage sourcePage = doc2.getPage(0);
197+
targetDoc.importPage(sourcePage);
198+
targetDoc.save(baosUncompressed, CompressParameters.NO_COMPRESSION);
199+
}
200+
try (PDDocument targetDoc = Loader.loadPDF(baosUncompressed.toByteArray()))
201+
{
202+
assertNotNull(targetDoc.getDocumentCatalog().getStructureTreeRoot());
203+
PDResources res = targetDoc.getPage(1).getResources();
204+
assertEquals("BCDEEE+Roboto-Regular", res.getFont(COSName.getPDFName("F1")).getName());
205+
assertEquals("BCDFEE+Roboto-Regular", res.getFont(COSName.getPDFName("F2")).getName());
206+
}
207+
184208
}
185209

186210
}

0 commit comments

Comments
 (0)