pdfbox-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From John Hewson <j...@jahewson.com>
Subject Re: Equivalent replacements for drawLine and drawPolygon?
Date Thu, 27 Aug 2015 20:36:21 GMT
Those methods are deprecated in 1.8 and have been removed in 2.0. I’d recommend following
the advice in the JavaDoc for those methods:

@deprecated Use {@link #moveTo} and {@link #lineTo} methods instead.

It’s trivial to call those methods for each point in an array. Note that there is no such
thing as a
line or a polygon in PDF which is why those methods were remove. There are only paths.

— John

> On 26 Aug 2015, at 15:32, Roberto Nibali <rnibali@gmail.com> wrote:
> 
> 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


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message