Questo tutorial spiega come inserire PDF in Word come immagine in Java. It guides you through performing this task with instructions to set up the environment, a list of programming steps, and sample code that demonstrates how to insert a PDF as an image in Word using Java. Some code variants will also be discussed to control the conversion process and create a custom output file.
Steps to insert a PDF image into Word using Java.
- Set up the environment to use Aspose.Total for Java to develop the application.
- Apply a license for the PDF and Word libraries.
- Load the source PDF file into the Document class object of the Aspose library.pdf
- Create a new empty Word file using the class object Document from the Aspose library.words
- Set the output image resolution and other parameters for rendering PDF pages to PNG.
- Iterate over each page of the PDF, convert it to an image, and save it in the Word document.
- Insert a page break after inserting each image in the Word file, except for the last page.
- Save the resulting Word file to disk.
These steps describe how to insert a PDF image into Word with Java. Inizia caricando il file PDF di origine, creando un file Word vuoto e iterando attraverso ogni pagina. Converte ogni pagina PDF in un’immagine PNG usando una risoluzione definita e altri parametri di rendering, salva ogni immagine in una nuova pagina del file Word e salva il file Word risultante.
Codice per inserire PDF come immagine in Word in Java
This code demonstrates how to insert a PDF image into Word in Java. If you want the inserted image dimensions to match the original PDF page, you can use PageSetup.setPageWidth o setPageHeight So the output image does not appear distorted or cropped. To check the image quality and file size, you can try the options. CompressionType Displayed via the image device.
This article explains the process of turning text‑based PDF pages into an image in a Word file. To convert a scanned PDF to Word, refer to the article Convert Scanned PDF to Word using Java.