Package org.apache.pdfbox.pdmodel

Examples of org.apache.pdfbox.pdmodel.PDPage


{
    public void testSetCmykColors() throws IOException
    {
        PDDocument doc = new PDDocument();

        PDPage page = new PDPage();
        doc.addPage(page);

        PDPageContentStream contentStream = new PDPageContentStream(doc, page, false, true);
        // pass a non-stroking color in CMYK color space
        contentStream.setNonStrokingColor(0.1f, 0.2f, 0.3f, 0.4f);
        contentStream.close();

        // now read the PDF stream and verify that the CMYK values are correct
        COSStream stream = page.getStream().getStream();
        PDFStreamParser parser = new PDFStreamParser(stream);
        parser.parse();
        java.util.List<Object>  pageTokens = parser.getTokens();
        // expected five tokens :
        // [0] = COSFloat{0.1}
        // [1] = COSFloat{0.2}
        // [2] = COSFloat{0.3}
        // [3] = COSFloat{0.4}
        // [4] = PDFOperator{"k"}
        assertEquals(0.1f, ((COSFloat)pageTokens.get(0)).floatValue());
        assertEquals(0.2f, ((COSFloat)pageTokens.get(1)).floatValue());
        assertEquals(0.3f, ((COSFloat)pageTokens.get(2)).floatValue());
        assertEquals(0.4f, ((COSFloat)pageTokens.get(3)).floatValue());
        assertEquals("k", ((Operator) pageTokens.get(4)).getName());

        // same as above but for PDPageContentStream#setStrokingColor
        page = new PDPage();
        doc.addPage(page);

        contentStream = new PDPageContentStream(doc, page, false, false);
        // pass a non-stroking color in CMYK color space
        contentStream.setStrokingColor(0.5f, 0.6f, 0.7f, 0.8f);
        contentStream.close();

        // now read the PDF stream and verify that the CMYK values are correct
        stream = page.getStream().getStream();
        parser = new PDFStreamParser(stream);
        parser.parse();
        pageTokens = parser.getTokens();
        // expected five tokens  :
        // [0] = COSFloat{0.5}
View Full Code Here


        RandomAccess reader = new RandomAccessFile(new File(tiffG3Path), "r");
        PDImageXObject ximage3 = CCITTFactory.createFromRandomAccess(document, reader);
        validate(ximage3, 1, 344, 287, "tiff", PDDeviceGray.INSTANCE.getName());
        BufferedImage bim3 = ImageIO.read(new File(tiffG3Path));
        checkIdent(bim3, ximage3.getOpaqueImage());
        PDPage page = new PDPage(PDRectangle.A4);
        document.addPage(page);
        PDPageContentStream contentStream = new PDPageContentStream(document, page, true, false);
        contentStream.drawXObject(ximage3, 0, 0, ximage3.getWidth(), ximage3.getHeight());
        contentStream.close();

        reader = new RandomAccessFile(new File(tiffG4Path), "r");
        PDImageXObject ximage4 = CCITTFactory.createFromRandomAccess(document, reader);
        validate(ximage4, 1, 344, 287, "tiff", PDDeviceGray.INSTANCE.getName());
        BufferedImage bim4 = ImageIO.read(new File(tiffG3Path));
        checkIdent(bim4, ximage4.getOpaqueImage());
        page = new PDPage(PDRectangle.A4);
        document.addPage(page);
        contentStream = new PDPageContentStream(document, page, true, false);
        contentStream.drawXObject(ximage4, 0, 0, ximage4.getWidth(), ximage4.getHeight());
        contentStream.close();
      
View Full Code Here

                break;
            }
            BufferedImage bim = imageReader.read(pdfPageNum);
            validate(ximage, 1, bim.getWidth(), bim.getHeight(), "tiff", PDDeviceGray.INSTANCE.getName());
            checkIdent(bim, ximage.getOpaqueImage());
            PDPage page = new PDPage(PDRectangle.A4);
            float fX = ximage.getWidth() / page.getMediaBox().getWidth();
            float fY = ximage.getHeight() / page.getMediaBox().getHeight();
            float factor = Math.max(fX, fY);
            document.addPage(page);
            PDPageContentStream contentStream = new PDPageContentStream(document, page, true, false);
            contentStream.drawXObject(ximage, 0, 0, ximage.getWidth() / factor, ximage.getHeight() / factor);
            contentStream.close();
View Full Code Here

     */
    public void testClonePDFWithCosArrayStream() throws IOException
    {
        PDDocument srcDoc = new PDDocument();
        PDDocument dstDoc = new PDDocument();
        PDPage pdPage = new PDPage();
        srcDoc.addPage(pdPage);
        new PDPageContentStream(srcDoc, pdPage, true, true).close();
        new PDPageContentStream(srcDoc, pdPage, true, true).close();
        new PDFCloneUtility(dstDoc).cloneForNewDocument(pdPage.getCOSObject());
        srcDoc.close();
        dstDoc.close();
    }
View Full Code Here

        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, true, false);
        pdPageContentStream1.setNonStrokingColor(Color.black);
        pdPageContentStream1.fillRect(100, 600, 300, 100);
        pdPageContentStream1.close();
View Full Code Here

                }
                PDFTextStripperByArea stripper = new PDFTextStripperByArea();
                stripper.setSortByPosition( true );
                Rectangle rect = new Rectangle( 10, 280, 275, 60 );
                stripper.addRegion( "class1", rect );
                PDPage firstPage = document.getPage(0);
                stripper.extractRegions( firstPage );
                System.out.println( "Text in the area:" + rect );
                System.out.println( stripper.getTextForRegion( "class1" ) );

            }
View Full Code Here

        PDDocument doc = null;
        try
        {
            doc = new PDDocument();

            PDPage page = new PDPage();
            doc.addPage(page);
            PDFont font = createPDType1AfmPfbFont(doc, fontfile);

            PDPageContentStream contentStream = new PDPageContentStream(doc,
                    page);
View Full Code Here

        try
        {
            document = new PDDocument();
            //Every document requires at least one page, so we will add one
            //blank page.
            PDPage blankPage = new PDPage();
            document.addPage( blankPage );
            document.save( file );
        }
        finally
        {
View Full Code Here

        }
    }

    private LayoutPage getLayoutPage(PDDocument doc) throws IOException
    {
        PDPage page = doc.getPage(0);
        COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS);
        PDResources resources = page.getResources();
        if (resources == null)
        {
            resources = new PDResources();
        }
        return new LayoutPage(page.getMediaBox(), createContentStream(contents),
                resources.getCOSObject());
    }
View Full Code Here

        PDDocumentCatalog catalog = doc.getDocumentCatalog();
        int numberOfPages = doc.getNumberOfPages();
        HashMap<Integer,LayoutPage> layoutPages = new HashMap<Integer, Overlay.LayoutPage>(numberOfPages);
        for (int i=0;i<numberOfPages;i++)
        {
            PDPage page = doc.getPage(i);
            COSBase contents = page.getCOSObject().getDictionaryObject(COSName.CONTENTS);
            PDResources resources = page.getResources();
            if (resources == null)
            {
                resources = new PDResources();
            }
            layoutPages.put(i,new LayoutPage(page.getMediaBox(), createContentStream(contents), resources.getCOSObject()));
        }
        return layoutPages;
    }
View Full Code Here

TOP

Related Classes of org.apache.pdfbox.pdmodel.PDPage

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.