Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-3206

Cannot change converted image's DPI

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Not A Problem
    • Affects Version/s: 2.0.0
    • Fix Version/s: None
    • Component/s: Documentation, Rendering
    • Labels:
    • Environment:
      Windows 10, JDK 1.7

      Description

      When i convert pdf to jpg, i use "renderImageWithDPI" and "JPEGFactory.createFromImage".
      but DPI doesn't change.

      So, How can i change image's DPI in pdfbox 2.0.0
      please let me know that.

      This is my source.
      1. using renderImageWithDPI

      PDDocument document = PDDocument.load(sourceFile);
      PDFRenderer pdfRenderer = new PDFRenderer(document);
      int pageCounter = 0;
      
      for (PDPage page : document.getPages()){ 
      
           RenderedImage im = pdfRenderer.renderImageWithDPI(pageCounter, Integer.parseInt(convertDPI), ImageType.RGB);
      
           File f = new File(destinationDir +"/"+saveName+"_"+ String.format("%03d", pageCounter)+"."+convertFormat);
      
           ImageIO.write(im, convertFormat,f);
      
           pageCounter++;
      
      }
      document.close();
      

      2. using "JPEGFactory.createFormImage"

      PDDocument document = PDDocument.load(sourceFile);
      PDFRenderer pdfRenderer = new PDFRenderer(document);
      int pageCounter = 0;
      
      for (PDPage page : document.getPages()){ 
      
          BufferedImage image = pdfRenderer.renderImage(pageCounter, 1);
          PDImageXObject pdImage = JPEGFactory.createFromImage(document, image, Float.parseFloat(convertQuality), Integer.parseInt(convertDPI));
      
          File f = new File(destinationDir +"/"+saveName+"_"+ String.format("%03d", pageCounter)+"."+convertFormat);
          ImageIO.write(pdImage.getImage(), convertFormat,f);
      }
      document.close();
      

        Attachments

        1. 캡처.JPG
          27 kB
          Jae Soon Kim
        2. package.JPG
          126 kB
          Jae Soon Kim
        3. Granizo1.jpg
          112 kB
          Tilman Hausherr
        4. Granizo.pdf
          54 kB
          Jae Soon Kim
        5. dependency.JPG
          53 kB
          Jae Soon Kim

          Activity

            People

            • Assignee:
              tilman Tilman Hausherr
              Reporter:
              dosagy Jae Soon Kim
            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: