Skip to content

Commit

Permalink
Merge pull request #81 from rototor/custom-metadata-from-html
Browse files Browse the repository at this point in the history
Support all <meta>-data
  • Loading branch information
danfickle authored Apr 11, 2017
2 parents 5f6fe71 + 685c8fd commit 952d6be
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1258,7 +1258,7 @@ public void setMetadata(String name, String value) {

// Class for storing metadata element name/content pairs from the head
// section of an xhtml document.
private static class Metadata {
static class Metadata {
private String _name;
private String _content;

Expand Down Expand Up @@ -1286,6 +1286,14 @@ public void setName(String name) {

// Metadata end


/**
* @return All metadata entries
*/
List<Metadata> getMetadata() {
return _metadata;
}

public SharedContext getSharedContext() {
return _sharedContext;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,15 @@
import com.openhtmltopdf.bidi.SimpleBidiReorderer;
import com.openhtmltopdf.context.StyleReference;
import com.openhtmltopdf.css.style.CalculatedStyle;
import com.openhtmltopdf.extend.FSCache;
import com.openhtmltopdf.extend.FSObjectDrawerFactory;
import com.openhtmltopdf.extend.FSUriResolver;
import com.openhtmltopdf.extend.HttpStreamFactory;
import com.openhtmltopdf.extend.NamespaceHandler;
import com.openhtmltopdf.extend.SVGDrawer;
import com.openhtmltopdf.extend.UserInterface;
import com.openhtmltopdf.extend.*;
import com.openhtmltopdf.layout.BoxBuilder;
import com.openhtmltopdf.layout.Layer;
import com.openhtmltopdf.layout.LayoutContext;
import com.openhtmltopdf.layout.SharedContext;
import com.openhtmltopdf.outputdevice.helper.BaseDocument;
import com.openhtmltopdf.outputdevice.helper.PageDimensions;
import com.openhtmltopdf.outputdevice.helper.UnicodeImplementation;
import com.openhtmltopdf.pdfboxout.PdfBoxOutputDevice.Metadata;
import com.openhtmltopdf.render.BlockBox;
import com.openhtmltopdf.render.PageBox;
import com.openhtmltopdf.render.RenderingContext;
Expand Down Expand Up @@ -611,29 +606,28 @@ private void writePDF(List<PageBox> pages, RenderingContext c, Rectangle2D first

// Sets the document information dictionary values from html metadata
private void setDidValues(PDDocument doc) {
String v = _outputDevice.getMetadataByName("title");

PDDocumentInformation info = new PDDocumentInformation();

if (v != null) {
info.setTitle(v);
}
v = _outputDevice.getMetadataByName("author");
if (v != null) {
info.setAuthor(v);
}
v = _outputDevice.getMetadataByName("subject");
if (v != null) {
info.setSubject(v);
}
v = _outputDevice.getMetadataByName("keywords");
if (v != null) {
info.setKeywords(v);
}

info.setCreationDate(Calendar.getInstance());
info.setProducer("openhtmltopdf.com");

for (Metadata metadata : _outputDevice.getMetadata()) {
String name = metadata.getName();
String content = metadata.getContent();
if( content == null )
continue;
if( name.equals("title"))
info.setTitle(content);
else if( name.equals("author"))
info.setAuthor(content);
else if(name.equals("subject"))
info.setSubject(content);
else if(name.equals("keywords"))
info.setKeywords(content);
else
info.setCustomMetadataValue(name,content);
}

doc.setDocumentInformation(info);
}

Expand Down

0 comments on commit 952d6be

Please sign in to comment.