Free Support Forum - aspose.com

Font file being automatically embedded when TextFragment.Text is changed

I am evaluating Aspose.Pdf for possible use in a document processing system my client wants to develop.

I am using TextFragmentAbsorber to locate TextFragments containing placeholder text strings. This works VERY nicely.

However, if I set TextFragment.Text = String.Empty to clear a CourierNew placeholder text string, a 190K CourierNew font file is being automatically embedded in the output PDF file. Here are the objects being added:

278 0 obj
<</Descent -300/FontName/CourierNew/Ascent 832/FontFile2 282 0 R/Flags 32/StemV 0/CapHeight 650/ItalicAngle 0/FontBBox[-21 -679 637 1020]/Type/FontDescriptor>>
endobj

282 0 obj
<</Length1 303296/Filter/FlateDecode/Length 192980>>stream....

Is there a way to prevent this font file from being embedded?

If not, is there a way to remove the embedded font file?

Hi Justjack,

Thanks for your interst in our products.

Can you please share some details regarding sample code and PDF Document that you need to generate with Aspose.Pdf. However during my testing, I am unable to notice any problem when using the code snippet shared over Add Text in an Existing PDF File.

We are really sorry for your inconvenience.

Thanks & Regards,

Here is a code snippet that shows the problem. The input PDF file is 25K. The ouput PDF is 214K

String inputPath = "C:\\Temp\\TestInput.pdf";

String outputPath = "C:\\Temp\\TestOutput.pdf";

String phrase = "X001222222222222222222222>";

Document doc = new Document(inputPath);

TextFragmentAbsorber absorber = new TextFragmentAbsorber(phrase);

doc.Pages[1].Accept(absorber);

int nFragments = absorber.TextFragments.Count;

TextFragment textFragment = absorber.TextFragments[1];

textFragment.Text = String.Empty;

doc.Save(outputPath);

Hi,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for sharing the template file and sample code.

Which version of Aspose.Pdf for .NET are you using. I used the latest version of Aspose.Pdf for .NET v6.3.0 with your provided template file and sample code and the resultant file is only 24.7KB (resultant file attached). Please download and try the latest from the following link and let us know if it works fine for you.

http://www.aspose.com/community/files/51/.net-components/aspose.pdf-for-.net/entry334920.aspx

Thank You & Best Regards,

Thanks for the info. I was running 6.2. I installed 6.3 and as you said, the code sample works fine.

My client, for whom I am evaluating Aspose.Pdf, also has a requirement to merge multiple PDFs onto a single page.

Consider attachment AutoIdACard1.pdf. My client needs to be able to concatenate 2-3 copies of this PDF onto a single page. See AutoIdACard_Out.pdf.

Does Aspose.Pdf provide a means to do this? This functionality was provided in another PDF SDK that we are evaluating, but we are hoping that Aspose.Pdf can provide it as well.

Thanks,

Jack Justice, Forest Objects, Inc

I have installed Aspose.Pdf 6.3 and that corrected the problem of a font file being embedded when TextFragment.Text was set to String.Empty.

But the font file is not being embedded when I ADD a TextFragment to a Page using TextBuilder. See the attached PDF files. Here is the code:

String inputPath = "C:\\Temp\\TestInput.pdf";

String outputPath1 = "C:\\Temp\\TestOutput.pdf";

String outputPath2 = "C:\\Temp\\TestOutput2.pdf";

String oldPhrase = "X001222222222222222222222>";

String newPhrase = "This is new added text....";

// Find and clear a TextFragment

Document doc1 = new Document(inputPath);

TextFragmentAbsorber absorber = new TextFragmentAbsorber(oldPhrase);

doc1.Pages[1].Accept(absorber);

int nFragments = absorber.TextFragments.Count;

TextFragment tf1 = absorber.TextFragments[1];

Position pos1 = tf1.Position;

tf1.Text = String.Empty;

doc1.Save(outputPath1);

// Add a TextFragment

Document doc2 = new Document(outputPath1);

Page page = doc2.Pages[1];

TextFragment tf2 = new TextFragment(newPhrase);

tf2.Position = pos1;

tf2.TextState.Font = tf1.TextState.Font;

tf2.TextState.FontSize = tf1.TextState.FontSize;

tf2.TextState.FontStyle = FontStyles.Bold;

tf2.TextState.ForegroundColor = tf1.TextState.ForegroundColor;

TextBuilder builder = new TextBuilder(page);

builder.AppendText(tf2);

doc2.Save(outputPath2);