8000 fix: improve Precision of Paper Sizes in Inches to 4 Decimal Places by hangyeol0531 · Pull Request #13087 · puppeteer/puppeteer · GitHub
[go: up one dir, main page]

Skip to content

fix: improve Precision of Paper Sizes in Inches to 4 Decimal Places #13087

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

Merged
merged 3 commits into from
Sep 16, 2024

Conversation

hangyeol0531
Copy link
Contributor
@hangyeol0531 hangyeol0531 commented Sep 14, 2024

This is related to the issue below.

#13050

By increasing the decimal places to 4, the accuracy was improved, and this resolved the issue.

The values were adjusted according to the ISO 216 A series.

As you can see in the two pictures below, the page size is the same. (It was different before the code change)

// works
const correctCreatePDFA4 = async (htmlString) => {
    const browser = await puppeteer.launch({
        executablePath: '/usr/local/bin/chromium',
        headless: true,
    });
    const page = await browser.newPage();
    await page.setContent(htmlString);
    const pdfBuffer = await page.pdf({path:'correctCreatePDFA4.pdf' , width: "210mm", height: "297mm" });
    await browser.close();
    return Buffer.from(pdfBuffer)
};

// doesnt work
const incorrectCreatePDFA4 = async (htmlString) => {
    const browser = await puppeteer.launch({
        executablePath: '/usr/local/bin/chromium',
        headless: true,
    });
    const page = await browser.newPage();
    await page.setContent(htmlString);
    const pdfBuffer = await page.pdf({path:'incorrectCreatePDFA4.pdf' , format: 'A4' });
    await browser.close();
    return Buffer.from(pdfBuffer)
};

(async () => {
    await correctCreatePDFA4(htmlString)
    await incorrectCreatePDFA4(htmlString)
})();
incorrect correct

Copy link
google-cla bot commented Sep 14, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@OrKoN OrKoN changed the title feat: improve Precision of Paper Sizes in Inches to 4 Decimal Places fix: improve Precision of Paper Sizes in Inches to 4 Decimal Places Sep 16, 2024
@OrKoN OrKoN force-pushed the feat/inch-precision-4-decimals branch from ca5eb8f to da1fc2a Compare September 16, 2024 09:47
@OrKoN OrKoN enabled auto-merge (squash) September 16, 2024 09:47
@OrKoN
Copy link
Collaborator
OrKoN commented Sep 16, 2024

Thanks!

@OrKoN OrKoN merged commit 47d6c44 into puppeteer:main Sep 16, 2024
35 checks passed
@release-please release-please bot mentioned this pull request Sep 16, 2024
@hangyeol0531 hangyeol0531 deleted the feat/inch-precision-4-decimals branch September 17, 2024 18:27
@release-please release-please bot mentioned this pull request Jan 10, 2025
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

Successfully merging this pull request may close these issues.

2 participants
0