Package org.icepdf.core.pobjects

Examples of org.icepdf.core.pobjects.Document


  public Image toImage(byte[] input, int pageNumber) throws PageException {
    return toImage(input, pageNumber, 100,false);
  }
 
  public Image toImage(byte[] input, int pageNumber, int scale, boolean transparent) throws PageException {
    Document document = toDocument(input);
        BufferedImage bi=toBufferedImage(document,pageNumber,scale/100f,transparent);
    document.dispose();
    return new Image(bi);
  }
View Full Code Here


      boolean goodQuality, boolean transparent) throws PageException,
      IOException {
    if(scale<1)
      throw new ExpressionException("invalid scale definition ["+Caster.toString(scale)+"], value should be in range from 1 to n");
       
    Document document = toDocument(input);
        try
      Resource res;
      int count = document.getNumberOfPages();
      for(int page=1;page<=count;page++) {
        if(pages!=null && !pages.contains(Integer.valueOf(page)))continue;
        res=createDestinationResource(outputDirectory,prefix,page,format,overwrite);
        //res=outputDirectory.getRealResource(prefix+"_page_"+page+"."+format);
        writeImage(document,page,res,format,scale,overwrite,goodQuality, transparent);
      }
    }
    finally{
     
    }
        document.dispose();
   
  }
View Full Code Here

  }
 


  private Document toDocument(byte[] input) throws PageException {
    Document document = new Document();
        try {
      document.setByteArray(input, 0, input.length, null);
    } catch (Throwable t) {
      throw Caster.toPageException(t);
    }
    return document;
  }
View Full Code Here

        File lo = new File(lookupFileName);
        String filePath = lo.getParent().concat("/outPDF.pdf");
        BufferedImage image = null;
        RenderedImage rendImage = null;
        // open the url
        Document document = new Document();
        try {
            document.setFile(filePath);
        } catch (PDFException ex) {
            System.out.println("Error parsing PDF document " + ex);
        } catch (PDFSecurityException ex) {
            System.out.println("Error encryption not supported " + ex);
        } catch (FileNotFoundException ex) {
            System.out.println("Error file not found " + ex);
        } catch (IOException ex) {
            System.out.println("Error handling PDF document " + ex);
        }

        // Increasing the scale value for increases the quality of image produced but at cost of more execution time
        float scale = 5.0f;
        float rotation = 0f;

        // Paint each pages content to an image and write the image to file
        for (int i = 0; i < document.getNumberOfPages(); i++) {
            image = (BufferedImage) document.getPageImage(i, GraphicsRenderingHints.SCREEN,
                    Page.BOUNDARY_CROPBOX, rotation, scale);
            rendImage = image;
            // capture the page image to file
            try {
                System.out.println("\t capturing page " + i);
                File file = new File(out + ".png");
                ImageIO.write(image, "png", file);

            } catch (IOException e) {
                e.printStackTrace();
            }
            image.flush();
        }
        // clean up resources
        document.dispose();
        return image;
    }
View Full Code Here

TOP

Related Classes of org.icepdf.core.pobjects.Document

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.