Hi
I have a sample to code to add text to PDF page. Output PDF is giving an error if i try to add text to some pages. Page 4 is working fine. I can open source document without any error messages.
Page 1 is giving an error. But i can add an image stamp (pdfPage.AddStamp()) to page 1 and open the output document without any errors.
“An error on this page. Acrobat may not display the page correctly. Please contact the person who created the PDF document to correct the problem”.
public void TestTextStamp(string inputPdfFullPath, string outputPDFFullPath, int pageNo)
{
try
{
Document pdfDocument = new Document(inputPdfFullPath);
// add age page to PDF document
pdfDocument.Pages.Add();
// create TextBuilder for first page
TextBuilder tb = new TextBuilder(pdfDocument.Pages[pageNo]);
// TextFragment with sample text
TextFragment fragment = new TextFragment(“Test message”);
// set the font for TextFragment
fragment.TextState.Font = FontRepository.FindFont(“Arial”);
fragment.TextState.FontSize = 10;
// set the formatting of text as Underline
fragment.TextState.Underline = true;
// specify the position where TextFragment needs to be placed
fragment.Position = new Position(10, 800);
// append TextFragment to PDF file
tb.AppendText(fragment);
// save the PDF file
pdfDocument.Save(outputPDFFullPath);
}
catch (Exception)
{
throw;
}
}
OS : Windows 10
IDE : VS2017
Target Framework : 4.6.2
Project Type : Class Library
Language : C#
Aspose.Pdf : 10.3.0.0