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

PDFBox seems to scale up image while it should not

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Not A Bug
    • None
    • None
    • None
    • None

    Description

      I have a test image (in attachment) and the following code:

        public static void main(String[] args) {
          final String filename = "test.jpg";
          try (
              final PDDocument doc = new PDDocument();
              final FileInputStream input = new FileInputStream(new File(filename));
              final ByteArrayOutputStream pdfOut = new ByteArrayOutputStream();
              final FileOutputStream output = new FileOutputStream("test.pdf")
          ) {
            final PDImageXObject jpeg = PDImageXObject.createFromByteArray(doc, IOUtils.toByteArray(input), filename);
      
            final PDPage page = new PDPage(new PDRectangle(jpeg.getWidth(), jpeg.getHeight()));
            doc.addPage(page);
            try (final PDPageContentStream contents = new PDPageContentStream(doc, page)) {
              contents.drawImage(jpeg, 0, 0);
            }
            doc.save(pdfOut);
            pdfOut.flush();
            IOUtils.write(pdfOut.toByteArray(), output);
          }catch (Exception e) {
            e.printStackTrace();
          }
        }
      

      The image in test.pdf is double sized (and quality is worse) than in original image

      Attachments

        1. comparison.png
          902 kB
          Kamil
        2. comparison-tilman.png
          906 kB
          Tilman Hausherr
        3. test.jpg
          91 kB
          Kamil
        4. test.pdf
          92 kB
          Tilman Hausherr

        Activity

          People

            Unassigned Unassigned
            eximius Kamil
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: