Insert PDF as OLE object inside Ms word

I’ve a requirement to show PDF file as OLE object inside Ms word. Can anyone please let me know if Aspose have free API or paid version? I free API, then any examples. Awaiting for quick reply.

Hi there,

Thanks for your inquiry. Please use DocumentBuilder.InsertOleObject method to insert an embedded or linked OLE object from a file into the document. See the detail from following link.
Inserting Ole Object

Please use latest version of Aspose.Words for Java 16.1.0. If you still face problem, please manually create your expected Word document using Microsoft Word and attach it here for our reference. We will investigate as to how you want your final Word output be generated like. We will then provide you more information on this along with code.

Thanks for your reply. PFA Model_Image file where it shows how the PDF to be shown as object inside MS Word. Can you please suggest solution for this requirement?

Thanks

Hi there,

Thanks for sharing the detail. Please use DocumentBuilder.InsertOleObject method as shown below to achieve your requirement. Hope this helps you. Please let us know if you have any more queries.

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertOleObject(MyDir + "test.pdf", "AcroExch.Document.7", false, true, null);
doc.save(MyDir + "Out.docx");
Document doc;
try
{
    doc = new Document();
    DocumentBuilder builder = new DocumentBuilder(doc);
    File file = new File("C:\Users\mastan\Downloads\Newtext.pdf");
    File file1 = new File("C:\Users\mastan\Downloads\NewDoc.docx");
    System.out.println("File name is" + file.getName());
    builder.insertOleObject(file.getName(), "AcroExch.Document.7", false, true, null);
    doc.save(file1.getName());
}
catch (Exception e)
{
    // TODO Auto-generated catch block
    e.printStackTrace();
}

Thanks for the reply. Tried this above code. But got “java.io.FileNotFoundException: Can’t find file: Newtext.pdf.” Not sure why it’s not able to find

Please ignore previous post. Wanted to check if this is usable only for trial version /specific time?

Hi there,

Thanks for your inquiry. Please note that in evaluation mode there are some limitations applied. E.g. Aspose.Words injects an evaluation watermark at the top of the document. The document’s content are truncated after a certain number of paragraphs during import or export. To avoid this you can request 30-days trial license which removes these evaluation restrictions.

Please read about applying license from here:
Applying a License

Hi,

Tried to implement this code in application where the PDF file comes from Database, but it says as below: Doesn’t it work with database files?.

Vector pdfDetails = view.getPdfFile();
Iterator PDFFileDetails = pdfDetails.iterator();
if(PDFFileDetails.hasNext())
{
    while (PDFFileDetails.hasNext())
    {
        document = (Doc)PDFFileDetails.next();
    }
}
builder.insertOleObject(document.getFilename(), "AcroExch.Document.7", false, true, null);
Caused by: java.io.FileNotFoundException: Can’t find file: xxxxxxx.PDF.
at asposewobfuscated.zzBR.(Unknown Source)
at asposewobfuscated.zzZ.zzY(Unknown Source)
at com.aspose.words.zzZF6.zzk(Unknown Source)
at com.aspose.words.zzZF6.zzT(Unknown Source)
at com.aspose.words.DocumentBuilder.zzZ(Unknown Source)
at com.aspose.words.DocumentBuilder.insertOleObject(Unknown Source)
at org.apache.jsp.designpackreport_jsp._jspService(designpackreport_jsp.java:6167)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:438)
… 38 more

Hi there,

Thanks for your inquiry. The first parameter of DocumentBuilder.insertOleObject method is full path to the file. Please make sure that the file path is correct. The shared stack trace shows that Pdf file is not found at specified path.

If you are reading the file from database in the form of stream, we suggest you please use following overloaded method of DocumentBuilder.insertOleObject.

DocumentBuilder.insertOleObject(InputStream stream,String progId, boolean asIcon, BufferedImage presentation)

Please check following code example for your kind reference. Hope this helps you.

InputStream stream = new FileInputStream(MyDir + "in.pdf");
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.insertOleObject(stream, "AcroExch.Document.7", true, null);
doc.save(MyDir + "Out.docx");