I have a fairly large .htm file, 100 MB which doesn't fully load in any browser I've tried (the page stops rendering after a certain point), so I want to try converting the file into a .pdf file so that I can view the entire document. Since a browser cannot fully render the file, which software/program out there can convert this large .htm file, if a browser cannot load the entire file in one go? Maybe some sort of software/program that can load the file in chunks at a time and then in the end, put them all together? Or converts the file on-the-fly without having to load the entire file before processing it? (I am on Windows 7) Thanks
익명
16:00
How to convert large .htm file to .pdf?
How to convert large .htm file to .pdf?
Top Answer/Comment:
Top Answer/Comment:
boxpdf-html (https://github.com/earonesty/boxpdf/tree/main/html) can convert static, document-style HTML without launching a browser:
npx -y boxpdf-html input.htm output.pdf --unsupported-css
It supports common HTML and CSS used in reports, tables, invoices, and similar documents. It does not execute JavaScript or provide full browser-compatible rendering, so check the reported unsupported CSS.
The underlying boxpdf (https://github.com/earonesty/boxpdf) library also has a streamFlow API that writes completed pages incrementally.
import { createWriteStream } from "node:fs";
import { PDFDocument, StandardFonts } from "pdf-lib";
import { nodeAdapter, streamFlow, text } from "boxpdf";
const pdf = await PDFDocument.create();
const font = await pdf.embedFont(StandardFonts.Helvetica);
const output = nodeAdapter(createWriteStream("output.pdf"));
async function* nodes() {
for await (const line of readLines()) {
yield text(line, { font, size: 10 });
}
}
await streamFlow(pdf, output, nodes());
However, the current boxpdf-html cli still reads and parses the entire HTML file before rendering (there are some output effeciencies from doing this); it does not parse an existing HTML file in chunks.
Disclosure: I am the author of boxpdf and boxpdf-html.
상단 광고의 [X] 버튼을 누르면 내용이 보입니다