You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
HTML:
<!DOCTYPEhtml><htmllang="en"><head><style>
@importurl('https://fonts.googleapis.com/css2?family=Roboto:wght@400;700&display=swap');body,*{font-family: 'Roboto', sans-serif!important;}</style><metacharset="UTF-8"></head><body><divstyle="margin: 50px;"><h1style="font-weight: bold; font-size: 24pt; color: #333;"id="departureDate">DepartureDate</h1><pstyle="font-size: 18pt; color: #333;"id="city-pair">CityPair: From-To</p><pstyle="font-size: 18pt; color: #333;"id="passengerName">PassengerName</p><pstyle="font-size: 18pt; color: #333;"id="flightNumber">FlightNumber</p><pstyle="font-size: 18pt; color: #333;"id="AirlineName">AirlineName</p></div></body></html>SERVER:
constpuppeteer=require('puppeteer');constfs=require('fs');constpath=require('path');// Read the HTML templateconsthtmlTemplate=fs.readFileSync(path.resolve(__dirname,'ticket-template.html'),'utf8');(async()=>{try{constbrowser=awaitpuppeteer.launch();constpage=awaitbrowser.newPage();// Set the HTML contentawaitpage.setContent(htmlTemplate,{waitUntil: 'networkidle0'});// Inject data into the templateawaitpage.evaluate(()=>{document.getElementById('departureDate').textContent='2024-05-16 08:30';document.getElementById('city-pair').textContent='City Pair: New York - London';document.getElementById('passengerName').textContent='John Doe';document.getElementById('flightNumber').textContent='Flight Number: AA123';document.getElementById('AirlineName').textContent='Airline: American Airlines';});// Wait for fonts to loadawaitpage.evaluateHandle('document.fonts.ready');// Generate the PDFconstpdfBuffer=awaitpage.pdf({path: 'test.pdf',format: 'A4',printBackground: true});awaitbrowser.close();console.log('PDF generated successfully');}catch(error){console.error('Error generating PDF:',error);}})();
Error string
no error
Bug behavior
Flaky
PDF
Background
I've been trying to generate PDFs from HTML templates using Puppeteer. While the HTML renders correctly in a browser, the text appears as gibberish or is incorrectly encoded in the generated PDFs.
Expectation
I expected the generated PDF to display the text as it appears in the HTML template, with the correct font and encoding.
Reality
In reality, the text in the generated PDF appears as gibberish or is incorrectly encoded.
Puppeteer configuration file (if used)
No response
Puppeteer version
22.8.2
Node version
18.16.0
Package manager
npm
Package manager version
9.5.1
Operating system
Windows
The text was updated successfully, but these errors were encountered:
This issue was not reproducible. Please check that your example runs locally and the following:
Ensure the script does not rely on dependencies outside of puppeteer and puppeteer-core.
Ensure the error string is just the error message.
Bad:
Error: somethingwentwrongatObject.<anonymous>(/Users/username/repository/script.js:2:1)atModule._compile(node:internal/modules/cjs/loader:1159:14)atModule._extensions..js(node:internal/modules/cjs/loader:1213:10)atModule.load(node:internal/modules/cjs/loader:1037:32)atModule._load(node:internal/modules/cjs/loader:878:12)atFunction.executeUserEntryPoint[asrunMain](node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
Good: Error: something went wrong.
Ensure your configuration file (if applicable) is valid.
If the issue is flaky (does not reproduce all the time), make sure 'Flaky' is checked.
If the issue is not expected to error, make sure to write 'no error'.
Once the above checks are satisfied, please edit your issue with the changes and we will
try to reproduce the bug again.
Minimal, reproducible example
Error string
no error
Bug behavior
Background
I've been trying to generate PDFs from HTML templates using Puppeteer. While the HTML renders correctly in a browser, the text appears as gibberish or is incorrectly encoded in the generated PDFs.
Expectation
I expected the generated PDF to display the text as it appears in the HTML template, with the correct font and encoding.
Reality
In reality, the text in the generated PDF appears as gibberish or is incorrectly encoded.
Puppeteer configuration file (if used)
No response
Puppeteer version
22.8.2
Node version
18.16.0
Package manager
npm
Package manager version
9.5.1
Operating system
Windows
The text was updated successfully, but these errors were encountered: