Insert an External File into Word Documents Using Java

import com.spire.doc.Document;
import com.spire.doc.FileFormat;
import com.spire.doc.Section;
import com.spire.doc.documents.OleObjectType;
import com.spire.doc.documents.Paragraph;
import com.spire.doc.fields.DocPicture;

public class InsertOLE {

public static void main(String[] args) {

//Create a Document object and load a Word document
Document doc = new Document();
doc.loadFromFile("Input 1.docx");

//Get the last section
Section section = doc.getLastSection();

//Add a paragraph
Paragraph par = section.addParagraph();

//Load an image which will be inserted to Word document representing the embedded file
DocPicture pdfIcon = new DocPicture(doc);

//Insert a PDF file to the Word document as an OLE object
par.appendOleObject("C:\\Users\\Administrator\\Desktop\\report.pdf", pdfIcon, OleObjectType.Adobe_Acrobat_Document);

//Save to another file
doc.saveToFile("EmbedDocument.docx", FileFormat.Docx_2013);




Sharing Java Code

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Google BigQuery Integration with SAP Data Warehouse Cloud

Why Data Professionals Should understand Infrastructure?

CS 373 Fall 2020: Week 5

*CUPOM DE 100% DE DESCONTO* — Google BigQuery e PostgreSQL: Big Query para análise de dados /…

Install Expo (React Native) app on iPhone with Testflight

VPN The Easy Way

So Easy MicroPython — ESP8266/ESP32 MCU File Management

Developing Models in Looker

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrew Wilson

Andrew Wilson

Sharing Java Code

More from Medium

Database connectivity with java 🤯, using mysql…

Distributing a Java command-line application: the JVM dependency

Auditing With Hibernate Envers

Introduction to Parallel Programming in Java