6 examples of 'how to display pdf in html using javascript' in JavaScript

Every line of 'how to display pdf in html using javascript' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
47async function createPDF(html) {
48 let browser: any = null;
49 try {
50 browser = await getPuppeteer();
51 const page = await browser.newPage();
52 await page.setContent(html);
53 return await page.pdf(pdfOptions);
54 } catch (error) {
55 throw error;
56 } finally {
57 if (browser) {
58 await browser.close();
59 }
60 }
61}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

74function _showPDF(url, options, close){
75 var w = iframe.window || iframe.contentWindow;
76 w.showPDF(url, options, close);
77 viewer.style.display = 'block';
78}
59function openPDF({ patient, bgUnits = MGDL_UNITS }) {
60 const doc = new PDFDocument({ autoFirstPage: false, bufferPages: true, margin: MARGIN });
61 const stream = doc.pipe(blobStream());
62 const opts = {
63 bgPrefs: {
64 bgBounds: bgBounds[bgUnits],
65 bgUnits,
66 },
67 timePrefs: {
68 timezoneAware: true,
69 timezoneName: 'US/Eastern',
70 },
71 patient,
72 };
73
74 createPrintView('basics', data[bgUnits].basics, opts, doc).render();
75 PrintView.renderPageNumbers(doc);
76
77 doc.end();
78
79 stream.on('finish', () => {
80 window.open(stream.toBlobURL('application/pdf'));
81 });
82}
58function openPDF({ patient, bgUnits = MGDL_UNITS }) {
59 const doc = new PDFDocument({ autoFirstPage: false, bufferPages: true, margin: MARGIN });
60 const stream = doc.pipe(blobStream());
61 const opts = {
62 bgPrefs: {
63 bgBounds: bgBounds[bgUnits],
64 bgUnits,
65 },
66 timePrefs: {
67 timezoneAware: true,
68 timezoneName: 'US/Eastern',
69 },
70 numDays: {
71 bgLog: 30,
72 },
73 patient,
74 };
75
76 createPrintView('bgLog', data[bgUnits].bgLog, opts, doc).render();
77 PrintView.renderPageNumbers(doc);
78
79 doc.end();
80
81 stream.on('finish', () => {
82 window.open(stream.toBlobURL('application/pdf'));
83 });
84}
75printPDF() {
76 const invoiceID = this.props.invoice._id;
77 ipc.send('print-to-pdf', invoiceID);
78}
111async renderPdf(url, options) {
112 return new Promise((resolve, reject) => {
113 CDP({host: this.host, port: this.port}, async (client) => {
114 try{
115 this.log(`Opening ${url}`);
116 const {Page, Emulation, LayerTree} = client;
117 await Page.enable();
118 await LayerTree.enable();
119
120 const loaded = this.cbToPromise(Page.loadEventFired);
121 const jsDone = this.cbToPromise(Emulation.virtualTimeBudgetExpired);
122
123 await Page.navigate({url});
124 await Emulation.setVirtualTimePolicy({policy: 'pauseIfNetworkFetchesPending', budget: 5000});
125
126 await this.profileScope('Wait for load', async () => {
127 await loaded;
128 });
129
130 await this.profileScope('Wait for js execution', async () => {
131 await jsDone;
132 });
133
134 await this.profileScope('Wait for animations', async () => {
135 await new Promise((resolve) => {
136 setTimeout(resolve, 5000); // max waiting time
137 let timeout = setTimeout(resolve, 100);
138 LayerTree.layerPainted(() => {
139 clearTimeout(timeout);
140 timeout = setTimeout(resolve, 100);
141 });
142 });
143 });
144
145 const pdf = await Page.printToPDF(options);
146 const buff = Buffer.from(pdf.data, 'base64');
147 client.close();
148 resolve(buff);
149 }catch (e) {
150 reject(e.message)
151 }
152 });
153 });
154}

Related snippets