0

Simarly to this question I want to find the location of the last item in a PDF document and add content at that place, more specifically I would like to add an electronic signature at a position where one would normally put a regular handwritten signature on letters.

In the question above the user is making the PDF file but I am importing an existing PDF file that can have any structure as such. Therefore, as far as I can see, I can not use the same method as I do not know if the last object made was a paragraph or some other object.

I found the following function and property on the PdfWriter class that bode well but can not find any documentation that explains the output I get when I run the programme:

        PdfWriter w = _document.GetWriter();
        long currentPos = w.GetCurrentPos();
        long pos = w.Position;

When I run this the output I get is something like the number 84178. What unit is that? Can I use this number to calculate how much vertical space there is left on the page and if it is too small then add a page and have the signature on the next page?

rbadi76
  • 21
  • 8
  • Just to be clear: you have an existing pdf, you want to open that pdf and put a signature at the position of the last element that was added to the pdf prior to you opening it? – Samuel Huylebroeck Nov 22 '16 at 14:10
  • rbadi, by *"last object"* you surely mean "bottom-most", or do you actually mean the "last object drawn in the content stream"? In that case consider parsing the page in question using a `TextMarginFinder` as listener. You may have to fine tune the code as you probably do not want to sign below footers... – mkl Nov 22 '16 at 18:18
  • @SamuelHuylebroeck No, I mean the bottom-most as mkl says. Sorry for the ambiguity. – rbadi76 Nov 23 '16 at 16:28
  • @mkl - I mean the bottom-most, sorry for the amiguity. Indeed, I don't want to sign below footers. – rbadi76 Nov 23 '16 at 16:30
  • Concerning footers, do you have criteria to recognize them? Like "text in the bottom inch of the page"? I ask because in general footers are not inherently recognizable as such in PDFs. – mkl Nov 23 '16 at 21:55
  • @mkl - Ah, ok, good to know. Then I suppose we would do something like that and simply add a page if the bottom 1 or 2 inches are populated and put the signature there. – rbadi76 Nov 24 '16 at 09:31

0 Answers0