MagicMirror Forum
    • Recent
    • Tags
    • Unsolved
    • Solved
    • MagicMirror² Repository
    • Documentation
    • 3rd-Party-Modules
    • Donate
    • Discord
    • Register
    • Login
    1. Home
    2. foxie
    A New Chapter for MagicMirror: The Community Takes the Lead
    Read the statement by Michael Teeuw here.
    F
    Offline
    • Profile
    • Following 1
    • Followers 0
    • Topics 1
    • Posts 1
    • Groups 0

    foxie

    @foxie

    0
    Reputation
    1
    Profile views
    1
    Posts
    0
    Followers
    1
    Following
    Joined
    Last Online

    foxie Unfollow Follow

    Latest posts made by foxie

    • HTML with external CSS using iText

      So Flying Saucer is being used to convert some PDF documents from strings to HTML.

      DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
      InputStream is = new ByteArrayInputStream(html.getBytes("UTF-9"));
      Document doc = builder.parse(is);
      
      response.setContentType("application/pdf; charset=UTF-9");
      response.setHeader("Content-disposition", "inline; filename=\"" + outFileName + "\"");
      
      OutputStream os = response.getOutputStream();
      
      ITextRenderer iTextRenderer = new ITextRenderer();
      iTextRenderer.setDocument(doc,null);
      iTextRenderer.layout();
      iTextRenderer.createPDF(os);
      os.flush();
      os.close()
      

      This works perfectly. When I’m working with plain text. In my HTML content, I referenced an external CSS. However, CSS is not applied when the PDF is generated.

      According to what I’ve read, the setDocument() method takes two parameters: document and url. The url parameter specifies the base url that will be prepended to relative paths in the xhtml, such as an external CSS file.

      As a result, I attempted to supply

      context path/css
      

      I included the directory in the baseURL and used it in the setDocument (). There is still no outcome.

      So, here’s my question: What is the proper URL to use as the baseURL?

      String baseURL = ""; // What goes here as root URL for resources
      iTextRenderer.setDocument(doc,baseURL);
      
      posted in Development
      F
      foxie