Skip to content

Commit

Permalink
Fix the case when resourceRootPath wasn't taken into account, added a…
Browse files Browse the repository at this point in the history
…nother XmlWorkerHelper overload
  • Loading branch information
yulian-gaponenko committed Feb 17, 2016
1 parent efc0238 commit 87484c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
Expand Up @@ -208,14 +208,27 @@ public void parseXHtml(final PdfWriter writer, final Document doc, final InputSt
* @throws IOException if the {@link InputStream} could not be read.
*/
public void parseXHtml(final PdfWriter writer, final Document doc, final InputStream in, final InputStream inCssFile, final Charset charset, final FontProvider fontProvider) throws IOException {
parseXHtml(writer, doc, in, inCssFile, charset, fontProvider, null);
}

/**
* @param writer the writer to use
* @param doc the document to use
* @param in the {@link InputStream} of the XHTML source.
* @param in the {@link CssFiles} of the css files.
* @param charset the charset to use
* @param resourcesRootPath defines the root path to find resources in case they are defined in html with relative paths (e.g. images)
* @throws IOException if the {@link InputStream} could not be read.
*/
public void parseXHtml(final PdfWriter writer, final Document doc, final InputStream in, final InputStream inCssFile, final Charset charset, final FontProvider fontProvider, final String resourcesRootPath) throws IOException {
CssFilesImpl cssFiles = new CssFilesImpl();
if (inCssFile != null)
cssFiles.add(getCSS(inCssFile));
else
cssFiles.add(getDefaultCSS());
StyleAttrCSSResolver cssResolver = new StyleAttrCSSResolver(cssFiles);
HtmlPipelineContext hpc = new HtmlPipelineContext(new CssAppliersImpl(fontProvider));
hpc.setAcceptUnknown(true).autoBookmark(true).setTagFactory(getDefaultTagProcessorFactory());
hpc.setAcceptUnknown(true).autoBookmark(true).setTagFactory(getDefaultTagProcessorFactory()).setResourcesRootPath(resourcesRootPath);
HtmlPipeline htmlPipeline = new HtmlPipeline(hpc, new PdfWriterPipeline(doc, writer));
Pipeline<?> pipeline = new CssResolverPipeline(cssResolver, htmlPipeline);
XMLWorker worker = new XMLWorker(pipeline, true);
Expand Down
Expand Up @@ -266,6 +266,9 @@ public HtmlPipelineContext clone() throws CloneNotSupportedException {
if (this.imageProvider != null) {
newCtx.setImageProvider(imageProvider);
}
if (this.resourcesRootPath != null) {
newCtx.setResourcesRootPath(resourcesRootPath);
}
if (null != this.charset) {
newCtx.charSet(Charset.forName(this.charset.name()));
}
Expand Down

0 comments on commit 87484c6

Please sign in to comment.