node-pdfkit

PDFKit, Not able to open the pdf generated

风格不统一 提交于 2020-01-06 14:46:27
问题 I am trying to generate a pdf using some texts of my own (and not a html page). I tried using PDFKit. I am able to generate the pdf but then I am not able to open it in Preview (It may be damaged or use a file format that Preview doesn’t recognize.) Below is the code, var fs = require('fs'); PDFDocument = require ('pdfkit'); var doc = new PDFDocument // Embed a font, set the font size, and render some text doc.text('Some text with an embedded font!', 100, 100) // Add another page doc.addPage(

PDFKit, Not able to open the pdf generated

拈花ヽ惹草 提交于 2020-01-06 14:46:13
问题 I am trying to generate a pdf using some texts of my own (and not a html page). I tried using PDFKit. I am able to generate the pdf but then I am not able to open it in Preview (It may be damaged or use a file format that Preview doesn’t recognize.) Below is the code, var fs = require('fs'); PDFDocument = require ('pdfkit'); var doc = new PDFDocument // Embed a font, set the font size, and render some text doc.text('Some text with an embedded font!', 100, 100) // Add another page doc.addPage(

Invalid PDF Structure error message with Nodejs & pdfkit

半腔热情 提交于 2020-01-06 08:09:52
问题 I am trying to generate a pdf using nodejs & pdfkit. This will be a GET webservice which will be hosted in AWS api gateway. I am trying to run it locally first and getting Invalid PDF structure everytime. Here is my code for it. The pdf file is getting generated properly if I place a local path of my system , but always turns up to be a invalid one if I call from browser or postman. Any help would be highly appreciated 'use strict'; const Actions = require('libs-api').Actions; const config =

Can I mix font weights in the same paragraph when using pdfkit?

≡放荡痞女 提交于 2020-01-02 02:24:53
问题 I'm trying to find a way to use bold font weights for inline emphasis in pdfkit Unfortunately I cannot find a way to change the font without forcing a line break (bad for inline emphasis...). I was trying something like: pdf.text('Hello ', LEFT, 200).font(bold).text('World!'); but this will output Hello World I also digged through the source but could not find any option to prevent this. Anyone has any idea or workaround to tackle this problem? EDIT : All I could come up with by now is a ugly

“Error: Unknown Version 0” when using NodeJS PDFKit

这一生的挚爱 提交于 2019-12-25 09:57:58
问题 I'm trying to get the very excellent NodeJS PDFKit to use custom fonts OpenSans and Roboto from Google Fonts. My code looks like the following: this.doc = new PDFDocument({bufferPages: true}); this.doc.registerFont("Roboto-Black", path.join(__dirname, "fonts", "Roboto-Black.ttf")); I've printed the path - it's finding the right file. I'm getting the following error: C:\projects\qbdvision\node_modules\restructure\src\VersionedStruct.js:37 throw new Error("Unknown version " + res.version); ^

HTML table in pdfkit (Expressjs-Nodejs)

孤街醉人 提交于 2019-12-18 13:15:14
问题 I am using pdfkit to generate pdf file and i want to send this pdf file to browser. My following code is working fine and i am getting one pdf with text. Actually following code is sample to generate pdf using pdfkit in nodejs but now i want to create html table. Latest Code var PDFDocument = require('pdfkit'); var fs=require('fs'); doc = new PDFDocument(); doc.pipe( fs.createWriteStream('out.pdf') ); doc.moveTo(300, 75) .lineTo(373, 301) .lineTo(181, 161) .lineTo(419, 161) .lineTo(227, 301)

pdfkit Browser - “Uncaught ReferenceError: fs is not defined” when using custom fonts

浪子不回头ぞ 提交于 2019-12-11 17:29:12
问题 This question may be asked previously but they have no answer. I try to create a pdf file using pdfkit library with Arabic language support. So, first I downloaded a prebuilt version of pdfkit (which is assumed to work in browser) from here. Then I wrote this code for adding an Arabic font (like in the docs) const doc = new PDFDocument; var text_arabic = "مرحبا مَرْحَبًا"; // Using a TrueType font (.ttf) doc.font('./trado.ttf') // --> this line gives the error. .text(text_arabic) .moveDown(0

How to attach a node.js readable stream to a Sendgrid email?

限于喜欢 提交于 2019-12-10 20:25:59
问题 I'm using PDFKit to generate PDFs. I'm using Nodejitsu for hosting, so I can't save the PDFs to file, but I can save them to a readable stream. I'd like to attach that stream in a Sendgrid email, like so: sendgrid.send({ to: email, files: [{ filename: 'File.pdf', content: /* what to put here? */ }] /* ... */ }); I've tried doc.output() to no avail. 回答1: To use the SendGrid nodejs API with a streaming file, just convert the streaming into a buffer. You can convert a readable stream into a

PDFKit, nodeJS merging two PDF files

隐身守侯 提交于 2019-12-07 12:22:57
问题 does anyone have experience with PDFKit with NodeJS. Specifically, I'm trying to merge 2 PDF documents into 1, but I can't seem seem to get the content of the two PDFs properly with formatting inside the merged one. Here's what I do: var PDFDocument = require('pdfkit'); var fs = require('fs'); var doc = new PDFDocument(); var fileName = 'test.pdf'; doc.pipe(fs.createWriteStream(fileName)); var file1 = '1.pdf'; var file2 = '2.pdf'; var stream1 = fs.createReadStream(file1); doc.text(stream1);

PDFKit, nodeJS merging two PDF files

巧了我就是萌 提交于 2019-12-06 00:31:40
does anyone have experience with PDFKit with NodeJS. Specifically, I'm trying to merge 2 PDF documents into 1, but I can't seem seem to get the content of the two PDFs properly with formatting inside the merged one. Here's what I do: var PDFDocument = require('pdfkit'); var fs = require('fs'); var doc = new PDFDocument(); var fileName = 'test.pdf'; doc.pipe(fs.createWriteStream(fileName)); var file1 = '1.pdf'; var file2 = '2.pdf'; var stream1 = fs.createReadStream(file1); doc.text(stream1); doc.addPage(); var stream2 = fs.createReadStream(file2); doc.text(stream2); doc.end(); The output, that