Forum Discussion

ArneVer's avatar
ArneVer
Regular Visitor
1 month ago
Solved

Convert HTML files to PDF

Hi

 

I'm currently looking for a technique to convert HTML files stored in a Microsoft Fabric Lakehouse into PDF files.

The goal is to preserve both the content and the original formatting/layout as accurately as possible.

I initially tried using xhtml2pdf, but the HTML files contain a large embedded CSS stylesheet (Bootstrap-like grid, media queries, advanced selectors such as :not() and attribute selectors). This resulted in CSS parsing errors. After removing the styling, the PDF could be generated successfully, but most of the original layout was lost. 

I also evaluated:

  • WeasyPrint, but it requires OS-level libraries (e.g. fontconfig) that are not available in my Fabric environment.
  • Playwright, but running Chromium inside a Fabric Notebook appears to be challenging due to runtime and browser binary limitations.

Since preserving the layout is a hard requirement, I'm looking for recommendations from anyone who has implemented HTML-to-PDF conversion in Microsoft Fabric while maintaining browser-quality rendering.

 

Thanks in advance for any suggestions.

  • ArneVer 
    AS per my understanding and findings, Fabric runs in managed environment so there is no built in fabric API that converts HTML to PDF.

    Workaround for this problem:
    Fabric NoteBook     ---->(Read HTML from Lakehouse) ----> Azure Function (PlayWrtie +Chromium) ----> Convert HTML to PDF  ----> Save PDF to ADSL /OneLake

    2nd Option similar approach but use Power Auomate Flow instead Azure Function.

    Lakehouse ----> Power Automate ---->HTML to PDF converter ---->Onelake / Sharepoint

    Please let me know how this goes on.


    If this helps, 
    ✓ Mark as Kudos | Help Others



  • Hi User,

    Preserving the original HTML layout (especially with complex CSS frameworks like Bootstrap) typically requires a browser-based rendering engine. Libraries such as xhtml2pdf are suitable for simple HTML but often struggle with modern CSS features.

    Based on your findings, here are a few approaches you could consider:

    • Use Playwright or Puppeteer in an environment that supports Chromium (such as Azure Functions, Azure Container Apps, Azure App Service, or a VM). Your Fabric Notebook can then invoke this service to generate high-fidelity PDFs.

    • If you're already using Azure, consider building a lightweight HTML-to-PDF microservice and calling it from a Fabric Pipeline or Notebook. This keeps the rendering separate from Fabric's runtime limitations.

    • If your HTML is generated from a reporting process, another option is to render the PDF outside Fabric before storing it in the Lakehouse.

    Unfortunately, Fabric Notebooks currently don't expose the OS-level dependencies required by tools such as WeasyPrint, nor are they designed to run headless Chromium reliably. Because of this, browser-based rendering directly inside Fabric isn't officially supported today.

    For more information:

    Could you also clarify:

    • Are the HTML files generated within Fabric, or are they imported from another application?

    • Is the PDF generation required entirely inside Microsoft Fabric, or would calling an external Azure service be an acceptable solution?

    • Approximately how many HTML files do you need to convert (e.g., tens, hundreds, or thousands per day)?

    This information will help determine the most suitable and scalable approach for your scenario.

    💡 Helpful? Give a Kudos 👍 — keep the community growing.

    Solved your issue? Mark this as the Accepted Solution ✔️

    Best regards,
    Prince Singh | Data Science & Microsoft Fabric Enthusiast

     

4 Replies

  • ArneVer 
    AS per my understanding and findings, Fabric runs in managed environment so there is no built in fabric API that converts HTML to PDF.

    Workaround for this problem:
    Fabric NoteBook     ---->(Read HTML from Lakehouse) ----> Azure Function (PlayWrtie +Chromium) ----> Convert HTML to PDF  ----> Save PDF to ADSL /OneLake

    2nd Option similar approach but use Power Auomate Flow instead Azure Function.

    Lakehouse ----> Power Automate ---->HTML to PDF converter ---->Onelake / Sharepoint

    Please let me know how this goes on.


    If this helps, 
    ✓ Mark as Kudos | Help Others



  • Kagiyama_yutaka's avatar
    Kagiyama_yutaka
    Responsive Resident

    Fabric Lakehouse and Notebooks do not provide any built‑in HTML→PDF, so the safe way is to read the HTML out of the Lakehouse and convert it to PDF in another environment (for example a normal browser’s “Print → Save as PDF” or an external HTML‑to‑PDF service).

  • v-abhinavmu's avatar
    v-abhinavmu
    Community Support

    Hi ArneVer,

    Thank you for posting your query in the Microsoft Fabric Community Forum, and thanks to Kagiyama_yutaka & Murtaza_Ghafoor  for sharing valuable insights.

     

    Could you please confirm if your query has been resolved by the provided solutions? This would be helpful for other members who may encounter similar issues.

     

    Thank you for being part of the Microsoft Fabric Community.

     

  • Hi User,

    Preserving the original HTML layout (especially with complex CSS frameworks like Bootstrap) typically requires a browser-based rendering engine. Libraries such as xhtml2pdf are suitable for simple HTML but often struggle with modern CSS features.

    Based on your findings, here are a few approaches you could consider:

    • Use Playwright or Puppeteer in an environment that supports Chromium (such as Azure Functions, Azure Container Apps, Azure App Service, or a VM). Your Fabric Notebook can then invoke this service to generate high-fidelity PDFs.

    • If you're already using Azure, consider building a lightweight HTML-to-PDF microservice and calling it from a Fabric Pipeline or Notebook. This keeps the rendering separate from Fabric's runtime limitations.

    • If your HTML is generated from a reporting process, another option is to render the PDF outside Fabric before storing it in the Lakehouse.

    Unfortunately, Fabric Notebooks currently don't expose the OS-level dependencies required by tools such as WeasyPrint, nor are they designed to run headless Chromium reliably. Because of this, browser-based rendering directly inside Fabric isn't officially supported today.

    For more information:

    Could you also clarify:

    • Are the HTML files generated within Fabric, or are they imported from another application?

    • Is the PDF generation required entirely inside Microsoft Fabric, or would calling an external Azure service be an acceptable solution?

    • Approximately how many HTML files do you need to convert (e.g., tens, hundreds, or thousands per day)?

    This information will help determine the most suitable and scalable approach for your scenario.

    💡 Helpful? Give a Kudos 👍 — keep the community growing.

    Solved your issue? Mark this as the Accepted Solution ✔️

    Best regards,
    Prince Singh | Data Science & Microsoft Fabric Enthusiast