You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@pdfbox.apache.org by Pascal Schumacher <pa...@gmx.net> on 2022/01/31 17:28:29 UTC

Rect: lower-left/upper-right vs. upper-left/lower-right coordinates

Hi,

I am adding a signature field to a pdf generated by another application
using this (simplified and abridged code):


try (PDDocument pdDocument = Loader.loadPDF(pdfBytes)) {
     PDPage pdPage = pdDocument.getPage(0);
     PDAcroForm acroForm = pdDocument.getDocumentCatalog().getAcroForm();
     String defaultAppearanceString = "/Helv 0 Tf 0 g";
     acroForm.setDefaultAppearance(defaultAppearanceString);

     // Create empty signature field, it will get the name "SignatureX"
     PDSignatureField signatureField = new PDSignatureField(acroForm);
     PDAnnotationWidget widget = signatureField.getWidgets().get(0);
     Rectangle2D rect = new Rectangle2D.Float(315, 368, 224, 16);
     widget.setRectangle(rect);
     widget.setPage(pdPage);
     widget.setPrinted(true);
     pdPage.getAnnotations().add(widget);

     acroForm.getFields().add(signatureField);

    ...
}

The signature field works fine in Adobe Acrobat Reader.

The problem is that the pdf will be displayed/processed by another
in-house application.
The developers tell me that "Rect" has to be defined lower left (x,y)
and upper right (x,y).
When I open the pdf with PDFBox debugger I see "Rect 315 472 540 457"
for the signature field, so it seems to be defined as upper left (x,y)
and lower right (x,y) coordinates.
I took a look at the PDF 1.7 specification and the examples seem to
follow the lower left/upper right style, while the text suggests upper
left/lower right style (I may very well be misunderstanding the spec,
because I have basically no knowledge of the pdf format). I guess both
are allowed?

Is there a way to generate signature field with lower left/upper right
coordinates with PDFBox?

Thanks and kind regards,

Pascal

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Rect: lower-left/upper-right vs. upper-left/lower-right coordinates

Posted by Pascal Schumacher <pa...@gmx.net>.
Hello Waldemar,

thank you very much for your reply.

I am aware of the difference in the coordinate system. The position of
the rectangle on the pdf is correct (at least as it is displayed by
Acrobat Reader). My problem is that the pdf generated by PDF Box (the
coordinates of the /rect) does not meet the expectations of the
developers of a consumer application (they may very well have incorrect
expectations).

I wanted to use a PDRectangle at first by I did not find a way to use it
to set the rectangle of a PDAnnotationWidget, therefore I switched to a
Rectangle2D.

Kind regards,
Pascasl

Am 31.01.2022 um 19:09 schrieb Waldemar Dick:
> Hello Pascal,
>
> In the PDF coordinate system origin (0, 0) is defined in the lower left of the page.
> The Java Geometrie coordinate system defines origin (0, 0) in the UPPER left. See JavaDoc of java.awt.geom.Rectangle2D.Float#Float(float, float, float, float).
>
> I think that is where the confusion comes from. Try either to use a PDRectangle or check out the code, how a Rectangle2D is converted into a PDRectangle.
>
>> Rectangle2D rect = new Rectangle2D.Float(315, 368, 224, 16);
>> When I open the pdf with PDFBox debugger I see "Rect 315 472 540 457"
>
> Further, check if you need to consider page rotation in your solution.
> If you do, then you will have to recalculate your x, y depending on the page rotation (page.getRotation()).
>
>
> Waldemar
>
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
> For additional commands, e-mail: users-help@pdfbox.apache.org
>


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org


Re: Rect: lower-left/upper-right vs. upper-left/lower-right coordinates

Posted by Waldemar Dick <wa...@skribble.com.INVALID>.
Hello Pascal,

In the PDF coordinate system origin (0, 0) is defined in the lower left of the page.
The Java Geometrie coordinate system defines origin (0, 0) in the UPPER left. See JavaDoc of java.awt.geom.Rectangle2D.Float#Float(float, float, float, float).

I think that is where the confusion comes from. Try either to use a PDRectangle or check out the code, how a Rectangle2D is converted into a PDRectangle.

> Rectangle2D rect = new Rectangle2D.Float(315, 368, 224, 16);
> When I open the pdf with PDFBox debugger I see "Rect 315 472 540 457"


Further, check if you need to consider page rotation in your solution.
If you do, then you will have to recalculate your x, y depending on the page rotation (page.getRotation()).


Waldemar





---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@pdfbox.apache.org
For additional commands, e-mail: users-help@pdfbox.apache.org