1. AsposeAPI를 이용한 Docx to Pdf

2. Docx to Pdf(Youtube 관련 자료)

  1. AsposeAPI를 이용한 Docx to Pdf

1-1) AsposeAPI 링크

https://blog.aspose.com/2020/02/20/convert-word-doc-docx-to-pdf-in-java-programmatically/

1-2) Java 코드

import com.aspose.words.PdfCompliance;
import com.aspose.words.PdfSaveOptions;

import com.aspose.words.*;

public class DocumentConversionDemo {
    public static void main(String[] args) throws Exception {

        // Load the Word document from disk
        Document doc = new Document("/Users/ssu/Downloads/Test.docx");

        // Set PDFSaveOption compliance to PDF15
        PdfSaveOptions options = new PdfSaveOptions();
        options.setCompliance(PdfCompliance.PDF_A_1_B);

        // Convert Word to PDF
        doc.save("/Users/ssu/Downloads/Test.pdf", options);
    }
}

1-3) Maven

<dependencies>
    <dependency>
        <groupId>com.aspose</groupId>
        <artifactId>aspose-words</artifactId>
        <version>20.1</version>
        <classifier>jdk17</classifier>
    </dependency>
</dependencies>
<repositories>
    <repository>
        <id>AsposeJavaAPI</id>
        <name>Aspose Java API</name>
        <url><https://repository.aspose.com/repo/></url>
    </repository>
</repositories>

1-4) Docx to Pdf

Untitled

  1. Docx to Pdf(Youtube 관련 자료)

1-1) Docx to Pdf 링크

https://github.com/opensagres/xdocreport

1-2) Java 코드

package docx2pdf;

import fr.opensagres.poi.xwpf.converter.pdf.PdfConverter;
import fr.opensagres.poi.xwpf.converter.pdf.PdfOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;

import java.io.*;

public class Docx2Pdf {
    public static void main(String[] args) {
        try {
            InputStream docFile = new FileInputStream(new File("/Users/ssu/Downloads/Test.docx"));
            XWPFDocument doc = new XWPFDocument(docFile);
            PdfOptions pdfOptions = PdfOptions.create();
            OutputStream out = new FileOutputStream(new File("/Users/ssu/Downloads/Test2.pdf"));
            PdfConverter.getInstance().convert(doc, out, pdfOptions);
            doc.close();
            out.close();
            System.out.println("Done");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

1-3) Maven

<dependencies>
    <dependency>
        <groupId>fr.opensagres.xdocreport</groupId>
        <artifactId>fr.opensagres.poi.xwpf.converter.pdf</artifactId>
        <version>2.0.1</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi</artifactId>
        <version>4.1.1</version>
    </dependency>
    <dependency>
        <groupId>org.apache.poi</groupId>
        <artifactId>poi-ooxml</artifactId>
        <version>4.1.1</version>
    </dependency>
</dependencies>

1-4) 에로사항

→ 관련 자료에서 사용하는 java 1.5버전을 사용하고 있음.

→ 1.8이나 11버전으로 변경해서 진행했으나 Maven 관련 버전과 호환 문제로

→ error : org/apache/poi/POIXMLTypeLoader

⇒ <xmlbeans 2.3.0에서 xmlbeans 3.1.0으로 버전 바꾸기> 오류 해결

→ error : org.apache.xmlbeans.impl.values.XmlValueOutOfRangeException: Invalid integer value: 863.9999999999999

⇒ Excel 관련 오류 해결은 많으나 Docx 관련 오류 자료가 많이 존재 하지 않음.

⇒ 해결 중에 있음.