You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Steve Jerman <st...@kloudspot.com> on 2017/11/26 18:19:52 UTC

Setting background transparency for imported PDFormXObject

Hi,


I am creating an application that creates a report using a template page for each and then positions graphics on each page.


To allow me to use vector based graphics, they are each imported as PDFs:


try (PDPageContentStream contents = new PDPageContentStream(doc, currentPage, AppendMode.APPEND, true);

PDDocument imageDoc = PDDocument.load(pdfGraph);) {


LayerUtility layerUtility = new LayerUtility(doc);

PDFormXObject form = layerUtility.importPageAsForm(imageDoc, 0);

contents.saveGraphicsState();

Matrix matrix = Matrix.getTranslateInstance(rect.getLowerLeftX(), rect.getLowerLeftY());

contents.transform(matrix);

contents.drawForm(form);

contents.restoreGraphicsState();


}

Now, this seems to work fine. However, these is one issue ... I would like to have the background of the imported graphic be transparent. At present it comes in with a white background.


Is there anyway to set a transparent background?


Thanks for any help

Steve


Re: Setting background transparency for imported PDFormXObject

Posted by Steve Jerman <st...@kloudspot.com>.
Thanks for the answer. I'm bringing the plots from R and your answer prompted me to look at some more options there. Found what I was looking for 😊


Also thanks for the PS .. will check

Steve

________________________________
From: Tilman Hausherr <TH...@t-online.de>
Sent: Monday, November 27, 2017 10:05:06 AM
To: users@pdfbox.apache.org
Subject: Re: Setting background transparency for imported PDFormXObject

You can't set only a part of it transparent. You can only have some
transparency effect on the whole thing.

Maybe there is some blending that would remove white, then this would
remove the white everywhere, or maybe have other effects. Have a look here:
http://www.pdfvt.com/PDFVT_TransparencyGuide.html

It would be easier to remove the white background in the xobject form
you want to invoke, especially if this is a one-time job. However this
may be tricky, a "background" can be many things.

Tilman

PS: use the PDPageContentStream with 5 parameters (read the javadoc
why), unless you know in advance what kind of PDFs you append to.


Am 26.11.2017 um 19:19 schrieb Steve Jerman:
> Hi,
>
>
> I am creating an application that creates a report using a template page for each and then positions graphics on each page.
>
>
> To allow me to use vector based graphics, they are each imported as PDFs:
>
>
> try (PDPageContentStream contents = new PDPageContentStream(doc, currentPage, AppendMode.APPEND, true);
>
> PDDocument imageDoc = PDDocument.load(pdfGraph);) {
>
>
> LayerUtility layerUtility = new LayerUtility(doc);
>
> PDFormXObject form = layerUtility.importPageAsForm(imageDoc, 0);
>
> contents.saveGraphicsState();
>
> Matrix matrix = Matrix.getTranslateInstance(rect.getLowerLeftX(), rect.getLowerLeftY());
>
> contents.transform(matrix);
>
> contents.drawForm(form);
>
> contents.restoreGraphicsState();
>
>
> }
>
> Now, this seems to work fine. However, these is one issue ... I would like to have the background of the imported graphic be transparent. At present it comes in with a white background.
>
>
> Is there anyway to set a transparent background?
>
>
> Thanks for any help
>
> Steve
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Setting background transparency for imported PDFormXObject

Posted by Tilman Hausherr <TH...@t-online.de>.
You can't set only a part of it transparent. You can only have some 
transparency effect on the whole thing.

Maybe there is some blending that would remove white, then this would 
remove the white everywhere, or maybe have other effects. Have a look here:
http://www.pdfvt.com/PDFVT_TransparencyGuide.html

It would be easier to remove the white background in the xobject form 
you want to invoke, especially if this is a one-time job. However this 
may be tricky, a "background" can be many things.

Tilman

PS: use the PDPageContentStream with 5 parameters (read the javadoc 
why), unless you know in advance what kind of PDFs you append to.


Am 26.11.2017 um 19:19 schrieb Steve Jerman:
> Hi,
>
>
> I am creating an application that creates a report using a template page for each and then positions graphics on each page.
>
>
> To allow me to use vector based graphics, they are each imported as PDFs:
>
>
> try (PDPageContentStream contents = new PDPageContentStream(doc, currentPage, AppendMode.APPEND, true);
>
> PDDocument imageDoc = PDDocument.load(pdfGraph);) {
>
>
> LayerUtility layerUtility = new LayerUtility(doc);
>
> PDFormXObject form = layerUtility.importPageAsForm(imageDoc, 0);
>
> contents.saveGraphicsState();
>
> Matrix matrix = Matrix.getTranslateInstance(rect.getLowerLeftX(), rect.getLowerLeftY());
>
> contents.transform(matrix);
>
> contents.drawForm(form);
>
> contents.restoreGraphicsState();
>
>
> }
>
> Now, this seems to work fine. However, these is one issue ... I would like to have the background of the imported graphic be transparent. At present it comes in with a white background.
>
>
> Is there anyway to set a transparent background?
>
>
> Thanks for any help
>
> Steve
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org