|
| 1 | +package com.itextpdf.kernel.pdf; |
| 2 | + |
| 3 | +import com.itextpdf.kernel.utils.CompareTool; |
| 4 | +import com.itextpdf.test.annotations.type.IntegrationTest; |
| 5 | +import org.junit.Assert; |
| 6 | +import org.junit.BeforeClass; |
| 7 | +import org.junit.Test; |
| 8 | +import org.junit.experimental.categories.Category; |
| 9 | + |
| 10 | +import java.io.IOException; |
| 11 | + |
| 12 | +import static com.itextpdf.test.ITextTest.createDestinationFolder; |
| 13 | + |
| 14 | +/** |
| 15 | + * This test checks correct handling of pdf documents with (slightly) corrupt XREF table |
| 16 | + * xref |
| 17 | + * 0 30 |
| 18 | + * 0000000000 65535 f |
| 19 | + * 0000000000 65535 f |
| 20 | + */ |
| 21 | +@Category(IntegrationTest.class) |
| 22 | +public class CorruptXRefTest { |
| 23 | + |
| 24 | + public static final String sourceFolder = "./src/test/resources/com/itextpdf/kernel/pdf/CorruptXRefTest/"; |
| 25 | + public static final String outputFolder = "./target/test/com/itextpdf/kernel/pdf/CorruptXRefTest/"; |
| 26 | + |
| 27 | + @BeforeClass |
| 28 | + public static void beforeClass() { |
| 29 | + createDestinationFolder(outputFolder); |
| 30 | + } |
| 31 | + |
| 32 | + @Test |
| 33 | + public void readPdfWithCorruptXRef() throws IOException, InterruptedException { |
| 34 | + String cmpFile = sourceFolder + "cmp_docOut.pdf"; |
| 35 | + String outputFile = outputFolder + "docOut.pdf"; |
| 36 | + String inputFile = sourceFolder + "docIn.pdf"; |
| 37 | + PdfWriter writer = new PdfWriter(outputFile); |
| 38 | + |
| 39 | + PdfReader reader = new PdfReader(inputFile); |
| 40 | + |
| 41 | + PdfDocument inputPdfDocument = new PdfDocument(reader); |
| 42 | + PdfDocument outputPdfDocument = new PdfDocument(writer); |
| 43 | + |
| 44 | + int lastPage = inputPdfDocument.getNumberOfPages(); |
| 45 | + inputPdfDocument.copyPagesTo(lastPage, lastPage, outputPdfDocument); |
| 46 | + |
| 47 | + inputPdfDocument.close(); |
| 48 | + outputPdfDocument.close(); |
| 49 | + |
| 50 | + Assert.assertNull(new CompareTool().compareByContent(outputFolder + "docOut.pdf", cmpFile, outputFolder, "diff_")); |
| 51 | + |
| 52 | + } |
| 53 | +} |
0 commit comments