PDF Libraries: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 1: | Line 1: | ||
==Apache PDFBox== | |||
<source lang="xml"> | |||
<dependency> | |||
<groupId>org.apache.pdfbox</groupId> | |||
<artifactId>pdfbox</artifactId> | |||
<version>2.0.24</version> | |||
</dependency> | |||
</source> | |||
<source lang="java"> | |||
@BeforeEach | |||
public void setUp() { | |||
destinationFilePath = String.format(DESTINATION_FORMAT, System.getProperty(USER_HOME)); | |||
String[] names = new String[]{"pdf_source_1.pdf", "pdf_source_2.pdf", "pdf_source_3.pdf"}; | |||
resourcePaths = Arrays.stream(names).map(name -> String.format(CLASSPATH_FORMAT, name)).collect(Collectors.toList()); | |||
} | |||
@Test | |||
public void mergeTest() throws IOException { | |||
LocalDateTime startTime = LocalDateTime.now(); | |||
PDFMergerUtility merger = new PDFMergerUtility(); | |||
resourcePaths.forEach(path -> { | |||
try { | |||
merger.addSource(new ClassPathResource(path).getInputStream()); | |||
} catch (IOException e) { | |||
throw new RuntimeException(e); | |||
} | |||
}); | |||
merger.setDestinationFileName(destinationFilePath); | |||
merger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly()); | |||
Duration duration = Duration.between(startTime, LocalDateTime.now()); | |||
LOG.info("Duration: {} Millis", duration.toMillis()); | |||
Assertions.assertTrue(true); | |||
} | |||
</source> | |||
==References== | ==References== | ||
{| | {| |
Revision as of 10:03, 5 December 2023
Apache PDFBox
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.24</version>
</dependency>
@BeforeEach
public void setUp() {
destinationFilePath = String.format(DESTINATION_FORMAT, System.getProperty(USER_HOME));
String[] names = new String[]{"pdf_source_1.pdf", "pdf_source_2.pdf", "pdf_source_3.pdf"};
resourcePaths = Arrays.stream(names).map(name -> String.format(CLASSPATH_FORMAT, name)).collect(Collectors.toList());
}
@Test
public void mergeTest() throws IOException {
LocalDateTime startTime = LocalDateTime.now();
PDFMergerUtility merger = new PDFMergerUtility();
resourcePaths.forEach(path -> {
try {
merger.addSource(new ClassPathResource(path).getInputStream());
} catch (IOException e) {
throw new RuntimeException(e);
}
});
merger.setDestinationFileName(destinationFilePath);
merger.mergeDocuments(MemoryUsageSetting.setupMainMemoryOnly());
Duration duration = Duration.between(startTime, LocalDateTime.now());
LOG.info("Duration: {} Millis", duration.toMillis());
Assertions.assertTrue(true);
}
References
| ||