Hi
[Using PDFBox from latest SVN checkout]
Today, I toyed around by stamping objects onto a PDF and quickly moved
towards a set of abstracted functions to do so (one to draw a line, one to
set a text, one to draw a rectangle). When doing so, I hit some obsolete
functionality inside PDFBox, which I believe has no equivalent counterpart.
Consider the following methods:
private void addRect(PDDocument srcDoc, final PDPage page,
final float posX, final float posY, final float
offX, final float offY) throws IOException {
float[] rectX = new float[]{posX, posX + offX, posX + offX, posX};
float[] rectY = new float[]{posY, posY, posY + offY, posY + offY};
PDPageContentStream contentStream = new
PDPageContentStream(srcDoc, page, true, true,true);
contentStream.drawPolygon(rectX, rectY);
contentStream.close();
}
private void addLine(PDDocument srcDoc, final PDPage page,
final float fromX, final float fromY, final float
toX, final float toY) throws IOException {
PDPageContentStream contentStream = new
PDPageContentStream(srcDoc, page, true, true,true);
contentStream.drawLine(fromX, fromY, toX, toY);
//TODO needed??: contentStream.closeAndStroke();
contentStream.close();
}
Both of them contain deprecated method calls. However, I fail to see how
the suggested replacement functionality allows me to write the methods in
such an easy way I have done currently. Any suggestions?
Out of curiosity, is the closeAndStroke() call needed for the drawline()
functionality? I does not seem to make any difference to the end result.
Thanks and best regards
Roberto