Dynamic PDF Content using
ITextSharp and PDF Template
This
article talks about, how we can update PDF content dynamically using ITextsharp
and an existing PDF template.
ITextSharp – Introduction:
It is an advanced tool library which is used
for creating/update complex pdf report. It also supports to create
documents and reports based on data from databases or xml files and Merge
or split pages from existing PDF files. It also supports Java, Android and
several languages.
Technologies/Language involved - C#, .Net Core, ITextsharp Library, Console
Pre-requisite:
Nuget Package:
iTextSharp.LGPLv2.Core
Namespace:
using iTextSharp.text.pdf;
PDF Template:
Create a PDF template with required Form fields
Steps:
1. 1.
Create a PDF Template with required Form fields
1. 2. Create a Console application
2.
3. Install the ITextsharp Nuget package
3. 4. Create a class which will be using to bind the model data
4. 5. Create a Struct or set of constants which will define the form
fields names
5. 6. Write a code to read the PDF template and convert to stream 6.
7. Using the stream, model object and ITextsharp(pdfreader,
pdfstamper, AcroFields) bind the model data to stream object 7.
8. Specify the path with output filename 8.
9. Create a FileStream using filename and Copy the output stream to
FileStream using CopyTo function.
9. 10. Go and check your output folder path and you can see the updated
PDF
|