feat: add md<->pdf document converters

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-07-31 08:31:53 +02:00
co-authored by Claude Sonnet 5
parent 1595c5e0af
commit 82533ca436
3 changed files with 30 additions and 0 deletions
+8
View File
@@ -58,6 +58,12 @@ async function convertHtmlToMd(inputPath, outputPath) {
await fs.writeFile(outputPath, markdown);
}
async function convertMdToPdf(inputPath, outputPath) {
const markdown = await fs.readFile(inputPath, 'utf8');
const html = new MarkdownIt().render(markdown);
await renderHtmlToPdf(html, outputPath);
}
async function extractPdfPageTexts(inputPath) {
const data = new Uint8Array(await fs.readFile(inputPath));
const doc = await pdfjsLib.getDocument({ data }).promise;
@@ -101,6 +107,8 @@ export function registerDocumentConverters() {
register({ family: 'document', sourceFormat: 'html', targetFormat: 'pdf', convert: convertHtmlToPdf });
register({ family: 'document', sourceFormat: 'md', targetFormat: 'html', convert: convertMdToHtml });
register({ family: 'document', sourceFormat: 'html', targetFormat: 'md', convert: convertHtmlToMd });
register({ family: 'document', sourceFormat: 'md', targetFormat: 'pdf', convert: convertMdToPdf });
register({ family: 'document', sourceFormat: 'pdf', targetFormat: 'md', convert: convertPdfToTxt });
register({ family: 'document', sourceFormat: 'docx', targetFormat: 'pdf', convert: convertDocxToPdf });
register({ family: 'document', sourceFormat: 'pdf', targetFormat: 'txt', convert: convertPdfToTxt });
register({ family: 'document', sourceFormat: 'pdf', targetFormat: 'html', convert: convertPdfToHtml });