Skip to content

Commit

Permalink
Existing pdf PDDocumentInformation should not be removed
Browse files Browse the repository at this point in the history
Motivation:

The method PdfRendererBuilder#usePDDocument(PDDocument) allow the user to provided an existing document. During the process, the information contains in PDDocumentInformation are removed.

Modification:
* Methods PdfBoxRenderer#setDidValues(PDDocument) add only missing information
  • Loading branch information
Vincent Galloy committed Mar 29, 2021
1 parent ccd29f0 commit aae3fd4
Showing 1 changed file with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -873,23 +873,25 @@ private XMPSchema createPdfaProperty(String category, String description, String

// Sets the document information dictionary values from html metadata
private void setDidValues(PDDocument doc) {
PDDocumentInformation info = new PDDocumentInformation();

info.setCreationDate(Calendar.getInstance());
if(doc.getDocumentInformation() == null) {
doc.setDocumentInformation(new PDDocumentInformation());
}
final PDDocumentInformation info = doc.getDocumentInformation();

if (_producer == null) {
info.setProducer("openhtmltopdf.com");
} else {
info.setProducer(_producer);
if(info.getCreationDate() == null) {
info.setCreationDate(Calendar.getInstance());
}
if(info.getProducer() == null) {
info.setProducer(_producer == null ? "openhtmltopdf.com": _producer);
}

for (Metadata metadata : _outputDevice.getMetadata()) {
String name = metadata.getName();
if (name.isEmpty())
continue;
String content = metadata.getContent();
if( content == null )
continue;
String name = metadata.getName();
if (name.isEmpty())
continue;
String content = metadata.getContent();
if( content == null )
continue;
if( name.equals("title"))
info.setTitle(content);
else if( name.equals("author"))
Expand All @@ -901,8 +903,6 @@ else if(name.equals("keywords"))
else
info.setCustomMetadataValue(name,content);
}

doc.setDocumentInformation(info);
}

private void paintPageFast(RenderingContext c, PageBox page, DisplayListPageContainer pageOperations, int additionalTranslateX) {
Expand Down

0 comments on commit aae3fd4

Please sign in to comment.