hello i wort to docx to pdf
this is my convert code
private void docxToPdf(String filePath) throws Exception {
// i use AWS S3
WordprocessingMLPackage wordMLPackage = loadDocxFromS3(filePath);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
String appleSDGothicNeo = "AppleSDGothicNeo.ttc ";
PhysicalFonts.getPhysicalFont(wordMLPackage, appleSDGothicNeo);
Mapper fontMapper = new IdentityPlusMapper();
fontMapper.put(appleSDGothicNeo, PhysicalFonts.get(appleSDGothicNeo));
/*
* i put on resources in font
* */
malgunGothicFontSettings(fontMapper, wordMLPackage);
wordMLPackage.setFontMapper(fontMapper);
Docx4J.toPDF(wordMLPackage, byteArrayOutputStream);
ObjectMetadata objectMetadata = new ObjectMetadata();
objectMetadata.setContentLength(byteArrayOutputStream.size());
objectMetadata.setContentType("application/pdf");
filePath = filePath.replace(".docx",".pdf");
try (InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray())) {
amazonS3Client.putObject(bucketName, filePath, inputStream, objectMetadata);
} catch (IOException e) {
throw new Docx4JException("Failed to upload the document to S3 in PDF", e);
}
}
this is my gradle
dependencies {
implementation 'org.springframework.boot:spring-boot-starter'
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok:1.18.24'
annotationProcessor 'org.projectlombok:lombok:1.18.24'
implementation 'org.springframework.boot:spring-boot-starter-validation'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-databind', version: '2.17.2'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-core', version: '2.17.2'
implementation group: 'com.fasterxml.jackson.core', name: 'jackson-annotations', version: '2.17.2'
implementation group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.12.765'
implementation 'commons-io:commons-io:2.13.0'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'org.glassfish.jaxb:jaxb-core:3.0.1'
implementation group: 'com.sun.xml.bind', name: 'jaxb-impl', version: '4.0.5'
implementation group: 'org.docx4j', name: 'docx4j-core', version: '11.4.11'
implementation group: 'org.docx4j', name: 'docx4j-JAXB-ReferenceImpl', version: '11.4.11'
implementation group: 'org.docx4j', name: 'docx4j-export-fo', version: '11.4.11'
}
originalFile(.docx)
enter image description here
convertedFile(.pdf)
enter image description here
The conversion itself goes well.
However, during conversion, all paragraphs are broken.
There are several related logs on my server.
1)
enter image description here
2)
2024-08-09T17:51:09.805+09:00 WARN 22686 — [nio-9000-exec-1] o.d.c.out.fo.FOPictWriterNoWrapImpl : No support for mso_position_horizontal_relative==false
2024-08-09T17:51:09.903+09:00 WARN 22686 — [nio-9000-exec-1] o.d.model.properties.paragraph.Indent : Only left/first-line indentation is handled at present
How to solve this problem?
and i how shoud we approach it?
I have seen similar cases stackoverflow
But I couldn’t solve this problem
I want to complete this task smoothly and for free.
doby-jin is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.