statiqdev / Statiq.Web

Statiq Web is a flexible static site generator written in .NET.
https://statiq.dev/web
Other
1.65k stars 236 forks source link

Create a Pdf module #31

Open daveaglick opened 9 years ago

daveaglick commented 9 years ago

Convert HTML content to PDF

MetalDent commented 4 years ago

Hi @daveaglick , which HTML files you want to convert?

daveaglick commented 4 years ago

The goal would be to convert HTML content stored in documents. The specific set of documents that get converted, how they’re aggregated into a single output PDF, and other details would need to be configurable.

As for use cases, I could see integrating this module into the docs pipelines to optionally produce a PDF of the documentation.

A word of caution - Wyam is no longer accepting PRs. If there’s interest in looking at this, head on over to Statiq Framework.

daveaglick commented 2 years ago

Could consider something like CefSharp which embeds the Chromium engine: https://github.com/cefsharp/CefSharp

Generating a PDF would be essentially one or two lines of code: https://stackoverflow.com/a/61723341/6287173

var success = await webBrowserObject.PrintToPdfAsync("filename.pdf", new PdfPrintSettings
{
    MarginType = CefPdfPrintMarginType.Custom,
    MarginBottom = 10,
    MarginTop = 0,
    MarginLeft = 20,
    MarginRight = 10,
    PageWidth = 210000,
    PageHeight = 297000
});