0

I have some scanned PDF documents (pretty flat, no selectable text, tags, objects, etc) and I would like to add a footer that can also be removed after being added. However, if it overwrites on top of anything, I want to remove the footer only. We can assume that, after the watermark is added, it won't be rescanned, changed, or flattened. (I should mention, in case any iText employees see this question, that my organization has recently purchased a license but I just started this project and I am waiting to have it sent to me so I can register for official support.)

I found an excellent answer for adding and removing watermarks here: iText 7 - Add and Remove Watermark on a PDF . My problem, as stupid as it might sound, is I'm really struggling with getting the variables right, even after lots of trial and error. The scanned documents seem to be coming in as portrait (when viewed in a PDF viewer) but they have a rotation of 270 such that, PdfDocument.GetPage(i).GetPageSize() and GetPageSizeWithRotation() have the height and width reversed and I need to take this into account but also don't want to assume that this is always the case. The footer should be centered at the bottom of the page.

The method signature can be as in the link provided (https://stackoverflow.com/a/45225597):

public static void WatermarkPDF(string sourceFile, string destinationPath)

Thank you in advance for the help and support.

Okay, BIG TIME EDIT: requirements are changing. In fact, they want to be able to have 2 lines of text as a left aligned header and have the ability to remove or replace either or or both AND additionally, have a right aligned footer that also can be removed or replaced. Not sure anymore if this should be implemented as a watermark. Again, I can assume that, once I add the headers and/or footers, the document won't be reflattened or edited in any major way... so, if they are added as elements, they should be able to be removed as elements but the problem is the scanned documents have no structure to begin with anyway (at least they don't seem to so far). So, there's no parent element, tag, or whatever.

Tamer Rifai
  • 169
  • 2
  • 14
  • 1
    Footers and headers are not really watermark material. If they shall be easy to change, how about making them free text annotations or even form fields? – mkl Jul 25 '19 at 05:21
  • Thank you for this suggestion @mkl . I'll try it out. – Tamer Rifai Jul 25 '19 at 14:07
  • @mlk I have ALMOST accomplished what I wanted and I'll post my answer here when I'm done. It works exactly how I wanted for non-rotated pages. However, the scanned documents, although viewed in portrait in any PDF viewer, are actually rotated 270 degrees. If I could, somehow, make rotation = 0 but keep the view of the PDF exactly the same, I could do what I'm already doing for the non-rotated pages. Any help would be appreciated. Thank you! – Tamer Rifai Jul 26 '19 at 20:56
  • *"If I could, somehow, make rotation = 0 but keep the view of the PDF exactly the same"* - if there aren't any annotations in your source pdf yet, that is feasible. But it also shouldn't be too difficult to tweak your solution up to now to also be able to handle rotated pages. – mkl Jul 27 '19 at 05:21

0 Answers0