Skip to content

Commit

Permalink
close #381: always use filename when adding a footer to the merged file
Browse files Browse the repository at this point in the history
  • Loading branch information
torakiki committed Jun 29, 2020
1 parent 2abc99b commit eac0abc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,13 +157,14 @@ public void execute(MergeParameters parameters) throws TaskException {
// skip the cover/title document, don't add it to the ToC
} else {
tocCreator.pageSizeIfNotSet(currentPageSize);
String tocText = sourceBaseName;
if (ToCPolicy.DOC_TITLES == parameters.getTableOfContentsPolicy()) {
sourceBaseName = ofNullable(
tocText = ofNullable(
sourceDocumentHandler.getUnderlyingPDDocument().getDocumentInformation())
.map(i -> i.getTitle()).filter(StringUtils::isNotBlank)
.orElse(sourceBaseName);
}
tocCreator.appendItem(sourceBaseName, pagesCounter, importedPage);
tocCreator.appendItem(tocText, pagesCounter, importedPage);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,23 @@ public void pageFooterAndToc() throws IOException {
});
}

@Test
public void pageFooterAndTocwithDocTitles() throws IOException {
List<PdfMergeInput> input = new ArrayList<PdfMergeInput>();
input.add(new PdfMergeInput(regularInput()));
input.add(new PdfMergeInput(customInput("pdf/test_file.pdf", "my_file.pdf")));
MergeParameters parameters = setUpParameters(input);
parameters.setTableOfContentsPolicy(ToCPolicy.DOC_TITLES);
parameters.setFilenameFooter(true);
testContext.pdfOutputTo(parameters);
execute(parameters);
testContext.assertTaskCompleted();
testContext.assertPages(16).forEachPdfOutput(d -> {
assertFooterHasText(d.getPage(1), "test-file 2");
assertFooterHasText(d.getPage(12), "my_file 13");
});
}

@Test
public void pageFooterAndTocAddBlank() throws IOException {
MergeParameters parameters = setUpParameters(getInput());
Expand Down

0 comments on commit eac0abc

Please sign in to comment.