Package org.apache.pdfbox.rendering

Examples of org.apache.pdfbox.rendering.PDFRenderer


                }

                // render the pages
                boolean success = true;
                int numPages = document.getNumberOfPages();
                PDFRenderer renderer = new PDFRenderer(document);
                for (int i = startPage - 1; i < endPage && i < numPages; i++)
                {
                    BufferedImage image = renderer.renderImageWithDPI(i, dpi, imageType);
                    String fileName = outputPrefix + (i + 1) + "." + imageFormat;                   
                    success &= ImageIOUtil.writeImage(image, fileName, dpi);
                }

                if (!success)
View Full Code Here


                {
                    System.err.println("Error: The document is encrypted.");
                }
            }
        }
        renderer = new PDFRenderer(document);
    }
View Full Code Here

        assertEquals(expectedPermissions.canModify(), currentAccessPermission.canModify());
        assertEquals(expectedPermissions.canModifyAnnotations(), currentAccessPermission.canModifyAnnotations());
        assertEquals(expectedPermissions.canPrint(), currentAccessPermission.canPrint());
        assertEquals(expectedPermissions.canPrintDegraded(), currentAccessPermission.canPrintDegraded());

        new PDFRenderer(doc).renderImage(0);

        doc.close();
    }
View Full Code Here

            AccessPermission permission, boolean nonSeq) throws IOException
    {
        PDDocument document = PDDocument.load(new ByteArrayInputStream(inputFileAsByteArray));
        String prefix = "Simple-";
        int numSrcPages = document.getNumberOfPages();
        PDFRenderer pdfRenderer = new PDFRenderer(document);
        ArrayList<BufferedImage> srcImgTab = new ArrayList<BufferedImage>();
        ArrayList<ByteArrayOutputStream> srcContentStreamTab = new ArrayList<ByteArrayOutputStream>();
        for (int i = 0; i < numSrcPages; ++i)
        {
            srcImgTab.add(pdfRenderer.renderImage(i));
            COSStream contentStream = document.getPage(i).getContentStream();
            InputStream unfilteredStream = contentStream.getUnfilteredStream();
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            IOUtils.copy(unfilteredStream, baos);
            unfilteredStream.close();
            srcContentStreamTab.add(baos);
        }

        PDDocument encryptedDoc = encrypt(keyLength, sizePriorToEncr, document,
                prefix, permission, nonSeq, userpassword, ownerpassword);

        Assert.assertEquals(numSrcPages, encryptedDoc.getNumberOfPages());
        pdfRenderer = new PDFRenderer(encryptedDoc);
        for (int i = 0; i < encryptedDoc.getNumberOfPages(); ++i)
        {
            // compare rendering
            BufferedImage bim = pdfRenderer.renderImage(i);
            ValidateXImage.checkIdent(bim, srcImgTab.get(i));

            // compare content streams
            COSStream contentStreamDecr = encryptedDoc.getPage(i).getContentStream();
            InputStream unfilteredStream = contentStreamDecr.getUnfilteredStream();
View Full Code Here

    {
        PDDocument doc = null;
        try
        {
            doc = PDDocument.load(PDFontTest.class.getResourceAsStream("F001u_3_7j.pdf"));
            PDFRenderer renderer = new PDFRenderer(doc);
            renderer.renderImage(0);
            // the allegation is that renderImage() will crash the JVM or hang
        }
        finally
        {
            if (doc != null)
View Full Code Here

    {
        PDDocument doc = null;
        try
        {
            doc = PDDocument.load(PDFontTest.class.getResourceAsStream("256.pdf"));
            PDFRenderer renderer = new PDFRenderer(doc);
            renderer.renderImage(0);
            // the allegation is that renderImage() will crash the JVM or hang
        }
        finally
        {
            if (doc != null)
View Full Code Here

    }

    private void writeImage(PDDocument document, String imageFormat, String outputPrefix,
            ImageType imageType, float dpi) throws IOException
    {
        PDFRenderer renderer = new PDFRenderer(document);
        BufferedImage image = renderer.renderImageWithDPI(0, dpi, imageType);
        String fileName = outputPrefix + 1;
        LOG.info("Writing: " + fileName + "." + imageFormat);
        System.out.println("  " + fileName + "." + imageFormat); // for Maven (keep me!)
        boolean res = ImageIOUtil.writeImage(image, fileName + "." + imageFormat, Math.round(dpi));
        assertTrue("ImageIOUtil.writeImage() failed for file " + fileName, res);
View Full Code Here

        File pdfFile = new File(testResultsDir, "misc.pdf");
        document.save(pdfFile);
        document.close();
       
        document = PDDocument.loadNonSeq(pdfFile, null);
        new PDFRenderer(document).renderImage(0);
        document.close();
    }
View Full Code Here

        contentStream.close();
        File pdfFile = new File(testResultsDir, pdfFilename);
        document.save(pdfFile);
        document.close();
        document = PDDocument.loadNonSeq(pdfFile, null);
        new PDFRenderer(document).renderImage(0);
        document.close();
    }
View Full Code Here

            document.save(file);
            document.close();
           
            // render the PDF and save it into a PNG file
            document = PDDocument.loadNonSeq(new File(file));
            BufferedImage bim = new PDFRenderer(document).renderImageWithDPI(0, 300);
            ImageIO.write(bim, "png", new File(file + ".png"));
            document.close();
        }
        finally
        {
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.rendering.PDFRenderer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.