Search in sources :

Example 86 with PDDocument

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();
}
Also used : PDPage(com.tom_roush.pdfbox.pdmodel.PDPage) PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) PDPageContentStream(com.tom_roush.pdfbox.pdmodel.PDPageContentStream) File(java.io.File)

Example 87 with PDDocument

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();
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) File(java.io.File) ScratchFile(com.tom_roush.pdfbox.io.ScratchFile) Test(org.junit.Test)

Example 88 with PDDocument

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();
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) File(java.io.File) ScratchFile(com.tom_roush.pdfbox.io.ScratchFile) Test(org.junit.Test)

Example 89 with PDDocument

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();
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) File(java.io.File) ScratchFile(com.tom_roush.pdfbox.io.ScratchFile) Test(org.junit.Test)

Example 90 with PDDocument

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();
}
Also used : PDDocument(com.tom_roush.pdfbox.pdmodel.PDDocument) File(java.io.File) ScratchFile(com.tom_roush.pdfbox.io.ScratchFile) PDDocumentInformation(com.tom_roush.pdfbox.pdmodel.PDDocumentInformation) Test(org.junit.Test)

Aggregations

PDDocument (com.tom_roush.pdfbox.pdmodel.PDDocument)137 File (java.io.File)80 Test (org.junit.Test)69 PDPage (com.tom_roush.pdfbox.pdmodel.PDPage)37 PDPageContentStream (com.tom_roush.pdfbox.pdmodel.PDPageContentStream)22 InputStream (java.io.InputStream)21 Bitmap (android.graphics.Bitmap)18 IOException (java.io.IOException)14 PDResources (com.tom_roush.pdfbox.pdmodel.PDResources)11 PDFRenderer (com.tom_roush.pdfbox.rendering.PDFRenderer)11 ArrayList (java.util.ArrayList)11 PDDocumentCatalog (com.tom_roush.pdfbox.pdmodel.PDDocumentCatalog)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 FileInputStream (java.io.FileInputStream)9 FileOutputStream (java.io.FileOutputStream)9 COSArray (com.tom_roush.pdfbox.cos.COSArray)8 PDEmbeddedFile (com.tom_roush.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile)8 PDFont (com.tom_roush.pdfbox.pdmodel.font.PDFont)8 COSDictionary (com.tom_roush.pdfbox.cos.COSDictionary)7 Paint (android.graphics.Paint)6