Bonjour,
Je tente de convertir un docx en pdf mais le résultat n'est pas bon au niveau des headers et footers
j'ai créé un projet Maven sous eclipse
voici le pom.xml
et le code pour l'appel aux fonction de POI
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.peincarm</groupId> <artifactId>docxtopdf</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>docxtopdf</name> <url>http://maven.apache.org</url> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>fr.opensagres.xdocreport</groupId> <artifactId>org.apache.poi.xwpf.converter.pdf</artifactId> <version>1.0.6</version> </dependency> <dependency> <groupId>commons-io</groupId> <artifactId>commons-io</artifactId> <version>2.6</version> </dependency> </dependencies> </project>
j'obtiens bien un pdf mais celui-ci ne correspond pas au docx au niveau de headers et footers
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15 try (InputStream is = new FileInputStream(new File(getFileDocx())); OutputStream out = new FileOutputStream(new File(getFilePdf()));) { long start = System.currentTimeMillis(); // 1) Load DOCX into XWPFDocument XWPFDocument document = new XWPFDocument(is); // 2) Prepare Pdf options PdfOptions options = PdfOptions.create(); // 3) Convert XWPFDocument to Pdf PdfConverter.getInstance().convert(document, out, options); System.out.println(getFilePdf() + " :: " + (System.currentTimeMillis() - start) + " milli seconds"); } catch (Throwable e) { e.printStackTrace(); }
Merci d'avance pour votre aide
cpf
Partager