This is a console application that modifies PDF files in a specified directory. The modifications include adding a watermark text to each page of the PDF.
The project uses the following namespaces:
iText.Kernel.Colors
iText.Kernel.Font
iText.Kernel.Pdf
iText.Kernel.Pdf.Canvas
iText.Kernel.Pdf.Extgstate
iText.Kernel.Geom
- The
Main
method gets all PDF files in the specified directory. - For each PDF file, it calls the
HandleFile
method. - The
HandleFile
method creates a newPdfReader
object for the current PDF file and a newPdfDocument
object for the output file. - It then calls the
ModifyPages
method to modify the pages of the PDF document. - The
ModifyPages
method loops through all pages of the PDF document. For each page, it creates a newPdfCanvas
object and adds a watermark text to the page. - The watermark text is "sample text", and it is added with a font size of 36. The text is positioned 5% from the left and top of the page.
- The watermark text is added on a grey rectangle with 50% transparency to make it look like a watermark.
- Finally, the
PdfDocument
object is closed, saving the modifications to the new file.
To use this application, simply run the Program.cs
file in your .NET environment. Make sure to update the directoryPath
variable in the Main
method to the directory containing the PDF files you want to modify.
Remember to install iText as well
dotnet add package itext.bouncy-castle-adapter --version 8.0.3
dotnet add package itext --version 8.0.3
This is an auto-generated README