Sign inSign up

deventerprisesoftware/html2pdf

By deventerprisesoftware

•Updated 4 months ago

Simple API to Convert HTML into PDF format using a headless Chromium browser instance.

Image
Developer tools
1

1.2K

deventerprisesoftware/html2pdf repository overview

⁠HTML-2-PDF API Service

Provides endpoints to convert raw HTML into a PDF document with configurable options.

The container starts up a headless Chrome browser instance (JavaScript and service workers disabled) and renders the provided HTML to export a PDF. Host this service privately and only pass trusted HTML content.

⁠Endpoints
MethodPathDescription
GET/Returns the current API version
POST/Converts HTML to a PDF file
⁠POST Request Body
FieldTypeRequiredDefaultDescription
htmlstringYesRaw HTML content to convert
fileNamestringNo"file"Output filename (without extension)
formatstringNo"Letter"Page size: Letter, Legal, Tabloid, Ledger, A0–A6
printBackgroundboolNotrueWhether to include CSS backgrounds
⁠Usage

The container exposes port 5000 so you can bind that to a port number of your choice (8080 in the example below).

docker run -p 8080:5000 deventerprisesoftware/html2pdf
⁠Examples
⁠cURL
curl \
  -d '{ "html": "<h1>HTML 2 PDF</h1><p>Sample text</p>", "format": "A4" }' \
  -H "Content-Type: application/json" \
  --output test_file.pdf \
  -X POST "http://localhost:8080/"
⁠C#
using System.Net.Http;
using System.Text;
using System.Text.Json;

var request = JsonSerializer.Serialize(new
{
    Html = "<h1>HTML 2 PDF</h1><p>Sample text</p>",
    FileName = "test_file",
    Format = "A4"
});

using var httpClient = new HttpClient();
using var requestContent = new StringContent(request, Encoding.UTF8, "application/json");

var response = await httpClient.PostAsync("http://localhost:8080/", requestContent);
response.EnsureSuccessStatusCode();

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

await File.WriteAllBytesAsync("test_file.pdf", pdfBytes);
⁠Github

https://github.com/DevEnterpriseSoftware/Html2Pdf⁠

Tag summary

Content type

Image

Digest

sha256:8599aa2c9…

Size

602.9 MB

Last updated

4 months ago

docker pull deventerprisesoftware/html2pdf