Hello,
I have an issue with the TextStamp class generating a file that is sometimes 2MB larger than the original. We are making a searchable pdf by stamping the text back in the original pdf. What we do is for every word we stamp it in the pdf. This results in a file size that is significantly larger by about .5 to 3 MB whereas I would expect the increase in size to be more of the order of 20 - 100 KB. To minimize the size I did call OptimizeResources(). Additionally, I did try to use the TextFragment class based on the example in [1], however even when setting all colors to transparent you could still see the text on top of the image in the pdf. This is why we decided to use the TextStamp class.
Could you tell me how we can minimize the size increase even further? We plan to process millions of documents and saving some bytes here will really help.
Thanks in advance,
Phil
[1] http://www.aspose.com/docs/display/pdfnet/Add+Text+in+an+Existing+PDF+File
Code
public class Test
{
public static void Main(string[] args)
{
var doc =
new Document(
@"stampedPdfTooLarge_before.pdf");
int nrOfWords = 1000;
var page = doc.Pages[1];
float increment = ((float)page.PageInfo.Height) / nrOfWords / 2;
for (int i = 0; i < nrOfWords; i++)
{
string text = $"word_{i}";
TextStamp textStamp = new TextStamp(text)
{
Background = true,
XIndent = 0,
YIndent = increment * 2 * i,
Width = 4.5* text.Length,
Height = increment,
};
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.Transparent;
page.AddStamp(textStamp);
}
doc.OptimizeResources();
doc.Save(@"stampedPdfTooLarge_after.pdf");
}
}