Class HtmlResourceResolver

java.lang.Object
com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver
com.itextpdf.html2pdf.resolver.resource.HtmlResourceResolver

public class HtmlResourceResolver extends com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver
Extends ResourceResolver to also support SVG images
  • Constructor Details

    • HtmlResourceResolver

      public HtmlResourceResolver (String baseUri, ProcessorContext context)
      Creates a new HtmlResourceResolver instance. If baseUri is a string that represents an absolute URI with any schema except "file" - resources url values will be resolved exactly as "new URL(baseUrl, uriString)". Otherwise base URI will be handled as path in local file system.

      If empty string or relative URI string is passed as base URI, then it will be resolved against current working directory of this application instance.

      Parameters:
      baseUri - base URI against which all relative resource URIs will be resolved
      context - ProcessorContext instance for the current HTML to PDF conversion process
    • HtmlResourceResolver

      public HtmlResourceResolver (String baseUri, ProcessorContext context, com.itextpdf.styledxmlparser.resolver.resource.IResourceRetriever retriever)
      Creates a new HtmlResourceResolver instance. If baseUri is a string that represents an absolute URI with any schema except "file" - resources url values will be resolved exactly as "new URL(baseUrl, uriString)". Otherwise base URI will be handled as path in local file system.

      If empty string or relative URI string is passed as base URI, then it will be resolved against current working directory of this application instance.

      Parameters:
      baseUri - base URI against which all relative resource URIs will be resolved
      context - ProcessorContext instance for the current HTML to PDF conversion process
      retriever - the resource retriever with the help of which data from resources will be retrieved
  • Method Details

    • retrieveImage

      public com.itextpdf.kernel.pdf.xobject.PdfXObject retrieveImage (String src)
      Overrides:
      retrieveImage in class com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver
    • tryResolveBase64ImageSource

      protected com.itextpdf.kernel.pdf.xobject.PdfXObject tryResolveBase64ImageSource (String src)
      Retrieve image as either PdfImageXObject, or PdfFormXObject.
      Overrides:
      tryResolveBase64ImageSource in class com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver
      Parameters:
      src - either link to file or base64 encoded stream
      Returns:
      PdfXObject on success, otherwise null
    • createImageByUrl

      protected com.itextpdf.kernel.pdf.xobject.PdfXObject createImageByUrl (URL url) throws Exception
      Overrides:
      createImageByUrl in class com.itextpdf.styledxmlparser.resolver.resource.ResourceResolver
      Throws:
      Exception