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

Preserve transparency when converting to image with rgba

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • 1.2.0
    • 1.2.0
    • PDModel
    • all

    Description

      When converting a pdf page to an image, the transparency is lost because PDPage.drawImage() sets the background color to white: graphics.setBackground( Color.WHITE );

      The desired behavior is to preserve transparency when rgba color is set, and to fall back to white when rgb is used.

      The following change works with either color mode:

      +
      + /**
      + * Fully transparent that can fall back to white when image type has no alpha.
      + */
      + private static final Color TRANSPARENT_WHITE = new Color( 255, 255, 255, 0 );
      +
      private COSDictionary page;

      /**
      @@ -706,7 +711,7 @@

      BufferedImage retval = new BufferedImage( widthPx, heightPx, imageType );
      Graphics2D graphics = (Graphics2D)retval.getGraphics();

      • graphics.setBackground( Color.WHITE );
        + graphics.setBackground( TRANSPARENT_WHITE );

      Attached is a patch and some sample pdfs and images.

      Attachments

        1. hello-DroidSans-Identity-H1-rgb.jpg
          10 kB
          Armando Singer
        2. hello-DroidSans-Identity-H1-rgb.png
          4 kB
          Armando Singer
        3. hello-DroidSans-Identity-H-rgba.png
          4 kB
          Armando Singer
        4. hello-DroidSans-Identity-H.pdf
          188 kB
          Armando Singer
        5. pdfbox-r945442.patch
          1 kB
          Armando Singer

        Activity

          People

            Unassigned Unassigned
            asinger Armando Singer
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 5m
                5m
                Remaining:
                Remaining Estimate - 5m
                5m
                Logged:
                Time Spent - Not Specified
                Not Specified