aspose-pdf-demo.zip (2.0 MB)
As shown in the attached code (aspose-pdf-demo/src/main/java/io/example/Main.java), we are using ofdrw to convert a PDF document to an OFD document, and then using Aspose PDF to convert the OFD to a PDF document, but we find that the PDF document opened is blank. However, ofdrw can successfully convert OFD documents to PDF documents.
package io.example;
import com.aspose.pdf.Document;
import com.aspose.pdf.OfdLoadOptions;
import org.ofdrw.converter.export.OFDExporter;
import org.ofdrw.converter.export.PDFExporterPDFBox;
import org.ofdrw.converter.ofdconverter.PDFConverter;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
public class Main {
public static void main(String[] args) throws IOException {
// 1. Use ofdrw convert pdf to ofd
Path ofd = new File("docs/2.ofd").toPath();
try (PDFConverter converter = new PDFConverter(ofd)) {
converter.convert(new File("docs/1.pdf").toPath());
}
// 2. Use Aspose-pdf-java convert odf to pdf
try (Document document = new Document(Files.newInputStream(ofd), new OfdLoadOptions())) {
document.save(Files.newOutputStream(new File("docs/3.pdf").toPath()));
}
// 3. Use ofdrw convert ofd to pdf
try (OFDExporter exporter = new PDFExporterPDFBox(ofd, new File("docs/4.pdf").toPath())) {
exporter.export();
}
}
}
The corresponding PDF and OFD documents are included in the aspose-pdf-demo/docs directory of the attachment.
We have already prepared to purchase Aspose Words to complete our need to convert documents from DOC to PDF. If Aspose PDF can solve this problem of the blank PDF document, we will also purchase Aspose PDF. ofdrw uses iText to handle PDF, and compared to iText, we think Aspose PDF is more suitable for developer.