use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class PDFCloneUtilityTest method testClonePDFWithCosArrayStream2.
/**
* broader test that saves to a real PDF document.
*
* @throws IOException
*/
public void testClonePDFWithCosArrayStream2() throws IOException {
final String TESTDIR = "target/test-output/clone/";
final String CLONESRC = "clone-src.pdf";
final String CLONEDST = "clone-dst.pdf";
new File(TESTDIR).mkdirs();
PDDocument srcDoc = new PDDocument();
PDPage pdPage = new PDPage();
srcDoc.addPage(pdPage);
PDPageContentStream pdPageContentStream1 = new PDPageContentStream(srcDoc, pdPage, AppendMode.APPEND, false);
pdPageContentStream1.setNonStrokingColor(AWTColor.black);
pdPageContentStream1.addRect(100, 600, 300, 100);
pdPageContentStream1.fill();
pdPageContentStream1.close();
PDPageContentStream pdPageContentStream2 = new PDPageContentStream(srcDoc, pdPage, AppendMode.APPEND, false);
pdPageContentStream2.setNonStrokingColor(AWTColor.red);
pdPageContentStream2.addRect(100, 500, 300, 100);
pdPageContentStream2.fill();
pdPageContentStream2.close();
PDPageContentStream pdPageContentStream3 = new PDPageContentStream(srcDoc, pdPage, AppendMode.APPEND, false);
pdPageContentStream3.setNonStrokingColor(AWTColor.yellow);
pdPageContentStream3.addRect(100, 400, 300, 100);
pdPageContentStream3.fill();
pdPageContentStream3.close();
srcDoc.save(TESTDIR + CLONESRC);
PDFMergerUtility merger = new PDFMergerUtility();
PDDocument dstDoc = new PDDocument();
// this calls PDFCloneUtility.cloneForNewDocument(),
// which would fail before the fix in PDFBOX-2052
merger.appendDocument(dstDoc, srcDoc);
// save and reload PDF, so that one can see that the files are legit
dstDoc.save(TESTDIR + CLONEDST);
PDDocument.load(new File(TESTDIR + CLONESRC)).close();
PDDocument.load(new File(TESTDIR + CLONESRC), (String) null).close();
PDDocument.load(new File(TESTDIR + CLONEDST)).close();
PDDocument.load(new File(TESTDIR + CLONEDST), (String) null).close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestPDFParser method testPDFBox3785.
/**
* PDFBOX-3785, PDFBOX-3957:
* Test whether truncated file with several revisions has correct page count.
*
* @throws IOException
*/
// TODO: PdfBox-Android - provide test file
@Test
public void testPDFBox3785() throws IOException {
File testPdf = new File(TARGETPDFDIR, "PDFBOX-3785-202097.pdf");
assumeTrue(testPdf.exists());
PDDocument doc = PDDocument.load(testPdf);
assertEquals(11, doc.getNumberOfPages());
doc.close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestPDFParser method testPDFBox3964.
/**
* PDFBOX-3964: test parsing of broken file.
*
* @throws IOException
*/
// TODO: PdfBox-Android - provide test file
@Test
public void testPDFBox3964() throws IOException {
File testPdf = new File(TARGETPDFDIR, "PDFBOX-3964-c687766d68ac766be3f02aaec5e0d713_2.pdf");
assumeTrue(testPdf.exists());
PDDocument doc = PDDocument.load(testPdf);
assertEquals(10, doc.getNumberOfPages());
doc.close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestPDFParser method testPDFBox3951.
// testPDFBox3950 is an instrumentation test
/**
* PDFBOX-3951: test parsing of truncated file.
*
* @throws IOException
*/
// TODO: PdfBox-Android - provide test file
@Test
public void testPDFBox3951() throws IOException {
File testPdf = new File(TARGETPDFDIR, "PDFBOX-3951-FIHUZWDDL2VGPOE34N6YHWSIGSH5LVGZ.pdf");
assumeTrue(testPdf.exists());
PDDocument doc = PDDocument.load(testPdf);
assertEquals(143, doc.getNumberOfPages());
doc.close();
}
use of com.tom_roush.pdfbox.pdmodel.PDDocument in project PdfBox-Android by TomRoush.
the class TestPDFParser method testPDFBox3977.
/**
* Test whether /Info dictionary is retrieved correctly in brute force search for the
* Info/Catalog dictionaries.
*
* @throws IOException
*/
// TODO: PdfBox-Android - provide test file
@Test
public void testPDFBox3977() throws IOException {
File testPdf = new File(TARGETPDFDIR, "PDFBOX-3977-63NGFQRI44HQNPIPEJH5W2TBM6DJZWMI.pdf");
assumeTrue(testPdf.exists());
PDDocument doc = PDDocument.load(testPdf);
PDDocumentInformation di = doc.getDocumentInformation();
assertEquals("QuarkXPress(tm) 6.52", di.getCreator());
assertEquals("Acrobat Distiller 7.0 pour Macintosh", di.getProducer());
assertEquals("Fich sal Fabr corr1 (Page 6)", di.getTitle());
assertEquals(DateConverter.toCalendar("D:20070608151915+02'00'"), di.getCreationDate());
assertEquals(DateConverter.toCalendar("D:20080604152122+02'00'"), di.getModificationDate());
doc.close();
}
Aggregations