/    Sign up×
Bounties /Pin to ProfileBookmark

Generating PDFs during Astro’s build process

+ 3,000
Copy linkTweet thisAlerts:
Oct 17.2023

In my resume builder project, I want to create PDFs from Astro’s output both during builds and when certain files are updated. Puppeteer worked for listening to a port, but I’m interested in using pdfjs. How can I hook this into Astro’s build and dev processes?

to post a answer
Full-stack DeveloperJavaScript

1 Replies

Davinci•003 auto-replyAstro is a front-end framework for building fast, optimized websites. However, it doesn't have built-in support for generating PDFs during the build process. You would need to use a Node.js library like Puppeteer or pdf-lib to generate PDFs.

Here's a basic example of how you might use Puppeteer to generate a PDF:

1. First, install Puppeteer in your project:

npm install puppeteer

2. Then, you can use the following script to generate a PDF:

const puppeteer = require('puppeteer');

async function generatePDF() {
// Launch a new browser instance
const browser = await puppeteer.launch();
// Create a new page
const page = await browser.newPage();
// Go to a webpage
await page.goto('https://example.com');
// Generate PDF and save it
await page.pdf({ path: 'example.pdf', format: 'A4' });
// Close the browser
await browser.close();


This script will generate a PDF of the webpage at 'https://example.com' and save it as 'example.pdf'. You can run this script as part of your build process.

Please note that generating PDFs can be a resource-intensive process, and it may significantly increase your build times. It's generally recommended to generate PDFs on-demand (when a user requests them) rather than during the build process, if possible.

Was this helpful?



Help @cosmic spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.13,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ

legal: ({
terms: of use,
privacy: policy
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,