Package org.jpedal.io

Examples of org.jpedal.io.ObjectStore


                /** read page or next pages */
                if (pdfObject != null) {

                    /** the ObjectStore for this file */
                    ObjectStore objectStoreRef = new ObjectStore();

                    PdfStreamDecoder current = new PdfStreamDecoder(currentPdfFile, false, layers);
                    current.setParameters(true, false, 0,PdfDecoder.TEXT + PdfDecoder.RAWIMAGES + PdfDecoder.FINALIMAGES);
                    current.setXMLExtraction(false);
                    current.setObjectValue(ValueTypes.Name, "markedContent");
                    current.setObjectValue(ValueTypes.ObjectStore,objectStoreRef);
                    current.setObjectValue(ValueTypes.StatusBar, null);
                    current.setObjectValue(ValueTypes.PDFPageData,pdfPageData);
                    current.setIntValue(ValueTypes.PageNum, pageNumber);

                    res.setupResources(current, false, pdfObject.getDictionary(PdfDictionary.Resources), pageNumber, currentPdfFile);

                    current.setObjectValue(ValueTypes.MarkedContent,pageStream);

                    current.decodePageContent(pdfObject);

                    objectStoreRef.flush();

                }
            }catch(Exception e){
                e.printStackTrace();
            }finally {
View Full Code Here


        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;

                /**
 
View Full Code Here


        /**
         * convert stream into an DynamicVector object we can then draw onto screen or tile
         */
        ObjectStore localStore = new ObjectStore();
        DynamicVectorRenderer glyphDisplay = decodePatternContent(PatternObj, matrix, streamData, localStore);

        //get the image
        BufferedImage image=glyphDisplay.getSingleImagePattern();

        /**
        * unashamed hack for very odd file
        * Investigate when more examples/time
        * (customers-june2011/10664.pdf)
        */
        //float[] BBox=PatternObj.getFloatArray(PdfDictionary.BBox);
        if(inputs!=null && inputs[0]<1.5 && inputs[3]<1.5 && inputs[1]==0 && inputs[2]==0 &&(image!=null || (rawXStep==-32768 && rawYStep==-32768))){//|| (BBox!=null && rawXStep==BBox[2] && rawYStep==BBox[3])){
        //if((rawXStep==-32768 && rawYStep==-32768)){//|| (BBox!=null && rawXStep==BBox[2] && rawYStep==BBox[3])){

            //turn upside down
            AffineTransform image_at2 =new AffineTransform();
            image_at2.scale(1,-1);
            image_at2.translate(0,-image.getHeight());
            AffineTransformOp invert3= new AffineTransformOp(image_at2,  null);
            image = invert3.filter(image,null);

            //ensure ARGB to avoid issues if we draw to BufferedImage
            if(image.getType()!=BufferedImage.TYPE_INT_ARGB)
                image=ColorSpaceConvertor.convertToARGB(image);

            //return as pattern to use
            return new PdfTexturePaint(image, new Rectangle((int) (inputs[4]-image.getWidth()),(int)(inputs[5]-image.getHeight()),image.getWidth(),image.getHeight()));

        }

        /**
         * if image is generated larger than slot we draw it into we
         * will lose definition. To avoid this, we draw at full size and
         * scale only when drawn onto page
         */
        //workout unscaled tile size
        float rawWidth=0,rawHeight=0;
        boolean isDownSampled=false;

        if(matrix!=null){
            rawWidth=matrix[0][0];
            if(rawWidth==0)
                rawWidth=matrix[0][1];
            if(rawWidth<0)
                rawWidth=-rawWidth;
            rawHeight=matrix[1][1];
            if(rawHeight==0)
                rawHeight=matrix[1][0];
            if(rawHeight<0)
                rawHeight=-rawHeight;
        }

        if(matrix!=null){ //this scales/rotated image onto tile - Java cannot handle this so we do it onto an unrotated tile

            //image scaled up to fit so create large tile and then draw upscaled version onto it
            if(inputs!=null && inputs[0]>1 && inputs[3]>1 && !isRotated){

                img=new BufferedImage((int)(XStep*rawWidth),(int)(YStep*rawHeight), BufferedImage.TYPE_INT_ARGB);
                Graphics2D g2=img.createGraphics();
                g2.setClip(new Rectangle(0,0,img.getWidth(),img.getHeight()));
                glyphDisplay.setG2(g2);
                glyphDisplay.paint(null,new AffineTransform(matrix[0][0], matrix[0][1], matrix[1][0],matrix[1][1], inputs[4],-inputs[5]/2) ,null);
             
            }else{ //buffer onto unrotated tile

                BufferedImage tileImg=null; //tile for image as faster to draw ONCE and then replicate image

                /**
                 * workout dx,dy and ensure positive and scaled
                 */
                dx=matrix[0][0];
                dy=matrix[1][1];

                if(dx==0)
                    dx=matrix[0][1];
                if(dx<0)
                    dx=-dx;

                if(dy==0)
                    dy=matrix[1][0];
                if(dy<0)
                    dy=-dy;

                dx=dx*XStep;
                dy=dy*YStep;

                /**
                 * workout size required for image
                 */
                int imgW=XStep,imgH=YStep; //default values for tile size

                if(!isRotated){
                /**
                 * special cases
                 */
                if(isUpsideDown){

                    int xCount=(int)(XStep/dx),yCount=(int)(YStep/dy);

                    if(xCount>0 && yCount>0){
                        imgW=(int)((xCount+1)*dx);
                        imgH=(int)((yCount+1)*dy);

                        XStep=imgW;
                        YStep=imgH;
                    }
                }else if(inputs!=null && inputs[0]>0 && inputs[0]<1 && inputs[3]>0 && inputs[3]<1){
                    imgW=(int)(dx);
                    imgH=(int)(dy);

                    if(imgH==0)
                    imgH=1;

                    //workout offsets
                    input_dxx=(int)inputs[4];
                    if(input_dxx>XStep){
                        while(input_dxx>0){
                            input_dxx=input_dxx-XStep;

                            if(input_dxx==0)
                                break;
                        }
                       
                        input_dxx=input_dxx/2;
                    }

                    //workout offsets
                    input_dyy=(int)inputs[5];
                    if(input_dyy>imgH){
                        while(input_dyy>0)
                        input_dyy=input_dyy-imgH;
                    }
                }

               

                if(isDownSampled){
                    img=new BufferedImage((int)(rawWidth+.5f),(int)(rawHeight+.5f),BufferedImage.TYPE_INT_ARGB);
                    imageScale=AffineTransform.getScaleInstance(XStep/rawWidth,YStep/rawHeight);
                }else{
                 
                  //a few file generate values less than 1 so code defensively for this case
                  if(imgW<1 || imgH<1)
                     img=new BufferedImage(1,1,BufferedImage.TYPE_INT_ARGB);
                  else
                    img=new BufferedImage(imgW,imgH,BufferedImage.TYPE_INT_ARGB);
                }
               
                Graphics2D g2=img.createGraphics();
                AffineTransform defaultAf=g2.getTransform();

                g2.setClip(new Rectangle(0,0,img.getWidth(),img.getHeight()));

                /**
                 * allow for tile not draw from 0,0
                 */
                int startX=0;
                Rectangle actualTileRect=glyphDisplay.getOccupiedArea().getBounds();


                int tileW,tileH;
                int dxx=0,dyy=0;
                if(actualTileRect.x<0){
                    tileW=actualTileRect.width-actualTileRect.x;
                    dxx=actualTileRect.x;
                }else
                    tileW=actualTileRect.width+actualTileRect.x;

                if(actualTileRect.y<0){
                    tileH=actualTileRect.height-actualTileRect.y;
                    dyy=actualTileRect.y;
                }else
                    tileH=actualTileRect.height+actualTileRect.y;

                if(tileH==0)
                tileH=1;
               
                if(tesslateOntoImage){
                 
                  //a few file generate values less than 1 so code defensively for this case
                  if(tileW<1 || tileH<1)
                    tileImg=new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
                  else
                    tileImg=new BufferedImage(tileW, tileH, BufferedImage.TYPE_INT_ARGB);

                 
                    Graphics2D tileG2=tileImg.createGraphics();
                    tileG2.translate(-dxx,-dyy);
                    glyphDisplay.setG2(tileG2);
                    glyphDisplay.paint(null,null,null);
                }

                int rectX=actualTileRect.x;
                if(rectX<0 && !tesslateOntoImage)
                    startX= (int) (-rectX*matrix[0][0]);

                    //if tile is smaller than Xstep,Ystep, tesselate to fill
                    float max=YStep;
                    if(tesslateOntoImage)
                    max=YStep+(tileImg.getHeight()*2);

                    //fix for odd pattern on phonbingo
                    int min=0;
                    if(matrix[1][1]<0)
                    min= (int) (-max/2);

                   
                    //adjustment for pattern on customers-june2011/Verizon PowerPoint Template.pdf
                    if(needsAdjusting && matrix[0][0]>0 && matrix[1][1]<0)
                    min=min+(pageHeight-pageWidth);

                    for(float y=min;y<max;y=y+dy){
                        for(float x=startX;x<XStep;x=x+dx){

                            if(isUpsideDown)
                                g2.translate(x,-y);
                            else
                                g2.translate(x,y);

                            if(tesslateOntoImage){
                              AffineTransform tileAff=new AffineTransform();
                                ColorSpaceConvertor.drawImage(g2, tileImg, tileAff, null);
                            }else{
                                glyphDisplay.setG2(g2);
                                glyphDisplay.paint(null,imageScale,null);
                            }
                            g2.setTransform(defaultAf);
                        }
                    }
                }
            }
        }else//no matrix value so just draw onto tile

            if(isDownSampled){
                img=new BufferedImage((int)(rawWidth+.5f),(int)(rawHeight+.5f),BufferedImage.TYPE_INT_ARGB); //.5 to allow for rounding of decimal
                imageScale=AffineTransform.getScaleInstance(XStep/rawWidth,YStep/rawHeight);
            }else
                img=new BufferedImage(XStep,YStep,BufferedImage.TYPE_INT_ARGB);

            Graphics2D g2=img.createGraphics();

            glyphDisplay.setG2(g2);
            glyphDisplay.paint(null,null,null);

            //flip now once for speed if upside down
            if(isUpsideDown && img.getHeight()>1){
                AffineTransform flip=new AffineTransform();
                flip.translate(0, img.getHeight());
                flip.scale(1, -1);
                AffineTransformOp invert =new AffineTransformOp(flip,ColorSpaces.hints);
                img=invert.filter(img,null);
            }
        }

        //now delete any stored images used in content
        localStore.flush();

        /**
         * create paint using image or decoded content if rotated
         */
        if(img!=null)
View Full Code Here

        BufferedImage image;
        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);


        resultsFromDecode.update(currentImageDecoder, false);

        /**
         * draw acroform data onto Panel
         */
        if (formRenderer != null && formRenderer.hasFormsOnPage(pageIndex) && !formRenderer.ignoreForms()) {

            resultsFromDecode.resetColorSpaces();

            formRenderer.createDisplayComponentsForPage(pageIndex,currentImageDecoder);

            formRenderer.getCompData().renderFormsOntoG2(g2,pageIndex, scaling, 0, displayRotation,
                    null, null,currentPdfFile, pageData.getMediaBoxHeight(pageIndex));

        }


        localStore.flush();
        return image;
    }
View Full Code Here

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

                        if (pdfObject != null) {

                            ObjectStore backgroundObjectStoreRef = new ObjectStore();

                            PdfStreamDecoder backgroundDecoder = new PdfStreamDecoder(currentPdfFile);
                            backgroundDecoder.setParameters(true, false, 0, extractionMode);
                           
                            backgroundDecoder.setXMLExtraction(options.isXMLExtraction());
View Full Code Here

      try{

        /**
         * generate local object to decode the stream
         */
            ObjectStore localStore = new ObjectStore();


        /**
         * create renderer object
         */
        T3Renderer glyphDisplay=new T3Display(0,false,20,localStore);
           
        //fix for hires
        if(!useHires)
          glyphDisplay.setOptimisedRotation(false);
        else
            //if(useHires)
                glyphDisplay.setHiResImageForDisplayMode(useHires);


            PdfStreamDecoder glyphDecoder=new PdfStreamDecoder(currentPdfFile,useHires,null); //switch to hires as well
            glyphDecoder.setParameters(false,true,15,0);

            glyphDecoder.setIntValue(ValueTypes.StreamType, ValueTypes.FORM);

            glyphDecoder.setBooleanValue(ValueTypes.XFormFlattening, true);
            glyphDecoder.setObjectValue(ValueTypes.ObjectStore,localStore);


            glyphDecoder.setObjectValue(ValueTypes.DynamicVectorRenderer,glyphDisplay);

        /**read any resources*/
        try{
          PdfObject Resources =XObject.getDictionary(PdfDictionary.Resources);
          if (Resources != null)
            glyphDecoder.readResources(Resources,false);

        }catch(Exception e){
          e.printStackTrace();
          System.out.println("Exception "+e+" reading resources in XForm");
        }

            /**decode the stream*/
        byte[] commands=XObject.getDecodedStream();

       
            if(commands!=null)
          glyphDecoder.decodeStreamIntoObjects(commands,false);


        boolean ignoreColors=glyphDecoder.ignoreColors;

        glyphDecoder=null;

        localStore.flush();

        org.jpedal.fonts.glyph.T3Glyph form= new org.jpedal.fonts.glyph.T3Glyph(glyphDisplay, 0,0,ignoreColors,"");

        float[] BBox=XObject.getFloatArray(PdfDictionary.BBox);
       
View Full Code Here

TOP

Related Classes of org.jpedal.io.ObjectStore

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.