Hi,
I am converting aspose.word to aspose.pdf jar because of some HTML alignment issues. In aspose word I have used FindandReplace and Mail Merged fields to update lot of data. But I am wondering how to work with Aspose pdf similar to mail merge fields. Can you provide some solution.
Thanks
Lakshmi M
@lakshmiM
In Aspose.PDF, you can use either find and replace text functionality in order to place desired values in the PDF template OR you can create a PDF template using AcroForm and fill form fields to create desired output. Please check below API documentation articles for more information:
Hi,
I have a PDF HTML text like below. I tried with couple of pattern matches and still it is not giving.
Text:
The following this Attachment: <<MMRSpec>> test
I tied with Pattern.compile("<<(.?)>>") or Pattern.compile("<<(.?)>>"). But still code is not recognizing the text. And the same logic is working fine whether try with FindAndReplace in aspose.word. Can you help me with this.
TextFragmentAbsorber textFragmentAbsorberPattern = new TextFragmentAbsorber(Pattern.compile("<<(.*?)>>"));
// Set text search option to specify regular expression usage
TextSearchOptions textSearchOptionsPattern = new TextSearchOptions(true);
// textSearchOptionsPattern.setRegularExpressionUsed(true);
textFragmentAbsorberPattern.setTextSearchOptions(textSearchOptionsPattern);
// Accept the absorber for all the pages
pdfDocument.getPages().accept(textFragmentAbsorberPattern);
// Get the extracted text fragments
TextFragmentCollection textFragmentCollectionPattern = textFragmentAbsorberPattern.getTextFragments();
// Loop through the fragments
for (TextFragment textFragment : textFragmentCollectionPattern)
{
System.out.println("Text : {0} "+ textFragment.getText());
}
@lakshmiM
Would you please share your sample PDF document with us so that we can test the scenario in our environment and address it accordingly.
Can we create multiple sub aspose.pdf.Documents and combine into One Parent aspose.pdf.Document ? We are doing the below with aspose.word. I am looking similar approach with PDF. That way we want to maintain separate Header and Footer for each sub-documents.
Here is the sample code snippet with aspose.word:
Document wordDocument = new Document();
for (DocGenSelectedTemplate template : selectedTemplates) {
if (!template.getTemplatetypeName().toUpperCase().equals("SCHEDULE A")) {
Document wordDocumentTemplate = new Document();
DocumentBuilder builderTemplate = new DocumentBuilder(wordDocumentTemplate);
builderTemplate.insertHtml("Template 1");
wordDocument.appendDocument(wordDocumentTemplate, ImportFormatMode.KEEP_SOURCE_FORMATTING);
} else if (template.getTemplatetypeName().toUpperCase().equals("SCHEDULE A")
&& template.getNetworkCode() != null) {
Document wordDocumentTemplate = new Document();
DocumentBuilder builderTemplate = new DocumentBuilder(wordDocumentTemplate);
builderTemplate.insertHtml("Template 2");
wordDocument.appendDocument(wordDocumentTemplate, ImportFormatMode.KEEP_SOURCE_FORMATTING);
} else if (template.getTemplatetypeName().toUpperCase().equals("SCHEDULE A")
&& template.getNetworkCode() == null) {
Document wordDocumentTemplate = new Document();
DocumentBuilder builderTemplate = new DocumentBuilder(wordDocumentTemplate);
builderTemplate.insertHtml("Template 3");
wordDocument.appendDocument(wordDocumentTemplate, ImportFormatMode.KEEP_SOURCE_FORMATTING);
}
}
I don’t see appendDocument function with aspose pdf. Is there any API that we could use to append multiple document templates into single document.
@lakshmiM
For this purpose, you need to use PdfFileStamp that can work like appending one document into another. Please check below example in the documentation article: