Insert pdf document into another pdf document based on a text tag

Hello,

I’m fairly new to the Aspose Words/PDF library and wanted to inquire about how to approach a particular requirement.

  1. We have a Word Document template that can have a “text” value placeholders. For example, <first_name> <last_name> where these placeholders will be replaced with the actual name like John Doe when we save the template to PDF. Additionally, we can have a place holder called <pdf_attachments> where this would be a different PDF Document “injected”/“inserted” into that placeholder.

  2. The <pdf_attachment> tag could exist anywhere. E.g., top of the page, bottom of the page, middle of the page. Maybe even multiple tags on one page.

  3. Can you recommend an approach to this requirement? Maybe a code sample already exists for this use case. I have a good idea on concatenating and/or inserting functionality. I’m interested if something may already exist for my specific requirement. Seems like the complicated part will be scanning through the document for the placeholders and inserting the content accordingly. Any suggestions are greatly appreciated.

@ccowden67 You can easily replace placeholders in your templates using Find/Replace functionality. But in your case, if you have control over the templates creation process, I would recommend to use LINQ Reporting Engine. Using LINQ Reporting Engine you can insert data in your templates suing simple placeholders like <<[FieldName]>> or insert documents.
You can find a simple “Hello, World!” code example here:
https://docs.aspose.com/words/net/hello-world-example/

Thank you, This looks promising. I will do some experiments and try it out.

1 Like

@alexey.noskov
I did some testing on the LINQ Reporting Engine approach to insert PDF content into a Word document. Following is the error I received:

Pdf format is not supported on this platform. Use .NET Standard or .NET 4.6.1 version of Aspose.Words for loading Pdf documents

I did discover that I can first convert the PDF to Doc, then I can use the reporting engine to insert that Doc into another Doc that has the expression tag successfully. Then the assembled document can be successfully saved to PDF.

The platform I’m running is PCF. It is a Java Spring Boot application.

Following are the versions of Aspose Libraries we are using:
Aspose-words: 21.4
Aspose-pdf: 22.8

Do you know if any updated library versions would support dynamic insert of PDF into DOC directly? If not, would first converting the PDF to DOC be a viable solution -or- would you recommend that I explore a different approach altogether?

Thanks for your help.

Charlie

@ccowden67 Unfortunately, Java version of Aspose.Words does not support importing PDF documents. So the only solution at the moment is conversion PDF to DOC or DOCX using other tool. You can use Aspose.PDF for Java to achieve this.