Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PDFBox : PDPageContentStream's append mode misbehaving

I am drawing an image on one of the PDF page.. when I use PDPageContentStream stream = new PDPageContentStream(doc, page); to draw image, everything works fine.. see below image.

image

but when I use constructor PDPageContentStream(doc, page, true, true); to create PDPageContentStream and draw image, the newly added image gets inverted upside down..

image

not getting what's going wrong here..

PS. I am using library PdfBox-Android

like image 749
Rupesh Avatar asked Jan 13 '15 10:01

Rupesh


1 Answers

Use the constructor that has a fifth parameter, so to reset the graphic context.

public PDPageContentStream(PDDocument document, PDPage sourcePage, boolean appendContent, 
                            boolean compress, boolean resetContext) throws IOException

alternatively, save and restore the graphics state in the first content stream by calling

saveGraphicsState();
// ...
restoreGraphicsState();
like image 137
Tilman Hausherr Avatar answered Oct 19 '22 23:10

Tilman Hausherr