I have used the below code :
package com.allianz.re.gim.service.util;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
public class PDF {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
String inputFile = "C:/TEMP/question.docx";
String outputFile = "C:/TEMP/question.pdf";
if ((args != null) && (args.length == 2)) {
inputFile = args[0];
outputFile = args[1];
}
System.out.println("inputFile:" + inputFile + ",outputFile:" + outputFile);
FileInputStream in = new FileInputStream(inputFile);
XWPFDocument document = new XWPFDocument(in);
File outFile = new File(outputFile);
OutputStream out = new FileOutputStream(outFile);
PdfOptions options = null;
PdfConverter.getInstance().convert(document, out, options);
}
}
Dependecnies used:
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>fr.opensagres.xdocreport</groupId>
<artifactId>fr.opensagres.poi.xwpf.converter.pdf</artifactId>
<version>2.0.1</version>
</dependency>
The Input :
The below docx has a rectangle shape placed over a text, the layout options of the rectangle is "behind text" you can see it from the image
The pdf output, which i have only ahs the text. the rectangle shape is absent. The same happens for image placed behind a text or a word art placed over an image too:
While using thse dependencies, and code snippet I am able to
1.convert images in docx with same font.
2.convert simple text in docx same font.
But few short comings are:
1. unable to convert an image, with layout option behind text(to show the text on top of an image) is not working properly.only the text is converted in the PDF.
2. the same issue happens for a word art or a shape which has some text inside it. only the test is converted.
Can someone help me?