Examples of PDPage


Examples of de.intarsys.pdf.pd.PDPage

    IGraphicsContext graphics = null;
    PDDocument pdfDoc = null;
    if (inputFile != null && inputFile.exists() && inputFile.isFile()) {
      try {
        pdfDoc = openDoc(inputFile, password);
        PDPage pdPage = pdfDoc.getPageTree().getPageAt(page - 1);
        Rectangle2D rect = pdPage.getCropBox().toNormalizedRectangle();

        retVal = new BufferedImage((int) rect.getWidth(), (int) rect.getHeight(), BufferedImage.TYPE_INT_RGB);
        Graphics2D g2 = (Graphics2D) retVal.getGraphics();
        graphics = new CwtAwtGraphicsContext(g2);
        // setup user space
        AffineTransform imgTransform = graphics.getTransform();
        imgTransform.scale(1, -1);
        imgTransform.translate(-rect.getMinX(), -rect.getMaxY());
        graphics.setTransform(imgTransform);
        graphics.setBackgroundColor(Color.WHITE);
        graphics.fill(rect);
        CSContent content = pdPage.getContentStream();
        if (content != null) {
          JPodRenderer renderer = new JPodRenderer(null, graphics);
          renderer.process(content, pdPage.getResources());
        }
        if (pdfDoc != null) {
          pdfDoc.close();
        }
        int totalRotation = (rotation + pdPage.getRotate()) % 360;
        if (totalRotation != 0) {
          Image rotated = ImageUtility.rotateImage(retVal, totalRotation);
          retVal = new BufferedImage(rotated.getWidth(null), rotated.getHeight(null),
              BufferedImage.TYPE_INT_RGB);
          Graphics g = retVal.getGraphics();
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

      // extract annotations
      StringBuilder annotsResult = new StringBuilder();
      List allPages = pdfDocument.getDocumentCatalog().getAllPages();
      for (int i = 0; i < allPages.size(); i++) {
        int pageNum = i + 1;
        PDPage page = (PDPage) allPages.get(i);
        List<PDAnnotation> annotations = page.getAnnotations();
        if (annotations.size() < 1) {
          continue;
        }
        mLog.debug("Total annotations = " + annotations.size());
        mLog.debug("\nProcess Page " + pageNum + "...");
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

        //finally append the pages
        List pages = source.getDocumentCatalog().getAllPages();
        Iterator pageIter = pages.iterator();
        while( pageIter.hasNext() )
        {
            PDPage page = (PDPage)pageIter.next();
            PDPage newPage =
                new PDPage( (COSDictionary)cloneForNewDocument( destination, page.getCOSDictionary() ) );
            newPage.setCropBox( page.findCropBox() );
            newPage.setMediaBox( page.findMediaBox() );
            newPage.setRotation( page.findRotation() );
            destination.addPage( newPage );
        }
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

        if(xobject instanceof PDXObjectForm)
        {
            PDXObjectForm form = (PDXObjectForm)xobject;
            COSStream invoke = (COSStream)form.getCOSObject();
            PDResources pdResources = form.getResources();
            PDPage page = context.getCurrentPage();
            if(pdResources == null)
            {
                pdResources = page.findResources();
            }

            getContext().processSubStream( page, pdResources, invoke );
        }
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

     * @throws IOException If there is an error displaying the inline image.
     */
    public void process(PDFOperator operator, List<COSBase> argumentsthrows IOException
    {
        PageDrawer drawer = (PageDrawer)context;
        PDPage page = drawer.getPage();
        Dimension pageSize = drawer.getPageSize();
        Graphics2D graphics = drawer.getGraphics();
        //begin inline image object
        ImageParameters params = operator.getImageParameters();
        PDInlinedImage image = new PDInlinedImage();
        image.setImageParameters( params );
        image.setImageData( operator.getImageData() );
        BufferedImage awtImage = image.createImage( context.getColorSpaces() );

        if (awtImage == null)
        {
            log.warn("BeginInlineImage.process(): createImage returned NULL");
            return;
        }
        int imageWidth = awtImage.getWidth();
        int imageHeight = awtImage.getHeight();
        double pageHeight = pageSize.getHeight();
       
        Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
        int pageRotation = page.findRotation();

        AffineTransform ctmAT = ctm.createAffineTransform();
        ctmAT.scale(1f/imageWidth, 1f/imageHeight);
        Matrix rotationMatrix = new Matrix();
        rotationMatrix.setFromAffineTransform( ctmAT );
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

     * @throws IOException If there is an error invoking the sub object.
     */
    public void process(PDFOperator operator, List<COSBase> arguments) throws IOException
    {
        PageDrawer drawer = (PageDrawer)context;
        PDPage page = drawer.getPage();
        Dimension pageSize = drawer.getPageSize();
        Graphics2D graphics = drawer.getGraphics();
        COSName objectName = (COSName)arguments.get( 0 );
        Map xobjects = drawer.getResources().getXObjects();
        PDXObject xobject = (PDXObject)xobjects.get( objectName.getName() );
        if( xobject instanceof PDXObjectImage )
        {
            PDXObjectImage image = (PDXObjectImage)xobject;
            try
            {
                image.setGraphicsState(drawer.getGraphicsState());
                BufferedImage awtImage = image.getRGBImage();
                if (awtImage == null)
                {
                    log.warn("getRGBImage returned NULL");
                    return;//TODO PKOCH
                }
                int imageWidth = awtImage.getWidth();
                int imageHeight = awtImage.getHeight();
                double pageHeight = pageSize.getHeight();

                log.info("imageWidth: " + imageWidth + "\t\timageHeight: " + imageHeight);
       
                Matrix ctm = drawer.getGraphicsState().getCurrentTransformationMatrix();
                int pageRotation = page.findRotation();

                AffineTransform ctmAT = ctm.createAffineTransform();
                ctmAT.scale(1f/imageWidth, 1f/imageHeight);
                Matrix rotationMatrix = new Matrix();
                rotationMatrix.setFromAffineTransform( ctmAT );
                if (pageRotation == 0 || pageRotation == 180)
                {
                    rotationMatrix.setValue(2,1,(float)pageHeight-ctm.getYPosition()-ctm.getYScale());
                }
                else if (pageRotation == 90 || pageRotation == 270)
                {
                    rotationMatrix.setValue(2,0,(float)ctm.getXPosition()-ctm.getYScale());
                    rotationMatrix.setValue(2,1,(float)pageHeight-ctm.getYPosition());
                }
                rotationMatrix.setValue(0, 1, (-1)*rotationMatrix.getValue(0, 1));
                rotationMatrix.setValue(1, 0, (-1)*rotationMatrix.getValue(1, 0));

                AffineTransform at = new AffineTransform(
                        rotationMatrix.getValue(0,0),rotationMatrix.getValue(0,1),
                        rotationMatrix.getValue(1,0), rotationMatrix.getValue( 1, 1),
                        rotationMatrix.getValue(2,0),rotationMatrix.getValue(2,1)
                    );
                Shape clip = context.getGraphicsState().getCurrentClippingPath();
                // If the pdf is printed, sometimes a NPE occurs, see PDFBOX-552 for details
                // As a workaround we have to replace a possible null-value with a rectangle having
                // the same dimension than the page to be printed
                if (clip == null)
                {
                    clip = new Rectangle(pageSize);
                }
                graphics.setClip(clip);
                graphics.drawImage( awtImage, at, null );
            }
            catch( Exception e )
            {
                e.printStackTrace();
                log.error(e, e);
            }
        }
        else if(xobject instanceof PDXObjectForm)
        {
            PDXObjectForm form = (PDXObjectForm)xobject;
            COSStream invoke = (COSStream)form.getCOSObject();
            PDResources pdResources = form.getResources();
            if(pdResources == null)
            {
                pdResources = page.findResources();
            }

            getContext().processSubStream( page, pdResources, invoke );
        }
        else
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

        {
            throw new IllegalArgumentException("First page of pdf is 1, not " + page);
        }


        PDPage firstPage = document.getPage(page - 1);
        PDRectangle mediaBox = firstPage.getMediaBox();
        pageHeight(mediaBox.getHeight());
        pageWidth = mediaBox.getWidth();

        float x = this.pageWidth;
        float y = 0;
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

     *
     * @throws IOException If there is an error parsing the text.
     */
    protected void processPages(PDPageTree pages) throws IOException
    {
        PDPage startPage = startBookmark == null ? null :
                startBookmark.findDestinationPage(document);

        PDPage endPage = endBookmark == null ? null :
                endBookmark.findDestinationPage(document);

        if (startPage != null && endPage != null &&
            startBookmark.getCOSObject() == endBookmark.getCOSObject())
        {
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

            context.addValidationError(new ValidationError(PreflightConstants.ERROR_GRAPHIC_MISSING_OBJECT, "ShadingPattern validation required at least a PDResources"));
        }
        else
        {
            PDShading shaddingResource = (PDShading) vPath.peek();
            PDPage page = vPath.getClosestPathElement(PDPage.class);
            checkColorSpace(context, page, shaddingResource);
            checkGraphicState(context, page, shaddingResource);
        }
    }
View Full Code Here

Examples of org.apache.pdfbox.pdmodel.PDPage

                throw new IOException("You do not have permission to extract images");
            }

            for (int i = 0; i < document.getNumberOfPages(); i++) // todo: ITERATOR would be much better
            {
                PDPage page = document.getPage(i);
                ImageGraphicsEngine extractor = new ImageGraphicsEngine(page);
                extractor.run();
            }
        }
        finally
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.