You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@pdfbox.apache.org by "Armando Singer (JIRA)" <ji...@apache.org> on 2010/06/02 07:42:36 UTC

[jira] Updated: (PDFBOX-738) Preserve transparency when converting to image with rgba

     [ https://issues.apache.org/jira/browse/PDFBOX-738?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Armando Singer updated PDFBOX-738:
----------------------------------

    Attachment: pdfbox-r945442.patch
                hello-DroidSans-Identity-H.pdf
                hello-DroidSans-Identity-H-rgba.png

Examples:

- convert to png image with rgba color -> image w/ transparent background (new)
- convert to png image with rgb color -> image w/ white background (as before)
- convert to jpg image with rgb image type -> image w/ white background (as before)

test with:

java -jar pdfbox-app-1.2.0-SNAPSHOT.jar PDFToImage -imageType png -startPage 1 -endPage 1 -color rgba -resolution 108 hello-DroidSans-Identity-H.pdf

java -jar pdfbox-app-1.2.0-SNAPSHOT.jar PDFToImage -imageType png -startPage 1 -endPage 1 -color rgb -resolution 108 hello-DroidSans-Identity-H.pdf

java -jar pdfbox-app-1.2.0-SNAPSHOT.jar PDFToImage -imageType jpg -startPage 1 -endPage 1 -color rgb -resolution 108 hello-DroidSans-Identity-H.pdf

> Preserve transparency when converting to image with rgba
> --------------------------------------------------------
>
>                 Key: PDFBOX-738
>                 URL: https://issues.apache.org/jira/browse/PDFBOX-738
>             Project: PDFBox
>          Issue Type: Bug
>          Components: PDModel
>    Affects Versions: 1.2.0
>         Environment: all
>            Reporter: Armando Singer
>            Priority: Minor
>         Attachments: hello-DroidSans-Identity-H-rgba.png, hello-DroidSans-Identity-H.pdf, hello-DroidSans-Identity-H1-rgb.jpg, hello-DroidSans-Identity-H1-rgb.png, pdfbox-r945442.patch
>
>   Original Estimate: 0.08h
>  Remaining Estimate: 0.08h
>
> 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.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.