You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Don Wills <do...@portablesoftware.com> on 2019/01/05 20:30:41 UTC

question about creating a PDF - layers and PDPageContentStream

Hello,

I'm a newbie to PDFBox.  It appears to be a very useful tool for what we're trying to accomplish.

FWIW, in the past we have been building our own raw PDF files from scratch for simple printed output from Java code.  It was tedious, but with a minimal API on top, it worked.  Thus I have a bit of knowledge about the structure of a PDF, but not much more.

I have noticed that when images, text and graphics are mixed in a single PDPageContentStream in no particular order, it appears that the elements are displayed and printed in layers.  From my initial tests, it appears that graphics (lines and filled polygons) are at the lowest layer, text is above the graphics, and images are on top of graphics and text.  Is that correct?  Is that a feature or an accident?  Is that a feature of the PDF spec or PDFBox?  Is that behavior documented anywhere?

I need to put a watermark on each page of a report.  So for each page of the report I create a PDPageContentStream, draw the watermark image on that content stream, close it, and then create a second PDPageContentStream in APPEND mode for the page that contains the text, graphics and images of the page.  All seems to work well. Is that the correct approach, or is there another better method?

Also, is there a place where I can search for answers to questions like this?  I'm sure this particular question has been answered before.  I couldn't find anything on StackOverflow and I have no idea how to search the archives of this email list.

TIA.

Don Wills
Portable Software Company
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: question about creating a PDF - layers and PDPageContentStream

Posted by Tilman Hausherr <TH...@t-online.de>.
See also 
https://stackoverflow.com/questions/53108150/rotate-text-at-45-degree-angle-across-the-center-apache-pdfbox

Tilman

Am 06.01.2019 um 07:40 schrieb Tilman Hausherr:
> Am 05.01.2019 um 21:30 schrieb Don Wills:
>> Hello,
>>
>> I'm a newbie to PDFBox.  It appears to be a very useful tool for what 
>> we're trying to accomplish.
>>
>> FWIW, in the past we have been building our own raw PDF files from 
>> scratch for simple printed output from Java code.  It was tedious, 
>> but with a minimal API on top, it worked.  Thus I have a bit of 
>> knowledge about the structure of a PDF, but not much more.
>>
>> I have noticed that when images, text and graphics are mixed in a 
>> single PDPageContentStream in no particular order, it appears that 
>> the elements are displayed and printed in layers.  From my initial 
>> tests, it appears that graphics (lines and filled polygons) are at 
>> the lowest layer, text is above the graphics, and images are on top 
>> of graphics and text.  Is that correct? Is that a feature or an 
>> accident?  Is that a feature of the PDF spec or PDFBox?  Is that 
>> behavior documented anywhere?
>
>
> It depends on the order in the content stream. This can be chosen freely.
>
> See the PDF specification...
>
>
>>
>> I need to put a watermark on each page of a report.  So for each page 
>> of the report I create a PDPageContentStream, draw the watermark 
>> image on that content stream, close it, and then create a second 
>> PDPageContentStream in APPEND mode for the page that contains the 
>> text, graphics and images of the page.  All seems to work well. Is 
>> that the correct approach, or is there another better method?
>
>
> Yes that is one solution.
>
>
> Another is to append and to use transparency.
>
>
>
>>
>> Also, is there a place where I can search for answers to questions 
>> like this?  I'm sure this particular question has been answered 
>> before.  I couldn't find anything on StackOverflow and I have no idea 
>> how to search the archives of this email list.
>
>
> "pdfbox watermark" finds a few on stackoverflow.
>
>
> Tilman
>
>
>>
>> TIA.
>>
>> Don Wills
>> Portable Software Company
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
>> For additional commands, e-mail: users-help@pdfbox.apache.org
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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


Re: question about creating a PDF - layers and PDPageContentStream

Posted by Don Wills <do...@portablesoftware.com>.
Tilman,

Thanks for the quick response.  I had an error in my test program that was leading me astray.  I'm able to put the watermark image on the page without having to use two PDPageContentStreams by always placing the image first in the one content stream on the page.

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


Re: question about creating a PDF - layers and PDPageContentStream

Posted by Tilman Hausherr <TH...@t-online.de>.
Am 05.01.2019 um 21:30 schrieb Don Wills:
> Hello,
>
> I'm a newbie to PDFBox.  It appears to be a very useful tool for what we're trying to accomplish.
>
> FWIW, in the past we have been building our own raw PDF files from scratch for simple printed output from Java code.  It was tedious, but with a minimal API on top, it worked.  Thus I have a bit of knowledge about the structure of a PDF, but not much more.
>
> I have noticed that when images, text and graphics are mixed in a single PDPageContentStream in no particular order, it appears that the elements are displayed and printed in layers.  From my initial tests, it appears that graphics (lines and filled polygons) are at the lowest layer, text is above the graphics, and images are on top of graphics and text.  Is that correct?  Is that a feature or an accident?  Is that a feature of the PDF spec or PDFBox?  Is that behavior documented anywhere?


It depends on the order in the content stream. This can be chosen freely.

See the PDF specification...


>
> I need to put a watermark on each page of a report.  So for each page of the report I create a PDPageContentStream, draw the watermark image on that content stream, close it, and then create a second PDPageContentStream in APPEND mode for the page that contains the text, graphics and images of the page.  All seems to work well. Is that the correct approach, or is there another better method?


Yes that is one solution.


Another is to append and to use transparency.



>
> Also, is there a place where I can search for answers to questions like this?  I'm sure this particular question has been answered before.  I couldn't find anything on StackOverflow and I have no idea how to search the archives of this email list.


"pdfbox watermark" finds a few on stackoverflow.


Tilman


>
> TIA.
>
> Don Wills
> Portable Software Company
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


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