[
https://issues.apache.org/jira/browse/PDFBOX-5101?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17283866#comment-17283866
]
Michael Klink commented on PDFBOX-5101:
---------------------------------------
You can color your pages like this:
{code:java}
PDDocument document = ...;
PDExtendedGraphicsState gState = new PDExtendedGraphicsState();
gState.setBlendMode(BlendMode.DARKEN);
for (PDPage page : document.getDocumentCatalog().getPages()) {
PDRectangle cropBox = page.getCropBox();
try ( PDPageContentStream canvas = new PDPageContentStream(document,
page, AppendMode.APPEND, false, true) ) {
canvas.setGraphicsStateParameters(gState);
canvas.setNonStrokingColor(0.95686f, 0.8f, 0.8f);
canvas.addRect(cropBox.getLowerLeftX(), cropBox.getLowerLeftY(),
cropBox.getWidth(), cropBox.getHeight());
canvas.fill();
}
}
document.save(...);
{code}
_([ColorPageWithBlendMode|https://github.com/mkl-public/testarea-pdfbox2/blob/master/src/test/java/mkl/testarea/pdfbox2/content/ColorPageWithBlendMode.java#L41]
test {{testForWithoutBGColor}})_
Applied to your [^without BG color.PDF] it produces [^without BG
color-darkened.PDF].
> White boxes after adding color in background
> --------------------------------------------
>
> Key: PDFBOX-5101
> URL: https://issues.apache.org/jira/browse/PDFBOX-5101
> Project: PDFBox
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 2.0.21
> Reporter: Wilhelm Ziegler
> Priority: Major
> Labels: how-to
> Attachments: with BG color.PDF, without BG color-darkened.PDF,
> without BG color.PDF
>
>
> Hey,
> I'm facing a problem when adding a background color to some documents with
> pdfbox. I am using the following code to add color do a document:
>
> {code:java}
> try (PDPageContentStream cs = new PDPageContentStream(doc, page,
> PDPageContentStream.AppendMode.PREPEND, true, true)) {
> cs.saveGraphicsState();
> cs.setGraphicsStateParameters(gs);
> cs.setNonStrokingColor(hexToColor(hexColor));
> cs.addRect(0, 0, page.getMediaBox().getWidth(),
> page.getMediaBox().getHeight()); cs.fill();
> cs.restoreGraphicsState();
> }
> {code}
> I've tried adding color in 3 different ways and always get the same problem
> (see attached documents). I don't know how to fix this and would really
> appreciate it if someone could help me out or steer me in the right
> direction. Thank you in advance
>
>
> Best regards,
> Wilhelm
--
This message was sent by Atlassian Jira
(v8.3.4#803005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]