vijendravijendra wrote:
I have been provided a 12 page PDF document by our marketing team.
Now, I have to read this PDF and replace values like customer name, address etc and generate a new PDF document for each customer.
Can I achieve this using PDFSharp?
I did something similar a while back. Mine was a one-page PDF which needed to be customized for each customer. The approach I used was:
- Step 0 (outside of your code, manually by hand): Create a template PDF file from the original document by deleting all cusomized/variable information (name, address etc.) and leaving just blank space there
- You may need 12 template files for each page in your PDF
Then your code will do the following:
- Open the template PDF file(s) into a PDfPage object(s)
- Loop through your customer records and:
- Create a new PdfDocument
- Create a PdfPage using your template (you may need to loop through your individual 12 templates here)
- Draw the customer info (name, address etc.) on the page (use XGraphics, XFont and XTextFormatter objects and DrawRectangle and DrawString methods)
- Save each PDF document
It may be tedious (especially if there is a lot of data pieces to insert, but it's doable).