Content Replacer increases file size

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”)


’ 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”, “”)

replacer.AddString(“WEBSITE_URL”, “”)

’ finally, apply


End Using

doc.Save(output_path + “BusinessCard.pdf”, 0)

End Using

Console.WriteLine(“Done. Result saved in BusinessCard.pdf”)

This is expected, because ContentReplacer is subsetting and embedding the fonts. The input test file does not contain embedded fonts.

Embedding fonts is the only way to guarantee rendering accuracy across all devices, which is the one of the most important features of a PDF.

This answer doesn’t make much sense to me. If the PDF contains text that should be replaced, the replaced text should behave exactly the way the original text did. Arbitrarily embedding fonts is not a desirable behavior. My PDF is intended for systems where I know the fonts will be present - I don’t want to inflate the size of the PDF by embedding fonts.

If the original PDF doesn’t contain embedded fonts, the new PDF shouldn’t either.