Package de.intarsys.pdf.pd

Examples of de.intarsys.pdf.pd.PDDocument


  public BufferedImage getPageImage(File inputFile, String password, int page, int rotation)
      throws ThumbnailCreationException {
    BufferedImage retVal = null;
    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),
View Full Code Here


   * @throws IOException
   * @throws COSLoadException
   */
  @SuppressWarnings("unchecked")
  private PDDocument openDoc(File inputFile, String password) throws IOException, COSLoadException {
    PDDocument retVal = null;
    FileLocator locator = new FileLocator(inputFile);
    if (password != null) {
      Map options = new HashMap();
      final char[] pwd = password.toCharArray();
      PasswordProvider.setPasswordProvider(options, new IPasswordProvider() {
View Full Code Here

TOP

Related Classes of de.intarsys.pdf.pd.PDDocument

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.