We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Aspose.pdf Evaluation Version

Hi There,

I am using free trial version of to generate pdf. I have a template pdf document added with placeholders and am trying to replace those with simple text replace logic of aspose.pdf api. But the layout of template and generated pdf is differing.

E.g.
If my placeholder is center aligned with value as @Test.Item.Value, then the replacement happens from ‘@’ keyword and the final pdf has this text wrongly aligned i.e. to the left.
Also if the replaced word is smaller than placeholder then it leaves space after the word.
If @Test.Item.Value gets replaced with ‘hello’ then it adds spaces for remaining letters in placeholders.

So is it with trial version only? will it work fine with licensed copy?

@nisg55

Thanks for contacting support.

The only limitation of API trial version is that you can process only 4 elements as per any collection, which can be avoid by applying temporary license. However, as far as the issue which you are facing, is concerned, please share your sample PDF document along with the code snippet which you are using. We will test the scenario in our environment and respond you accordingly.

Using below code to replace the pdf text-

PdfContentEditor pdfContentEditor = new PdfContentEditor();
TextReplaceOptions options = new TextReplaceOptions(TextReplaceOptions.ReplaceAdjustment.AdjustSpaceWidth);
pdfContentEditor.TextReplaceOptions = options;

pdfContentEditor.BindPdf(@“Aspose\TemplatePdf.pdf”);

pdfContentEditor.ReplaceText("@Data.Person.Id", “1”);
pdfContentEditor.ReplaceText("@Data.Person.Name.Firstname", “test”);
pdfContentEditor.ReplaceText("@Data.Person.EmpType", “C”);
pdfContentEditor.ReplaceText("@Data.Person.Birthdate", “01 August 1999”);
pdfContentEditor.ReplaceText("@Data.Person.Birthdate.Day", “2”);
pdfContentEditor.ReplaceText("@Data.Person.Birthdate.Month", “August”);

pdfContentEditor.Save(@“Aspose\ReplacedPdf.pdf”);

Please find attached pdf used -

Template pdf:
TemplatePdf.pdf (198.0 KB)

Result pdf:
ReplacedPdf.pdf (238.7 KB)

Please advise as soon as possible.

@nisg55

Thanks for sharing sample document and code snippet.

We have tested the scenario in our environment and managed to reproduce the issue which you have stated. We have also tried a DOM based code snippet to replace the text from PDF like following but did not get much success.

Document pdfdocument = new Document(dataDir + "TemplatePdf.pdf");
TextFragmentAbsorber tfa = new TextFragmentAbsorber();
tfa.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.None;
pdfdocument.Pages[1].Accept(tfa);
foreach(TextFragment tf in tfa.TextFragments)
{
 switch(tf.Text)
 {
  case "@Data.Person.Id":
   tf.Text = "1";
   break;
  case "@Data.Name.Firstname":
   tf.Text = "test";
   break;
  case "@Data.Person.EmpType":
   tf.Text = "C";
   break;
  case "@Data.Person.Birthdate":
   tf.Text = "01 August 1999";
   break;
  case "@Data.Person.Birthdate.Day":
   tf.Text = "2";
   break;
  case "@Data.Person.Birthdate.Month":
   tf.Text = "August";
   break;
 }
}
pdfdocument.ProcessParagraphs();
pdfdocument.Save(dataDir + "replacedtextw.pdf"); 

We have logged an issue as PDFNET-43163 in our issue tracking system. We will further investigate this and keep you updated with the status of its correction. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hi Asad,

Could you please update on this issue? It would be great if you can provide update on this.
Our major concern is the horizontal alignment of the text in table should not be changed.

@nisg55

Thanks for writing back.

Now that issue has been logged in our issue tracking system, our product team will investigate it as per their development schedule. Though we have recorded your concerns and intimated relevant team about them. As soon as we have some significant updates regarding its resolution, we will certainly inform you. Please spare us little time.

We are sorry for the inconvenience.

Hello Asad,

Any updates on this issue?

@nisg55

Thanks for posting your inquiry.

As we recently noticed the earlier logged issue, so I am afraid it is pending for review. Product team will definitely look into this after resolving other pending issues in the queue, which were reported prior to this. As soon as we have some news regarding its resolution, we will update you. Please be patient and spare us little time.

We are sorry for this inconvenience.