@taktikal/pdf2html
Purpose
Provide utility functions for consuming Taktikal's PDF-to-HTML service.
Configuration
There is no default value for the URL. If it is not configured, you will run into errors.
import { setPdf2HtmlUrl } from "@taktikal/pdf2html";
setPdf2HtmlUrl(process.env.PDF_TO_HTML_URL);
Usage
Getting the PDF HTML
import { getPdfHtml } from "@taktikal/pdf2html";
const html = await getPdfHtml(pdfUrl);
Using the PDF HTML
import { PdfHtmlData } from "@taktikal/pdf2html";
const render = (html: PdfHtmlData) => (
<>
<Head>
{html.styles.map((styleHTML, i) => (
<style key={i.toString()} dangerouslySetInnerHTML={{ __html: styleHTML }} />
))}
</Head>
{html.pages.map((pageHTML, i) => (
<div
key={i}
id={"pf" + (i + 1).toString(16)} // pdf2htmlEX uses hexadecimal page numbering
className="pf"
data-page-no={i + 1}
dangerouslySetInnerHTML={{ __html: pageHTML }}
style={{ overflow: "hidden" }}
/>
))}
</>
);