Developer forum

Forum » Ecommerce - Standard features » DW10 PDF Converter/PDF renderer setup

DW10 PDF Converter/PDF renderer setup

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,
I have set up a solution where I am trying to configre DAP and Publications.
I have started with DAp and most o the setup is done, exceot for the PDF thumbnail generation.
The solution is set to use the Default PDF renderer:

But the thumbnails are not generated:

I suppose that I may need to make some additional configurations?
The solution is hosted by DW cloud and it is running on DW 10.28.9.
Thank you,
Adrian


Replies

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

DW10 has no PDF engine = Default means no PDF. And it will not get one for a lot of technical reasons.

Swift templates was changed long ago: https://doc.dynamicweb.dev/documentation/fundamentals/dw10release/releasenotes/workiteminfo.html?workitemid=22708

If this is important, use JS in the frontend to do it:

Mozilla PDF.js to fetch the PDF and render page one into a small <canvas>, entirely in the browser. The server only needs to serve the PDF file. PDF.js examples

Host the PDF.js distribution under /js/pdfjs/, keeping the library and worker on the same version:

<canvas id="pdf-thumbnail" role="img" aria-label="PDF first page"></canvas>

<script type="module">
  import * as pdfjs from "/js/pdfjs/build/pdf.mjs";

  pdfjs.GlobalWorkerOptions.workerSrc =
    "/js/pdfjs/build/pdf.worker.mjs";

  async function renderThumbnail(url, canvas, width = 180) {
    const loadingTask = pdfjs.getDocument({
      url,
      cMapUrl: "/js/pdfjs/cmaps/",
      cMapPacked: true,
      standardFontDataUrl: "/js/pdfjs/standard_fonts/",
      wasmUrl: "/js/pdfjs/wasm/"
    });

    try {
      const pdf = await loadingTask.promise;
      const page = await pdf.getPage(1);

      const original = page.getViewport({ scale: 1 });
      const viewport = page.getViewport({
        scale: width / original.width
      });

      // Keep the thumbnail sharp on high-density screens.
      const ratio = window.devicePixelRatio || 1;
      canvas.width = Math.ceil(viewport.width * ratio);
      canvas.height = Math.ceil(viewport.height * ratio);
      canvas.style.width = `${viewport.width}px`;
      canvas.style.height = `${viewport.height}px`;

      await page.render({
        canvasContext: canvas.getContext("2d"),
        viewport,
        transform: [ratio, 0, 0, ratio, 0, 0],
        background: "#ffffff"
      }).promise;
    } finally {
      await loadingTask.destroy();
    }
  }

  renderThumbnail(
    "/Files/Documents/brochure.pdf",
    document.getElementById("pdf-thumbnail")
  ).catch(console.error);
</script>

A few practical points:

  • The PDF must be accessible through a URL. If it’s on another domain, that server must allow CORS.
  • A small thumbnail can still require a large download. PDF.js can use HTTP range requests when supported, but rendering page one doesn’t guarantee downloading only that page. PDF.js FAQ
  • For a grid of PDFs, lazy-load thumbnails as they approach the viewport, and limit simultaneous renders to avoid slowing the browser.
 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nicolai,
This is a problem for Publications and DAP, which are both somehow connected to the PDF generation/Renderer.
Since the interface allows selection of a PDF provider, can I build my own provider? Does it make sense?
I can see some issues with projects migrated from DW9 where PDF generation was supported.

Do you have any pointers?

Thank you,
Adrian
 

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply

It is not supported. I will remove it from the UI.

In DW9 90% of the application download is PDF rendering.

The browser can already render a PDF. So it is a much better solution and super simple.

https://www.nuget.org/packages/PDFtoImage/  can technically do it more lean than the DW9 approach (which uses a headless chrome). But this lib loads un-managed operating system dependent libraries (which again has dependencies) - and getting this to work reliable, without performance and memory issues and the need for elevated permissions on the app pool and access to temp folders etc. - is not fun. If we added this to DW10 the application size would go up with 100mb at least 

 
Lauritz H Dynamicweb Employee
Lauritz H
Reply

Hi NP!

Just chiming in here in relation to some other projects - making sure I underestand.

We've used IronPDF on DW9 projects to generate and build PDF files - fx. invoices and packing slips (some special business logics require this). These are requests we are also getting in DW10 projects. But this is not something that we can reuse in DW10 context - or do we need to look other ways?

 
Nicolai Pedersen Dynamicweb Employee
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Lauritz,

Tough one - it deserves a longer answer because it comes up in most DW9 to DW10 migrations.

First, two different problems are being discussed in this thread. Adrian needs to render an existing PDF as an image (thumbnails for DAP/Publications). The browser does that with PDF.js and the server only serves the file. You need to produce a new PDF from data (invoices, packing slips). That is the harder one, and it is where DW9 spent most of its weight.

Why DW10 has no server-side PDF engine

The DW9 renderer was a headless Chrome. It accounted for the majority of the application download, and it was the source of a disproportionate number of support cases. The reasons we did not carry it over:

Security. HTML-to-PDF means running a full browser engine on the server and feeding it HTML that contains customer data and often user-supplied content. A browser follows links. <img src="http://169.254.169.254/..."> or a file:// reference in a product description means the renderer can reach internal endpoints and local files and write the result into the PDF. Chromium also has a weekly patch cadence; a pinned browser binary inside a CMS is a liability the moment it is a few months old.

Unmanaged code. Chromium, PDFium, Skia and similar are native libraries loaded into the .NET process. A crash in native code is not an exception you can catch; it takes the whole process down, including every other request in flight. Memory is allocated outside the GC, so leaks are invisible to .NET diagnostics. The binaries have to be extracted to disk, which needs write access to a temp folder, and they need system libraries (fontconfig, libX11, GTK and friends on Linux) that must be present on the host. On DW Cloud, where the standard application is auto-upgraded and customizations are kept separate, there is no way to isolate that failure mode.

Cross platform. DW10 runs on Windows, Linux, Mac. A native dependency like IronPDF means shipping and testing all those builds, each with its own set of system dependencies. I giant download with loading and upgrade issues. (Technical, I know, but important for customer stability)

Licensing. IronPDF is a commercial product. For DW9 we have a license that covers creating PDF in the product - if you use the API directly or indirectly it is a license issue. This is not DW10 specific but the usage you describe is a breach, others do it, and then it becomes our problem as well.

Rendering fidelity. Web fonts not installed on the server fall back silently. The viewport width the renderer uses decides the layout, so the PDF does not look like the preview in the browser. Lazy-loaded images never load. Content rendered by JavaScript is missing if the snapshot is taken too early. Page breaks depend on CSS support that varies by engine version. Page numbers in headers and footers are a workaround in every engine. Each of those becomes a ticket titled "the PDF looks different from the website", and none of them are bugs we can fix in the platform. We have spent a ton of time on this.

IronPDF in DW10

None of the above stops you from using IronPDF in a DW10 custom project. It is a NuGet package, not a DW feature - we just do not use it anymore. If you want to use it, you can reference IronPDF in your ustom project - then you own the caveats above: native dependencies in your deployment, memory and stability in the app pool, the license question, and rendering support. I would not run it in-process on DW Cloud.

Alternatives

The important distinction is between two ways of getting a PDF:

  1. HTML to PDF: render a web page with a browser engine and print it. High visual fidelity, needs Chromium or equivalent somewhere, and inherits every issue listed above wherever that engine runs.
  2. Generating a PDF: build the document programmatically from data. No html, no browser, managed code only, deterministic output. Less flexible for design, but invoices and packing slips are not design-heavy.

For invoices and packing slips I would start with option 2 - or see below.

PDFsharp (with MigraDoc): MIT-licensed, pure managed code, no native binaries, no Chromium, targets current .NET. PDFsharp is a low-level canvas where you position text, lines and images yourself. PDFsharp-MigraDoc adds a document model (paragraphs, tables, headers/footers, pagination) on top. Use the first for fixed layouts like labels and simple invoices, the second when content flows across pages. One cross-platform note: on Linux you must provide a font resolver or embed fonts, since there is no GDI to look them up.

 
csharp
using PdfSharp.Drawing;
using PdfSharp.Pdf;

var document = new PdfDocument();
document.Info.Title = "Invoice 1001";

var page = document.AddPage();
page.Size = PdfSharp.PageSize.A4;
var gfx = XGraphics.FromPdfPage(page);

var title = new XFont("Arial", 20, XFontStyleEx.Bold);
var body = new XFont("Arial", 11);

gfx.DrawString("Invoice 1001", title, XBrushes.Black,
    new XRect(40, 40, page.Width.Point - 80, 30), XStringFormats.TopLeft);

double y = 100;
foreach (var line in orderLines)
{
    gfx.DrawString(line.ProductName, body, XBrushes.Black, 40, y);
    gfx.DrawString(line.Quantity.ToString(), body, XBrushes.Black, 350, y);
    gfx.DrawString(line.Total.ToString("C"), body, XBrushes.Black, 450, y);
    y += 18;
}

document.Save(stream);

If you genuinely need HTML rendering, for example because the customer wants the PDF to match a designed web page, do not use a PDF component on the server - use a service instead:

Hosted HTML-to-PDF APIs: your .NET side becomes one HTTP call and zero rendering dependencies. It just runs on someone else's infrastructure. Chromium-backed options include PDFShift (simplest integration), API2PDF (pay per use, good for spiky volume), PDFCrowd and ConvertAPI. For typographically serious documents with real CSS Paged Media support, DocRaptor (PrinceXML) and PdfBroker.io (WeasyPrint, EU-hosted, produces PDF/A and PDF/UA) are the options. EU hosting will matter for many Danish customers.

csharp
using var http = new HttpClient();
http.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue(
    "Basic", Convert.ToBase64String(Encoding.ASCII.GetBytes("api:" + apiKey)));

var payload = JsonSerializer.Serialize(new { source = invoiceHtml, format = "A4" });
var response = await http.PostAsync("https://api.pdfshift.io/v3/convert/pdf",
    new StringContent(payload, Encoding.UTF8, "application/json"));

response.EnsureSuccessStatusCode();
var pdfBytes = await response.Content.ReadAsByteArrayAsync();

Two cautions. Avoid any service whose only engine is wkhtmltopdf; it was archived in 2023 with unpatched CVEs (Security issues). And check the per-conversion price against your real volume. Order confirmations across a customer base add up quickly.

Is PDF even the right tool?

Before choosing any of the above, ask why the customer wants a PDF. The usual answer is "for the invoice", but an invoice is data plus a layout, and an email already is that. An HTML email can be printed, it is readable on a phone, and it removes the click to open a PDF attachment. A QR code for payment, a tracking link, a return label, all of it embeds directly in the email. In most cases the PDF requirement is a habit carried over from a time when email clients could not render a table properly. If the requirement is legal archiving or a fixed document the ERP must own, the ERP already produces it and DW should link to it. If it is "the customer wants something to print", a well-built email does that better and with none of the engineering above.

NP

Votes for this answer: 1

 

You must be logged in to post in the forum