I was experimenting with Content Replacer and I noticed that the PDF file was significantly larger after using it. I thought it was something I was doing, so I went back to the sample code (below) and ran it. I commented out the image replace so that it only replace text. The original PDF file (BusinessCardTemplate.pdf) is 17K. The PDF after using Content Replacer is 34Kb - twice the size. Why is that, and how do I prevent it?
Console.WriteLine(“Opening the input file…”)
Using doc As PDFDoc = New PDFDoc(input_path + “BusinessCardTemplate.pdf”)
doc.InitSecurityHandler()
’ first, replace the image on the first page
Using replacer As ContentReplacer = New ContentReplacer()
Dim page As Page = doc.GetPage(1)
'Dim img As Image = Image.Create(doc.GetSDFDoc(), input_path + “peppers.jpg”)
’ replacer.AddImage(page.GetMediaBox(), img.GetSDFObj())
’ next, replace the text place holders on the second page
replacer.AddString(“NAME”, “John Smith”)
replacer.AddString(“QUALIFICATIONS”, “Philosophy Doctor”)
replacer.AddString(“JOB_TITLE”, “Software Developer”)
replacer.AddString(“ADDRESS_LINE1”, “#100 123 Software Rd”)
replacer.AddString(“ADDRESS_LINE2”, “Vancouver, BC”)
replacer.AddString(“PHONE_OFFICE”, “604-730-8989”)
replacer.AddString(“PHONE_MOBILE”, “604-765-4321”)
replacer.AddString(“EMAIL”, “info@pdftron.com”)
replacer.AddString(“WEBSITE_URL”, “http://www.pdftron.com”)
’ finally, apply
replacer.Process(page)
End Using
doc.Save(output_path + “BusinessCard.pdf”, 0)
End Using
Console.WriteLine(“Done. Result saved in BusinessCard.pdf”)