How to use PDFDocument method in wpt

Best JavaScript code snippet using wpt

Renderer.js

Source:Renderer.js Github

copy

Full Screen

1import TextDecorator from './TextDecorator';2import TextInlines from './TextInlines';3import { isNumber } from './helpers/variableType';4import SVGtoPDF from './3rd-party/svg-to-pdfkit';5const findFont = (fonts, requiredFonts, defaultFont) => {6 for (let i = 0; i < requiredFonts.length; i++) {7 let requiredFont = requiredFonts[i].toLowerCase();8 for (let font in fonts) {9 if (font.toLowerCase() === requiredFont) {10 return font;11 }12 }13 }14 return defaultFont;15};16/**17 * Shift the "y" height of the text baseline up or down (superscript or subscript,18 * respectively). The exact shift can / should be changed according to standard19 * conventions.20 *21 * @param {number} y22 * @param {object} inline23 * @returns {number}24 */25const offsetText = (y, inline) => {26 var newY = y;27 if (inline.sup) {28 newY -= inline.fontSize * 0.75;29 }30 if (inline.sub) {31 newY += inline.fontSize * 0.35;32 }33 return newY;34};35class Renderer {36 constructor(pdfDocument, progressCallback) {37 this.pdfDocument = pdfDocument;38 this.progressCallback = progressCallback;39 }40 renderPages(pages) {41 this.pdfDocument._pdfMakePages = pages; // TODO: Why?42 this.pdfDocument.addPage();43 let totalItems = 0;44 if (this.progressCallback) {45 pages.forEach(page => {46 totalItems += page.items.length;47 });48 }49 let renderedItems = 0;50 for (let i = 0; i < pages.length; i++) {51 if (i > 0) {52 this._updatePageOrientationInOptions(pages[i]);53 this.pdfDocument.addPage(this.pdfDocument.options);54 }55 let page = pages[i];56 for (let ii = 0, il = page.items.length; ii < il; ii++) {57 let item = page.items[ii];58 switch (item.type) {59 case 'vector':60 this.renderVector(item.item);61 break;62 case 'line':63 this.renderLine(item.item, item.item.x, item.item.y);64 break;65 case 'image':66 this.renderImage(item.item);67 break;68 case 'svg':69 this.renderSVG(item.item);70 break;71 case 'attachment':72 this.renderAttachment(item.item);73 break;74 case 'beginClip':75 this.beginClip(item.item);76 break;77 case 'endClip':78 this.endClip();79 break;80 }81 renderedItems++;82 if (this.progressCallback) {83 this.progressCallback(renderedItems / totalItems);84 }85 }86 if (page.watermark) {87 this.renderWatermark(page);88 }89 }90 }91 renderLine(line, x, y) {92 function preparePageNodeRefLine(_pageNodeRef, inline) {93 let newWidth;94 let diffWidth;95 let textInlines = new TextInlines(null);96 if (_pageNodeRef.positions === undefined) {97 throw new Error('Page reference id not found');98 }99 let pageNumber = _pageNodeRef.positions[0].pageNumber.toString();100 inline.text = pageNumber;101 newWidth = textInlines.widthOfText(inline.text, inline);102 diffWidth = inline.width - newWidth;103 inline.width = newWidth;104 switch (inline.alignment) {105 case 'right':106 inline.x += diffWidth;107 break;108 case 'center':109 inline.x += diffWidth / 2;110 break;111 }112 }113 if (line._pageNodeRef) {114 preparePageNodeRefLine(line._pageNodeRef, line.inlines[0]);115 }116 x = x || 0;117 y = y || 0;118 let lineHeight = line.getHeight();119 let ascenderHeight = line.getAscenderHeight();120 let descent = lineHeight - ascenderHeight;121 const textDecorator = new TextDecorator(this.pdfDocument);122 textDecorator.drawBackground(line, x, y);123 //TODO: line.optimizeInlines();124 //TOOD: lines without differently styled inlines should be written to pdf as one stream125 for (let i = 0, l = line.inlines.length; i < l; i++) {126 let inline = line.inlines[i];127 let shiftToBaseline = lineHeight - ((inline.font.ascender / 1000) * inline.fontSize) - descent;128 if (inline._pageNodeRef) {129 preparePageNodeRefLine(inline._pageNodeRef, inline);130 }131 let options = {132 lineBreak: false,133 textWidth: inline.width,134 characterSpacing: inline.characterSpacing,135 wordCount: 1,136 link: inline.link137 };138 if (inline.linkToDestination) {139 options.goTo = inline.linkToDestination;140 }141 if (line.id && i === 0) {142 options.destination = line.id;143 }144 if (inline.fontFeatures) {145 options.features = inline.fontFeatures;146 }147 let opacity = isNumber(inline.opacity) ? inline.opacity : 1;148 this.pdfDocument.opacity(opacity);149 this.pdfDocument.fill(inline.color || 'black');150 this.pdfDocument._font = inline.font;151 this.pdfDocument.fontSize(inline.fontSize);152 let shiftedY = offsetText(y + shiftToBaseline, inline);153 this.pdfDocument.text(inline.text, x + inline.x, shiftedY, options);154 if (inline.linkToPage) {155 this.pdfDocument.ref({ Type: 'Action', S: 'GoTo', D: [inline.linkToPage, 0, 0] }).end();156 this.pdfDocument.annotate(x + inline.x, shiftedY, inline.width, inline.height, { Subtype: 'Link', Dest: [inline.linkToPage - 1, 'XYZ', null, null, null] });157 }158 }159 // Decorations won't draw correctly for superscript160 textDecorator.drawDecorations(line, x, y);161 }162 renderVector(vector) {163 //TODO: pdf optimization (there's no need to write all properties everytime)164 this.pdfDocument.lineWidth(vector.lineWidth || 1);165 if (vector.dash) {166 this.pdfDocument.dash(vector.dash.length, { space: vector.dash.space || vector.dash.length, phase: vector.dash.phase || 0 });167 } else {168 this.pdfDocument.undash();169 }170 this.pdfDocument.lineJoin(vector.lineJoin || 'miter');171 this.pdfDocument.lineCap(vector.lineCap || 'butt');172 //TODO: clipping173 let gradient = null;174 switch (vector.type) {175 case 'ellipse':176 this.pdfDocument.ellipse(vector.x, vector.y, vector.r1, vector.r2);177 if (vector.linearGradient) {178 gradient = this.pdfDocument.linearGradient(vector.x - vector.r1, vector.y, vector.x + vector.r1, vector.y);179 }180 break;181 case 'rect':182 if (vector.r) {183 this.pdfDocument.roundedRect(vector.x, vector.y, vector.w, vector.h, vector.r);184 } else {185 this.pdfDocument.rect(vector.x, vector.y, vector.w, vector.h);186 }187 if (vector.linearGradient) {188 gradient = this.pdfDocument.linearGradient(vector.x, vector.y, vector.x + vector.w, vector.y);189 }190 break;191 case 'line':192 this.pdfDocument.moveTo(vector.x1, vector.y1);193 this.pdfDocument.lineTo(vector.x2, vector.y2);194 break;195 case 'polyline':196 if (vector.points.length === 0) {197 break;198 }199 this.pdfDocument.moveTo(vector.points[0].x, vector.points[0].y);200 for (let i = 1, l = vector.points.length; i < l; i++) {201 this.pdfDocument.lineTo(vector.points[i].x, vector.points[i].y);202 }203 if (vector.points.length > 1) {204 let p1 = vector.points[0];205 let pn = vector.points[vector.points.length - 1];206 if (vector.closePath || p1.x === pn.x && p1.y === pn.y) {207 this.pdfDocument.closePath();208 }209 }210 break;211 case 'path':212 this.pdfDocument.path(vector.d);213 break;214 }215 if (vector.linearGradient && gradient) {216 let step = 1 / (vector.linearGradient.length - 1);217 for (let i = 0; i < vector.linearGradient.length; i++) {218 gradient.stop(i * step, vector.linearGradient[i]);219 }220 vector.color = gradient;221 }222 let patternColor = this.pdfDocument.providePattern(vector.color);223 if (patternColor !== null) {224 vector.color = patternColor;225 }226 let fillOpacity = isNumber(vector.fillOpacity) ? vector.fillOpacity : 1;227 let strokeOpacity = isNumber(vector.strokeOpacity) ? vector.strokeOpacity : 1;228 if (vector.color && vector.lineColor) {229 this.pdfDocument.fillColor(vector.color, fillOpacity);230 this.pdfDocument.strokeColor(vector.lineColor, strokeOpacity);231 this.pdfDocument.fillAndStroke();232 } else if (vector.color) {233 this.pdfDocument.fillColor(vector.color, fillOpacity);234 this.pdfDocument.fill();235 } else {236 this.pdfDocument.strokeColor(vector.lineColor || 'black', strokeOpacity);237 this.pdfDocument.stroke();238 }239 }240 renderImage(image) {241 let opacity = isNumber(image.opacity) ? image.opacity : 1;242 this.pdfDocument.opacity(opacity);243 if (image.cover) {244 const align = image.cover.align || 'center';245 const valign = image.cover.valign || 'center';246 const width = image.cover.width ? image.cover.width : image.width;247 const height = image.cover.height ? image.cover.height : image.height;248 this.pdfDocument.save();249 this.pdfDocument.rect(image.x, image.y, width, height).clip();250 this.pdfDocument.image(image.image, image.x, image.y, { cover: [width, height], align: align, valign: valign });251 this.pdfDocument.restore();252 } else {253 this.pdfDocument.image(image.image, image.x, image.y, { width: image._width, height: image._height });254 }255 if (image.link) {256 this.pdfDocument.link(image.x, image.y, image._width, image._height, image.link);257 }258 if (image.linkToPage) {259 this.pdfDocument.ref({ Type: 'Action', S: 'GoTo', D: [image.linkToPage, 0, 0] }).end();260 this.pdfDocument.annotate(image.x, image.y, image._width, image._height, { Subtype: 'Link', Dest: [image.linkToPage - 1, 'XYZ', null, null, null] });261 }262 if (image.linkToDestination) {263 this.pdfDocument.goTo(image.x, image.y, image._width, image._height, image.linkToDestination);264 }265 if (image.linkToFile) {266 const attachment = this.pdfDocument.provideAttachment(image.linkToFile);267 this.pdfDocument.fileAnnotation(268 image.x,269 image.y,270 image._width,271 image._height,272 attachment,273 // add empty rectangle as file annotation appearance with the same size as the rendered image274 {275 AP: {276 N: {277 Type: 'XObject',278 Subtype: 'Form',279 FormType: 1,280 BBox: [image.x, image.y, image._width, image._height]281 }282 },283 }284 );285 }286 }287 renderSVG(svg) {288 let options = Object.assign({ width: svg._width, height: svg._height, assumePt: true }, svg.options);289 options.fontCallback = (family, bold, italic) => {290 let fontsFamily = family.split(',').map(f => f.trim().replace(/('|")/g, ''));291 let font = findFont(this.pdfDocument.fonts, fontsFamily, svg.font || 'Roboto');292 let fontFile = this.pdfDocument.getFontFile(font, bold, italic);293 if (fontFile === null) {294 let type = this.pdfDocument.getFontType(bold, italic);295 throw new Error(`Font '${font}' in style '${type}' is not defined in the font section of the document definition.`);296 }297 return fontFile;298 };299 SVGtoPDF(this.pdfDocument, svg.svg, svg.x, svg.y, options);300 }301 renderAttachment(attachment) {302 const file = this.pdfDocument.provideAttachment(attachment.attachment);303 const options = {};304 if (attachment.icon) {305 options.Name = attachment.icon;306 }307 this.pdfDocument.fileAnnotation(attachment.x, attachment.y, attachment._width, attachment._height, file, options);308 }309 beginClip(rect) {310 this.pdfDocument.save();311 this.pdfDocument.addContent(`${rect.x} ${rect.y} ${rect.width} ${rect.height} re`);312 this.pdfDocument.clip();313 }314 endClip() {315 this.pdfDocument.restore();316 }317 renderWatermark(page) {318 let watermark = page.watermark;319 this.pdfDocument.fill(watermark.color);320 this.pdfDocument.opacity(watermark.opacity);321 this.pdfDocument.save();322 this.pdfDocument.rotate(watermark.angle, { origin: [this.pdfDocument.page.width / 2, this.pdfDocument.page.height / 2] });323 let x = this.pdfDocument.page.width / 2 - watermark._size.size.width / 2;324 let y = this.pdfDocument.page.height / 2 - watermark._size.size.height / 2;325 this.pdfDocument._font = watermark.font;326 this.pdfDocument.fontSize(watermark.fontSize);327 this.pdfDocument.text(watermark.text, x, y, { lineBreak: false });328 this.pdfDocument.restore();329 }330 _updatePageOrientationInOptions(currentPage) {331 let previousPageOrientation = this.pdfDocument.options.size[0] > this.pdfDocument.options.size[1] ? 'landscape' : 'portrait';332 if (currentPage.pageSize.orientation !== previousPageOrientation) {333 let width = this.pdfDocument.options.size[0];334 let height = this.pdfDocument.options.size[1];335 this.pdfDocument.options.size = [height, width];336 }337 }338}...

Full Screen

Full Screen

pdf_document_properties.js

Source:pdf_document_properties.js Github

copy

Full Screen

1/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */2/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */3/* Copyright 2012 Mozilla Foundation4 *5 * Licensed under the Apache License, Version 2.0 (the "License");6 * you may not use this file except in compliance with the License.7 * You may obtain a copy of the License at8 *9 * http://www.apache.org/licenses/LICENSE-2.010 *11 * Unless required by applicable law or agreed to in writing, software12 * distributed under the License is distributed on an "AS IS" BASIS,13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.14 * See the License for the specific language governing permissions and15 * limitations under the License.16 */17/* globals Promise, mozL10n, getPDFFileNameFromURL, OverlayManager */18'use strict';19/**20 * @typedef {Object} PDFDocumentPropertiesOptions21 * @property {string} overlayName - Name/identifier for the overlay.22 * @property {Object} fields - Names and elements of the overlay's fields.23 * @property {HTMLButtonElement} closeButton - Button for closing the overlay.24 */25/**26 * @class27 */28var PDFDocumentProperties = (function PDFDocumentPropertiesClosure() {29 /**30 * @constructs PDFDocumentProperties31 * @param {PDFDocumentPropertiesOptions} options32 */33 function PDFDocumentProperties(options) {34 this.fields = options.fields;35 this.overlayName = options.overlayName;36 this.rawFileSize = 0;37 this.url = null;38 this.pdfDocument = null;39 // Bind the event listener for the Close button.40 if (options.closeButton) {41 options.closeButton.addEventListener('click', this.close.bind(this));42 }43 this.dataAvailablePromise = new Promise(function (resolve) {44 this.resolveDataAvailable = resolve;45 }.bind(this));46 OverlayManager.register(this.overlayName, this.close.bind(this));47 }48 PDFDocumentProperties.prototype = {49 /**50 * Open the document properties overlay.51 */52 open: function PDFDocumentProperties_open() {53 Promise.all([OverlayManager.open(this.overlayName),54 this.dataAvailablePromise]).then(function () {55 this._getProperties();56 }.bind(this));57 },58 /**59 * Close the document properties overlay.60 */61 close: function PDFDocumentProperties_close() {62 OverlayManager.close(this.overlayName);63 },64 /**65 * Set the file size of the PDF document. This method is used to66 * update the file size in the document properties overlay once it67 * is known so we do not have to wait until the entire file is loaded.68 *69 * @param {number} fileSize - The file size of the PDF document.70 */71 setFileSize: function PDFDocumentProperties_setFileSize(fileSize) {72 if (fileSize > 0) {73 this.rawFileSize = fileSize;74 }75 },76 /**77 * Set a reference to the PDF document and the URL in order78 * to populate the overlay fields with the document properties.79 * Note that the overlay will contain no information if this method80 * is not called.81 *82 * @param {Object} pdfDocument - A reference to the PDF document.83 * @param {string} url - The URL of the document.84 */85 setDocumentAndUrl:86 function PDFDocumentProperties_setDocumentAndUrl(pdfDocument, url) {87 this.pdfDocument = pdfDocument;88 this.url = url;89 this.resolveDataAvailable();90 },91 /**92 * @private93 */94 _getProperties: function PDFDocumentProperties_getProperties() {95 if (!OverlayManager.active) {96 // If the dialog was closed before dataAvailablePromise was resolved,97 // don't bother updating the properties.98 return;99 }100 // Get the file size (if it hasn't already been set).101 this.pdfDocument.getDownloadInfo().then(function(data) {102 if (data.length === this.rawFileSize) {103 return;104 }105 this.setFileSize(data.length);106 this._updateUI(this.fields['fileSize'], this._parseFileSize());107 }.bind(this));108 // Get the document properties.109 this.pdfDocument.getMetadata().then(function(data) {110 var content = {111 'fileName': getPDFFileNameFromURL(this.url),112 'fileSize': this._parseFileSize(),113 'title': data.info.Title,114 'author': data.info.Author,115 'subject': data.info.Subject,116 'keywords': data.info.Keywords,117 'creationDate': this._parseDate(data.info.CreationDate),118 'modificationDate': this._parseDate(data.info.ModDate),119 'creator': data.info.Creator,120 'producer': data.info.Producer,121 'version': data.info.PDFFormatVersion,122 'pageCount': this.pdfDocument.numPages123 };124 // Show the properties in the dialog.125 for (var identifier in content) {126 this._updateUI(this.fields[identifier], content[identifier]);127 }128 }.bind(this));129 },130 /**131 * @private132 */133 _updateUI: function PDFDocumentProperties_updateUI(field, content) {134 if (field && content !== undefined && content !== '') {135 field.textContent = content;136 }137 },138 /**139 * @private140 */141 _parseFileSize: function PDFDocumentProperties_parseFileSize() {142 var fileSize = this.rawFileSize, kb = fileSize / 1024;143 if (!kb) {144 return;145 } else if (kb < 1024) {146 return mozL10n.get('document_properties_kb', {147 size_kb: (+kb.toPrecision(3)).toLocaleString(),148 size_b: fileSize.toLocaleString()149 }, '{{size_kb}} KB ({{size_b}} bytes)');150 } else {151 return mozL10n.get('document_properties_mb', {152 size_mb: (+(kb / 1024).toPrecision(3)).toLocaleString(),153 size_b: fileSize.toLocaleString()154 }, '{{size_mb}} MB ({{size_b}} bytes)');155 }156 },157 /**158 * @private159 */160 _parseDate: function PDFDocumentProperties_parseDate(inputDate) {161 // This is implemented according to the PDF specification, but note that162 // Adobe Reader doesn't handle changing the date to universal time163 // and doesn't use the user's time zone (they're effectively ignoring164 // the HH' and mm' parts of the date string).165 var dateToParse = inputDate;166 if (dateToParse === undefined) {167 return '';168 }169 // Remove the D: prefix if it is available.170 if (dateToParse.substring(0,2) === 'D:') {171 dateToParse = dateToParse.substring(2);172 }173 // Get all elements from the PDF date string.174 // JavaScript's Date object expects the month to be between175 // 0 and 11 instead of 1 and 12, so we're correcting for this.176 var year = parseInt(dateToParse.substring(0,4), 10);177 var month = parseInt(dateToParse.substring(4,6), 10) - 1;178 var day = parseInt(dateToParse.substring(6,8), 10);179 var hours = parseInt(dateToParse.substring(8,10), 10);180 var minutes = parseInt(dateToParse.substring(10,12), 10);181 var seconds = parseInt(dateToParse.substring(12,14), 10);182 var utRel = dateToParse.substring(14,15);183 var offsetHours = parseInt(dateToParse.substring(15,17), 10);184 var offsetMinutes = parseInt(dateToParse.substring(18,20), 10);185 // As per spec, utRel = 'Z' means equal to universal time.186 // The other cases ('-' and '+') have to be handled here.187 if (utRel === '-') {188 hours += offsetHours;189 minutes += offsetMinutes;190 } else if (utRel === '+') {191 hours -= offsetHours;192 minutes -= offsetMinutes;193 }194 // Return the new date format from the user's locale.195 var date = new Date(Date.UTC(year, month, day, hours, minutes, seconds));196 var dateString = date.toLocaleDateString();197 var timeString = date.toLocaleTimeString();198 return mozL10n.get('document_properties_date_string',199 {date: dateString, time: timeString},200 '{{date}}, {{time}}');201 }202 };203 return PDFDocumentProperties;...

Full Screen

Full Screen

pdfUtils.ts

Source:pdfUtils.ts Github

copy

Full Screen

2import PDFDocument from 'pdfkit';3import { config } from '../../config';4import { RISEAPPS_ADDRESS, RISEAPPS_EMAIL, RISEAPPS_PHONE } from '../config';5export const createPDFDocument = (): PDFKit.PDFDocument => {6 const pdfDocument = new PDFDocument({7 margins: {8 top: config.pdfDocument.sizes.verticalMargin,9 bottom: config.pdfDocument.sizes.verticalMargin,10 left: config.pdfDocument.sizes.horizontalMargin,11 right: config.pdfDocument.sizes.horizontalMargin,12 },13 info: {14 Author: config.pdfDocument.author,15 Creator: config.pdfDocument.creator,16 CreationDate: new Date(),17 },18 });19 pdfDocument.registerFont(config.pdfDocument.fonts.regularFont, config.pdfDocument.fonts.regularFontPath);20 pdfDocument.registerFont(config.pdfDocument.fonts.boldFont, config.pdfDocument.fonts.boldFontPath);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var PDFDocument = require('pdfkit');2var doc = new PDFDocument();3doc.pipe(fs.createWriteStream('output.pdf'));4doc.fontSize(25)5 .text('Here is some vector graphics...', 100, 80);6doc.scale(0.6)7 .translate(470, -380)8 .path('M 250,75 L 323,301 131,161 369,161 177,301 z')9 .fill("red", "even-odd")10 .restore();11doc.addPage()12 .fontSize(25)13 .text('Here is some text wrapped into columns...', 100, 80);14doc.text('And here is some wrapped text...', {15});16doc.end();17var PDFDocument = require('pdfkit');18var doc = new PDFDocument();19doc.pipe(fs.createWriteStream('output.pdf'));20doc.fontSize(25)21 .text('Here is some vector graphics...', 100, 80);22doc.scale(0.6)23 .translate(470, -380)24 .path('M 250,75 L 323,301 131,161 369,161 177,301 z')25 .fill("red", "even-odd")26 .restore();27doc.addPage()28 .fontSize(25)29 .text('Here is some text wrapped into columns...', 100, 80);30doc.text('And here is some wrapped text...', {31});32doc.end();33var PDFDocument = require('pdfkit');34var doc = new PDFDocument();35doc.pipe(fs.createWriteStream('output.pdf'));36doc.fontSize(25)37 .text('Here is some vector graphics...', 100, 80);38doc.scale(0.6)39 .translate(470, -380)40 .path('M 250,75 L 323,301 131,161 369,161 177,301 z')

Full Screen

Using AI Code Generation

copy

Full Screen

1var PDFDocument = require('pdfkit');2var doc = new PDFDocument;3doc.pipe(fs.createWriteStream('output.pdf'));4doc.text('Some text with an embedded font!', 100, 100);5doc.addPage()6 .fontSize(25)7 .text('Here is some vector graphics...', 100, 100);8doc.save()9 .moveTo(100, 150)10 .lineTo(100, 250)11 .lineTo(200, 250)12 .fill("#FF3300");13doc.scale(0.6)14 .translate(470, -380)15 .path('M 250,75 L 323,301 131,161 369,161 177,301 z')16 .fill('red', 'even-odd')17 .restore();18doc.addPage()19 .fillColor("blue")20 .text('Here is a link!', 100, 100)21 .underline(100, 100, 160, 27, {color: "#0000FF"})22doc.end();23How to Install Node.js on Windows Subsystem for Linux (WSL)

Full Screen

Using AI Code Generation

copy

Full Screen

1var PDFDocument = require('pdfkit');2var fs = require('fs');3var doc = new PDFDocument();4doc.pipe(fs.createWriteStream('output.pdf'));5doc.text('Hello world!');6doc.end();7var PDFDocument = require('pdfkit');8var fs = require('fs');9var doc = new PDFDocument();10doc.pipe(fs.createWriteStream('output.pdf'));11doc.text('Hello world!');12doc.end();13var file = new Blob([data], {type: 'application/pdf'});14var fileURL = URL.createObjectURL(file);15window.open(fileURL);16var file = new Blob([data], {type: 'application/pdf'});17var fileURL = URL.createObjectURL(file);18window.open(fileURL);19var doc = new PDFDocument();20doc.pipe(fs.createWriteStream('output.pdf'));21doc.text('Hello world!');22doc.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var PDFDocument = require('pdfkit');2var fs = require('fs');3var doc = new PDFDocument;4doc.pipe(fs.createWriteStream('output.pdf'));5doc.text('Hello world!');6doc.end();7var PDFDocument = require('pdfkit');8var fs = require('fs');9var doc = new PDFDocument;10doc.pipe(fs.createWriteStream('output.pdf'));11doc.text('Hello world!');12doc.end();13var PDFDocument = require('pdfkit');14var fs = require('fs');15var doc = new PDFDocument;16doc.pipe(fs.createWriteStream('output.pdf'));17doc.text('Hello world!');18doc.end();19var PDFDocument = require('pdfkit');20var fs = require('fs');21var doc = new PDFDocument;22doc.pipe(fs.createWriteStream('output.pdf'));23doc.text('Hello world!');24doc.end();25var PDFDocument = require('pdfkit');26var fs = require('fs');27var doc = new PDFDocument;28doc.pipe(fs.createWriteStream('output.pdf'));29doc.text('Hello world!');30doc.end();31var PDFDocument = require('pdfkit');32var fs = require('fs');33var doc = new PDFDocument;34doc.pipe(fs.createWriteStream('output.pdf'));35doc.text('Hello world!');36doc.end();37var PDFDocument = require('pdfkit');38var fs = require('fs');39var doc = new PDFDocument;40doc.pipe(fs.createWriteStream('output.pdf'));41doc.text('Hello world!');42doc.end();43var PDFDocument = require('pdfkit');44var fs = require('fs');45var doc = new PDFDocument;46doc.pipe(fs.createWriteStream('output.pdf'));47doc.text('Hello world!');48doc.end();49var PDFDocument = require('pdfkit');50var fs = require('fs');51var doc = new PDFDocument;52doc.pipe(fs.createWriteStream('output.pdf'));53doc.text('Hello world!');54doc.end();

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var pdf = require('html-pdf');4var options = { format: 'Letter' };5var html = fs.readFileSync('./test.html', 'utf8');6pdf.create(html, options).toFile('./test.pdf', function(err, res) {7 if (err) return console.log(err);8});9wptools.page('Albert_Einstein').get(function(err, info) {10 if (err) {11 console.log(err);12 } else {13 console.log(info);14 }15});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var pdf = require('pdfkit');3var fs = require('fs');4var doc = new pdf();5doc.pipe(fs.createWriteStream('output.pdf'));6doc.text('Hello world!', 100, 100);7doc.addPage()8 .fontSize(25)9 .text('Here is some vector graphics...', 100, 100);10doc.save()11 .moveTo(100, 150)12 .lineTo(100, 250)13 .lineTo(200, 250)14 .fill("#FF3300");15doc.scale(0.6)16 .translate(470, -380)17 .path('M 250,75 L 323,301 131,161 369,161 177,301 z')18 .fill('red', 'even-odd')19 .restore();20doc.addPage()21 .fillColor("blue")22 .text('Here is a link!', 100, 100)23 .underline(100, 100, 160, 27, {color: "#0000FF"})24doc.end();25var doc = new PDFDocument();26doc.pipe(fs.createWriteStream('output.pdf'));27doc.text('Hello world!');28doc.addPage()29 .fontSize(25)30 .text('Here is some vector graphics...', 100, 100);31doc.save()32 .moveTo(100, 150)33 .lineTo(100, 250)34 .lineTo(200, 250)35 .fill("#FF3300");36doc.scale(0.6)37 .translate(470, -380)38 .path('M 250,75 L 323,301 131,161 369,161 177,301 z')39 .fill('red', 'even-odd')40 .restore();41doc.addPage()42 .fillColor("blue")43 .text('Here is a link!', 100, 100)44 .underline(100, 100, 160, 27, {color: "#0000FF"})

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var request = require('request');4var file = fs.createWriteStream("file.pdf");5var request = http.get(url, function(response) {6 response.pipe(file);7});8wptools.page('Dr. Strangelove').get(function(err, resp) {9 resp.pdf(function(err, pdf) {10 console.log(pdf);11 });12});

Full Screen

Using AI Code Generation

copy

Full Screen

1var wptools = require('wptools');2var fs = require('fs');3var pdfPath = "./test.pdf";4var textPath = "./test.txt";5wptools.pdfDocument(pdfPath, textPath, function(err) {6 if (err) {7 console.log(err);8 }9 else {10 console.log("Success");11 }12});

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run wpt automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful