Hi,
I have a pdf file having 10(no of variables change pdf to pdf ) dynamic variables like <>, <> ect.
My requirement is to supply values(take values from database) for all dynamic variable and after replace, it generate a new pdf file.
Here problem is when I supply all 10 values to replace then it working fine, but if I supply less than 10 values then it generate a corrupted pdf file.
Below is the code I am using for edit pdf file.
using Aspose.Pdf;
using Aspose.Pdf.Text;
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense(“Aspose.Pdf.lic”);
PDFVariablesBAL myPDFVariablesBAL = new PDFVariablesBAL();
Dictionary<string, string> pdfVariableList = (Dictionary<string,string>)myPDFVariablesBAL.SelectAll(tempArrary[0], tempArrary[1]);
Document pdfDocument = new Document(pdfFilePath);
foreach (KeyValuePair<string, string> item in pdfVariableList)
{
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(item.Key);
pdfDocument.Pages.Accept(textFragmentAbsorber);
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
foreach (TextFragment textFragment in textFragmentCollection)
{
textFragment.Text = item.Value;
}
}
Please give a solution.
Thank you.