Package org.jpedal.render

Examples of org.jpedal.render.DynamicVectorRenderer


        //Create Rectangle object to match width and height of cropbox
        Rectangle cropBox = new Rectangle(0, 0, cropW, cropH);
        //Find middle of cropbox in Pdf Coordinates
        Point2D midPoint = new Point2D.Double((cropW / 2) + cropX, (cropH / 2) + cropY);
       
        DynamicVectorRenderer JavaFXOutput=null;
               
                final boolean outputAsFXML=false; //our debug code to add FXML - not live yet
                //we will need JavaFXMLDisplay and JavaFXMLShape
                if(outputAsFXML){
                  JavaFXOutput =new JavaFXMLDisplay(page, midPoint, cropBox ,false, 100, new ObjectStore());
                }else
            JavaFXOutput =new JavaFXDisplay(page, midPoint, cropBox ,false, 100, new ObjectStore());

                //have a scaling factor so we can alter the page size
                float scaling=1.0f;

                /**
                 * if you want to fit it to a certain size, use this code
                 * work out max possible scaling for both width and height
                 * and use smaller to get max possible size but retain aspect ratio
                 * - will not always be exact match as preserves aspect ratio
                 *
                float preferredWidth=1000,preferredHeight=1000;

                float scalingX=preferredWidth/cropW; // scaling we need to scale w up to our value
                float scalingY=preferredHeight/cropH; // scaling we need to scale w up to our value

                if(scalingX>scalingY)
                    scaling=scalingY;
                else
                    scaling=scalingX;
                /**/

                JavaFXOutput.setValue(OutputDisplay.PercentageScaling, (int) (scaling*100)); //set page scaling (default is 100%)
                JavaFXOutput.writeCustom(OutputDisplay.PAGEDATA,decode_pdf.getPdfPageData()); //pass in PageData object so we c
                JavaFXOutput.setValue(OutputDisplay.MaxNumberOfDecimalPlaces, 0);   //let use select max number of decimal places
                JavaFXOutput.setOutputDir(output_dir, name, pageAsString); //root for output

                decode_pdf.addExternalHandler(JavaFXOutput, Options.CustomOutput); //custom object to draw PDF

        /**
                 * This allows the user to have a nav bar on page
                 */
                JavaFXOutput.setBooleanValue(OutputDisplay.AddNavBar, true);

        /**
         * useful config options
         */
        //JavaFXOutput.writeCustom(OutputDisplay.SET_ENCODING_USED, new String[]{"UTF-16","utf-16"}); //java/output string value
View Full Code Here


        Graphics2D g2;

        PdfObject Resources=pdfObject.getDictionary(PdfDictionary.Resources);

        ObjectStore localStore = new ObjectStore();
        DynamicVectorRenderer imageDisplay = new ImageDisplay(pageIndex,false, 5000, localStore);

        PdfStreamDecoder currentImageDecoder = new PdfStreamDecoder(currentPdfFile);
        currentImageDecoder.setParameters(true, true, renderMode,0);

        externalHandlers.addHandlers(currentImageDecoder);

        //currentImageDecoder.setObjectValue(ValueTypes.Name, filename);
        currentImageDecoder.setObjectValue(ValueTypes.ObjectStore,localStore);
        currentImageDecoder.setFloatValue(BaseDecoder.Multiplier, multiplyer);
        currentImageDecoder.setObjectValue(ValueTypes.PDFPageData,pageData);
        currentImageDecoder.setIntValue(ValueTypes.PageNum, pageIndex);

        currentImageDecoder.setObjectValue(ValueTypes.DynamicVectorRenderer,imageDisplay);

        res.setupResources(currentImageDecoder, true, Resources,pageIndex,currentPdfFile);

        //can for max
        if(multiplyer==-2){

            multiplyer=-1;
            currentImageDecoder.setFloatValue(BaseDecoder.Multiplier, multiplyer);

            PdfStreamDecoderForSampling currentImageDecoder2 = new PdfStreamDecoderForSampling(currentPdfFile);
            currentImageDecoder2.setParameters(true, true, renderMode,0);

            //currentImageDecoder2.setObjectValue(ValueTypes.Name, filename);
            currentImageDecoder2.setObjectValue(ValueTypes.ObjectStore,localStore);
            currentImageDecoder2.setFloatValue(BaseDecoder.Multiplier, multiplyer);
            currentImageDecoder2.setObjectValue(ValueTypes.PDFPageData,pageData);
            currentImageDecoder2.setIntValue(ValueTypes.PageNum, pageIndex);
            currentImageDecoder2.setObjectValue(ValueTypes.DynamicVectorRenderer,imageDisplay);

            res.setupResources(currentImageDecoder2, true, Resources,pageIndex,currentPdfFile);

            /** bare minimum to get value*/
            multiplyer=currentImageDecoder2.decodePageContentForImageSampling(pdfObject);

            int bestQualityMaxScalingToUse = 0;
            if(instance_bestQualityMaxScaling != null)
                bestQualityMaxScalingToUse = instance_bestQualityMaxScaling;
            else if (bestQualityMaxScaling != null)
                bestQualityMaxScalingToUse = bestQualityMaxScaling;

            if (bestQualityMaxScalingToUse > 0 && multiplyer > bestQualityMaxScalingToUse) {
                multiplyer = bestQualityMaxScalingToUse;
            }

            currentImageDecoder2.setFloatValue(BaseDecoder.Multiplier, multiplyer);
            currentImageDecoder.setFloatValue(BaseDecoder.Multiplier, multiplyer);
        }

        if(!allowPagesSmallerThanPageSize &&
                !instance_allowPagesSmallerThanPageSize &&
                multiplyer<1 && multiplyer>0)
            multiplyer=1;

        //allow for value not set
        if(multiplyer==-1)
            multiplyer=1;

        /**
         * setup transformations and image
         */


        AffineTransform imageScaling = setPageParametersForImage(scaling*multiplyer, pageIndex,pageData);

        //include scaling in size
        int mediaH = (int) (scaling*pageData.getMediaBoxHeight(pageIndex));
        int rotation = pageData.getRotation(pageIndex);

        int crw = (int) (scaling*pageData.getCropBoxWidth(pageIndex));
        int crh = (int) (scaling*pageData.getCropBoxHeight(pageIndex));
        int crx = (int) (scaling*pageData.getCropBoxX(pageIndex));
        int cry = (int) (scaling*pageData.getCropBoxY(pageIndex));

        boolean rotated = false;
        int w, h;
        if ((rotation == 90) || (rotation == 270)) {
            h = (int) (crw*multiplyer); // * scaling);
            w = (int) (crh*multiplyer); // * scaling);
            rotated = true;
        } else {
            w = (int) (crw*multiplyer); // * scaling);
            h = (int) (crh*multiplyer); // * scaling);
        }

        image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);

        Graphics graphics = image.getGraphics();

        g2 = (Graphics2D) graphics;

        if (!imageIsTransparent) {
            g2.setColor(Color.white);
            g2.fillRect(0, 0, w, h);
        }

        /**
         * adjustment for upside down images
         */
        if(rotation==180){
            g2.translate(crx*2*multiplyer, -(cry*2*multiplyer));
        }

        /**
         * pass in values as needed for patterns
         */
        ((DynamicVectorRenderer)currentImageDecoder.getObjectValue(ValueTypes.DynamicVectorRenderer)).setScalingValues(crx*multiplyer, (crh*multiplyer) + cry, multiplyer*scaling);


        g2.setRenderingHints(ColorSpaces.hints);
        g2.transform(imageScaling);

        if (rotated){

            if(rotation==90){//90

                if(multiplyer<1){
                    cry = (int)(imageScaling.getTranslateX() + cry);
                    crx = (int)(imageScaling.getTranslateY() + crx);

                }else{
                    cry = (int)((imageScaling.getTranslateX()/multiplyer) + cry);
                    crx = (int)((imageScaling.getTranslateY()/multiplyer) + crx);
                }
                g2.translate(-crx, -cry);

            }else{ //270
                if(cry<0)
                    g2.translate(-crx, mediaH-crh+cry);
                else
                    g2.translate(-crx,mediaH-crh-cry);
            }
        }

        /** decode and print in 1 go */
        currentImageDecoder.setObjectValue(ValueTypes.DirectRendering, g2);//(Graphics2D) graphics);
        imageDisplay.setG2(g2);
        if (pdfObject != null){
            currentImageDecoder.decodePageContent(pdfObject);
        }

        g2.setClip(null);
View Full Code Here

TOP

Related Classes of org.jpedal.render.DynamicVectorRenderer

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.