pdfOffice - Example
pdfOffice is an iText 7 add-on that allows generating a PDF document from either a Word, PowerPoint, or Excel file.
Currently supported file types are: .doc, .docx, .dotx, docm, .dotm, .dot, .ppt, .pptx, .potx, .pptm, .potm, .ppsx, .ppsm, .pot, .pps, xlsx, xls, xlsm, xltx, xltm, xlt, xlam, and xla.
The example below demonstrates converting a Word document (.docx) into a PDF.
JAVA
import com.itextpdf.pdfoffice.OfficeConverter;
import com.itextpdf.pdfoffice.OfficeDocumentConverterProperties;
import com.itextpdf.pdfoffice.OfficePageRange;
import java.io.File;
import java.io.IOException;
public class Office {
public static void main(String[] args) throws IOException {
LicenseKey.loadLicenseFile(new File("license.json"));
File pdfOutFile = new File("out_office.pdf");
File demoFile = new File("input.docx");
// converts pages between 1 to 8
OfficeConverter.convertOfficeDocumentToPdf(demoFile, pdfOutFile, new OfficeDocumentConverterProperties()
.setPageRange(new OfficePageRange().addPageSequence(1, 8)));
}
}