[
https://issues.apache.org/jira/browse/PDFBOX-1176?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13607654#comment-13607654
]
Maruan Sahyoun commented on PDFBOX-1176:
----------------------------------------
Try this
PDDocument document = PDDocument.load( .... );
PDPage page = (PDPage)
document.getDocumentCatalog().getAllPages().get(0);
// The transparency, opacity of graphic objects can be set directly
on the drawing commands
// but need to be set to a graphic state which will become part of
the
// resources.
/* Set up the graphic state */
// Define a new extended graphic state
PDExtendedGraphicsState extendedGraphicsState = new
PDExtendedGraphicsState();
// Set the transparency/opacity
extendedGraphicsState.setNonStrokingAlphaConstant(0.5f);
// Get the page resources.
PDResources resources = page.findResources();
// Get the defined graphic states.
Map graphicsStateDictionary = resources.getGraphicsStates();
graphicsStateDictionary.put("TransparentState",
extendedGraphicsState);
resources.setGraphicsStates(graphicsStateDictionary);
/* End of setup */
PDFont font = PDType1Font.HELVETICA;
// Now we will be able to call the state definition before doing
the drawing
PDPageContentStream contentStream = new
PDPageContentStream(document, page,true,true);
contentStream.appendRawCommands("/TransparentState gs\n");
contentStream.setNonStrokingColor(Color.yellow);
contentStream.beginText();
contentStream.setFont( PDType1Font.HELVETICA, 72 );
contentStream.moveTextPositionByAmount( 10, 10 );
contentStream.setTextRotation(1,100,100);
contentStream.drawString( "Watermark" );
contentStream.endText();
contentStream.close();
document.save("watermark.pdf");
> Watermark
> ---------
>
> Key: PDFBOX-1176
> URL: https://issues.apache.org/jira/browse/PDFBOX-1176
> Project: PDFBox
> Issue Type: Wish
> Reporter: Rubesh MX
> Labels: Watermark
> Original Estimate: 24h
> Remaining Estimate: 24h
>
> I am checking if watermarks can be added to a PDF doc and the same way can
> be removed, so far I could not find any option to do that with PDFBox; It
> will be better if we have an option to add and remove watermak to a PDF.
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira