Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Font not rendered at all #12646

Closed
tiaxter opened this issue Nov 21, 2020 · 1 comment
Closed

Font not rendered at all #12646

tiaxter opened this issue Nov 21, 2020 · 1 comment

Comments

@tiaxter
Copy link

tiaxter commented Nov 21, 2020

Link to PDF file:
https://www.interno.gov.it/sites/default/files/2020-10/modello_autodichiarazione_editabile_ottobre_2020.pdf

Configuration:

  • Web browser and its version: I'm using NodeJS not browser
  • Operating system and its version: Windows 10
  • PDF.js version: "^2.5.207",
  • Is a browser extension: No

Steps to reproduce the problem:

const pdf = "https://www.interno.gov.it/sites/default/files/2020-10/modello_autodichiarazione_editabile_ottobre_2020.pdf";

(async function () {

    const pdfBuffer = await fetch(pdf).then(res => res.buffer()).then(buffer => buffer);

    await convert2PNG(file);

    async function convert2PNG(pdfFile) {
        PDFJavaScript.disableWorker = true;
        PDFJavaScript.disableFontFace = true;
        const loadingTask = pdfjsLib.getDocument(pdfFile);
        const pdfDocument = await loadingTask.promise;
        const page = await pdfDocument.getPage(1);

        const viewport = page.getViewport({scale: 1.0});
        const canvasFactory = new NodeCanvasFactory();
        const canvasAndContext = canvasFactory.create(
            viewport.width,
            viewport.height
        );
        const renderContext = {
            canvasContext: canvasAndContext.context,
            viewport: viewport,
            canvasFactory: canvasFactory,
            renderInteractiveForms: true,
        };
        await page.render(renderContext).promise;
        const image = canvasAndContext.canvas.toBuffer();
        fs.writeFile("output.png", image, function (error) {
            if (error) {
                console.error("Error: " + error);
            } else {
                console.log("Finished converting first page of PDF file to a PNG image.");
            }
        });

    }
});

What is the expected behavior?
image

What went wrong?
The initial part of PDF, and font is not rendered at all.
output

I noticed that fonts are not embedded, so may I ask is there a way to embed missing fonts?

@Snuffleupagus
Copy link
Collaborator

Duplicate of #4244

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants