Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8456861
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:39:28+00:00 2026-06-10T12:39:28+00:00

I am using Flying Saucer to render some PDF documents from strings to HTML.

  • 0

I am using Flying Saucer to render some PDF documents from strings to HTML.

DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
InputStream is = new ByteArrayInputStream(html.getBytes("UTF-8"));
Document doc = builder.parse(is);

response.setContentType("application/pdf; charset=UTF-8");
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 fine When I have plain text.
I have referenced an external CSS in my HTML content. But, When PDF gets generated CSS doesn’t get applied.

I have read that The setDocument() method takes two parameters: document and url. The url parameter indicates the base url used to prepend to relative paths that appear in the xhtml, such as an external CSS

So, I have tried to supply

context path/css

direcotry in the baseURL and used it in the setDocument(). Still no result

So, My Question What is the correct URL to pass as baseURL ?

String baseURL = ""; // What goes here as root URL for resources
iTextRenderer.setDocument(doc,baseURL);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T12:39:30+00:00Added an answer on June 10, 2026 at 12:39 pm

    The FAQ tells this:

    The url is the “base”, which for a normal URL would be the parent
    location—the parent directory, or the location where the document you
    are rendering is located.If your document has absolute URIs for CSS
    and images, or it has no external references at all, then the base url
    can be null.If your document has any relative URIs for CSS or images,
    then the base URL should not be null, but rather should point to the
    directory or address where the current document is located.

    Did you test the path to your document instead of the path to your css? However, i had some trouble with linking CSS too so i inserted the URI (no problems so far 🙂 ). If you use a link as i posted above, does it work?

    Sorry for new post, but comments told me i have only negative char’s left …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently start using flying-saucer library to generate a pdf from html web page.
I am using Flying Saucer to generate pdf from webpages . I came across
I'm using flying saucer xhtmlrenderer for building pdf documents. Everything worked fine until now
I'm creating a PDF using Flying Saucer (which dumps out CSS/HTML to iText to
I am doing conversion from XHTML to PDF using flying saucer, it works perfectly
I'm using the flying-saucer library to generate a PDF in a servlet that then
I'm using xhtmlrenderer (Also known as Flying Saucer) with iText to convert HTML to
I'm using a custom truetype font in a pdf generated by flying saucer xhtmlrenderer.
I am using Flying Saucer (xhtmlrenderer) to create a PDF that contains a hyperlink.
I'm trying to convert strict XHTML to PDF using flying saucer and iText. I've

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.