Reputation: 1256
I'm using PDFBox 1.8.11. I'm trying to draw a line from (0,0) to (x,y). That's how I do it:
PDPageContentStream stream = new PDPageContentStream(document, page, true, false);
stream.setStrokingColor(80, 100, 200);
stream.setLineWidth(1.0f);
stream.drawLine(0, 0, x, y);
stream.close();
All works fine for almost all PDFs. But for one PDF if I append to the stream (the third parameter of new PDPageContentStream()) the line is drawn from the right bottom corner and goes beyond the page right border. If I don't append to the content stream, the line is drawn as expected.
It happens only for this PDF (maybe some others), and I'm wondering if I miss anything. Maybe I need to reset some coordinate system before drawing or the like?
P.S. The media box of the page starts from (0,0) and is equal to the page size.
Thanks in advance
Upvotes: 1
Views: 613
Reputation: 1256
Actually this post (PDFBox : PDPageContentStream's append mode misbehaving) explains the issue.
Setting the last parameter resetContext to true in the constructor below solved my problem.
public PDPageContentStream(PDDocument document, PDPage sourcePage,
boolean appendContent,
boolean compress, boolean resetContext)
throws IOException
Upvotes: 2