bpampuch / pdfmake Goto Github PK
View Code? Open in Web Editor NEWClient/server side PDF printing in pure JavaScript
Home Page: http://pdfmake.org
License: Other
Client/server side PDF printing in pure JavaScript
Home Page: http://pdfmake.org
License: Other
Hi, I've test your library in different navigators :
I can't seem to find this.
I have a requirement for a PDF builder that can handle many rows (several thousand hopefully). pdfmake looks great, but seems to crash Chrome after about ~1500 rows maximum. Any chance that this is something the library could handle in the future?
I've tried a different server side utility that has similar problems after 3-4000 rows, but I like the idea of a javascript utility that relies on local resources rather than server resources.
Hi,
First of its an excellent library and very easy to use.
I tried to use this locally in a sample html file and it worked like a charm without any problems. After that I tried to include this in one of my projects (SharePoint site) and here when I try to create the pdf document I get the error "No unicode cmap for font". I haven't changed anything WRT fonts. Can you give me some idea on what could be the reason for this. And what other things could cause this to fail.
Any help or insight will be really helpful. I just need to generate this PDF document with one image and few tables and a header.
Thanks in advance.
Regards,
Guru
There is a function called registerDefaultTableLayouts
that provides default table layouts called headerLineOnly
and lightHorizontalLines
. The border header for is very thick: in a pixel world, I would say they are 2px high.
It might be nice if these default options were updated to have: headerLineOnlyThin
, headerLineOnlyThick
, lightHorizontalLinesThinHeader
, lightHorizontalLinesThickHeader
.
hLineWidth: function (i, node) {
if (i === 0 || i === node.table.body.length) return 0;
return (i === node.table.headerRows) ? 1 : 1;
},
Perhaps these are too verbose, and maybe this is overkill, but I think you can understand why it may not always be desirable to have a "thick" header row border.
Hi Bartosz,
First i'd like to say, that I really love your work with pdfmake. It's really great and many thanks to You.
I'm trying to use pdfmake with Google Web Toolkit and found some strange behaviour.
This is the piece of code that works in playground:
var a = { text: "This is first line"}
var b = { text: "This is the second"}
var dd = {
content: [a, b]
}
When I'm trying to use it in GWT:
public static native void pdfmake2()
/*-{
var a = { text: "This is first line"}
var b = { text: "This is the second"}
var dd = {
content: [a, b]
}
$wnd.pdfMake.createPdf(dd).download();
}-*/;
it generates error:
Exception caught: (String) @willma.net.pl.testPDF.client.TestPDF::pdfmake2()([]): Unrecognized document structure: [{"text":"This is first line"},{"text":"This is the second"}]
I've found, that doing it this way works:
public static native void pdfmake1()
/*-{
function buildContent(){
var stack = []
stack.push({ text: "This is first line"})
stack.push({ text: "This is the second"})
return{
stack: stack
}
}
var dd = {
content: buildContent()
}
$wnd.pdfMake.createPdf(dd).download();
}-*/;
Strange, isn't it ?
Problem with my solution is, that when stack becomes larger, pdfmake does not breake it into pages.
Any ideas how should i deal with it in GWT ?
i have a variable which has value like this IW‐B‐(L)
. After pdfMake generate pdf, the value become like this IW B (L)
I looked through the repository and found the vectors example. This is nice but appears to only access the fixed shape helpers. I would like to draw a fractional pie chart as part of a report being generated w/ your library. Is there a way to accomplish this? Perhaps direct access to the pdfDoc library for drawing the shape? Maybe using your table drawing routines to draft the document and then updating the file w/ the pie chart using PDFKit? Thoughts?
Is it possible to add a logo(image) to the page header
I looked around the source and the examples but I couldn't really figure out how to add a page break in the document. I will appreciate to document it here if it is implemented. Thanks.
I've been playing w/ the renderVector method to allow me to add SVG path objects to my pdf reports. However, I am very new to the javascript world and grunt in particular. Your gruntfile.js doesn't seem to build the pdfmake.js file from the src/* files. When I edit the src/printer.js to edit the case stmt in renderVector, the edits don't show up when I run the grunt build. Can you help me understand what I am missing? If I can get this cut in, I would love to contribute back to your repository so that path objects are included.
One thing that would enable more scaling client-side scenarios would be if pdfMake can run in a web worker compatible mode. One thing I'm seeing with more complex PDFs in IE and Firefox is script time outs, which probably is to be expected if most of the logic runs on the UI thread.
Trying to use from a web worker just to see how many dependencies on window DOM, initially get errors in sections of pdfmake.js using the window.navigator object.
in pdfWebWorker.js importScripts fails. Thinking it might be possible to put shim components before invoking importScripts in the web worker....or fork and create custom build of pdfmake...
importScripts("pdfmake.js", "vfs_fonts.js");
(Thought maybe it had a chance if the same source code was managing to run on node.js there couldn't be that many dependencies on DOM.)
Great tool so far. Thanks.
Perhaps it would be worth noting in the documentation how the "text" value has to be converted to a a string if the value is not a string?
The reason I raise the issue is because I had a variable whose value was an integer. When I had the variable in the output as text: myVar
, where myVar
was a number, no output was generated. But when I had text: myVar.toString()
, the integer was converted to a string, and then was generated as output in the pdf.
when I load the minimized version in chrome, throws error Unexpected token ILLEGAL
All of the examples provided for pdfmake use inline text; in other words, static data.
But I cannot imagine too many people working with documents in such a manner.
When working with tables, for instance, someone is likely to be working with JSON data obtained from the server.
Is pdfmake supposed to handle such scenarios, and if so, can a generic example be provided?
I am running into unexpected oddities as I try this out. In some attempts, I get a
TypeError: Cannot read property '_calcWidth' of undefined
. You can generate the problem as well by trying to use variables for multiple table rows in the playground.
Unless there is a way to have dynamic row data for tables, this is a showstopper for me.
Is there any?
Hello!
I want to start a new page because I'm workin with dynamic datas.
Is it possible?
Thanks
I try to use pdfmake with node-webkit but unless i just do
var docDefinition = { content: 'First paragraph'};
I always get "Unrecognized document structure" error:
Uncaught Unrecognized document structure: ["First paragraph","Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines"] /Users/alex/flyvekt/node_modules/pdfMake/src/docMeasure.js:63
(anonymous function) ....node_modules/pdfMake/src/docMeasure.js:63
StyleContextStack.auto ....node_modules/pdfMake/src/styleContextStack.js:122
DocMeasure.measureNode ....node_modules/pdfMake/src/docMeasure.js:42
DocMeasure.measureDocument ..../node_modules/pdfMake/src/docMeasure.js:29
LayoutBuilder.layoutDocument ....node_modules/pdfMake/src/layoutBuilder.js:48
PdfPrinter.createPdfKitDocument ....node_modules/pdfMake/src/printer.js:98
(anonymous function) test.html:25
code for test.html:
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript" charset="utf-8">
var fonts = {
Roboto: {
normal: 'fonts/Roboto-Regular.ttf',
bold: 'fonts/Roboto-Medium.ttf',
italics: 'fonts/Roboto-Italic.ttf',
bolditalics: 'fonts/Roboto-Italic.ttf'
}
};
var PdfPrinter = require('pdfMake');
var printer = new PdfPrinter(fonts);
var fs = require('fs');
var docDefinition = {
content: [
'First paragraph',
'Another paragraph, this time a little bit longer to make sure, this line will be divided into at least two lines'
]
};
var pdfDoc = printer.createPdfKitDocument(docDefinition);
pdfDoc.pipe(fs.createWriteStream('./pdfs/basics.pdf'));
pdfDoc.end();
</script>
</head>
<body>
</body>
</html>
please some of the pdfs generated by the pdfmake are not printable by printers. Some of the documents when printed would print characters such as "!#&@$" . Some printers would error out "49.4C02". Please excuse me if I have not given enough details, but can you suggest how we can get around printer issues, and, is there a way to generate image instead of pdf.
Your help is really appreciated
I stumbled upon this error when trying to include the colSpan
.
[{ text: 'header ', colSpan: 3, style: 'header', alignment: 'center' }],
Is it currently possible to overlay a vector over another element (image in my case)? The documentation around vectors is pretty sparse and I'm having trouble determining if this is possible by going over the code.
hi bpampuch,
Terrific work with pdfmake, congratz.., can u please look into adding background images to pages, and also column background color.?
It would be awseome if the framework could render horizontal and/or vertical lines (configurable of course) around table cells.
It would be nice if one could declaratively define a desired page size. The docuement definition object now supports this syntax:
var dd = {
content: someContentObject,
pageSize: {
width: pageWidth,
height: pageHeight
}
};
I'd like to be able to define it like that:
var dd = {
content: someContentObject,
pageSize: 'A4' // A3, A5 or other standard page sizes
};
Is it possible to have more than 2 lines in the page header
First of all, thank you for this great tool!
It's not an issue but a request (I don't know where to put it so sorry if it's not the right place).
It would be amazing to have an odt or docx to PDF conversion! Do you think it's possible and realistic in the 'not too' long term?
It seems that the vfs_fonts.js file contains the binary font data of the Roboto font but somehow encoded (data URI / base64 ?).
could you explain how to generate the required JS file for other fonts (and: is the LICENSE.txt required ?)
btw: great work - thanks, seems quite promising !
kind regards,
matthias
Hello.
I'm working on a solution for getting the pdf generated to be saved on the server.
I have pdmake working on client side with angularjs. On the backend I hava nodejs and express.
My intention is to send an email with the pdf attached to it.
Any ideas for having this working?
Thanks... and really good work with pdfmake!
New feature request: would it be possible to use color background as well as text.
A good feature would be the ability to insert a horizontal line as a separator on this content from the rest of the document. This line can be modife.
This line could be modified by specifying the width(i.e. in %) of the page in the document.
:)
As the title says, pdfmake does not work when Firefox is set to open PDF files by default. If you change the default file association for opening PDF files, it works properly again. This could be a problem in uncontrolled environments, as one simply can't enforce every user to change that file association.
If i enter a text with some tabultors (e.g. 'some\t\ttext'
) in document definition the words will overlap.
It would be nice to be able to work with an equivalent of an <hr />
element that has hooks for styling. I can do a workaround by having a table with empty text cells ' '
and a fontSize of 0, but this approach is just a hack.
I have try to follow this: #8. But the data is overflow of the page.
I have set the page to pageMargins: [40, 100, 40, 50]
and page orientation to landscape. How do I set the margin of bottom page
I'm really fighting with your missing documentation. I try to run the images.js
-example, but it will give me the following error:
Fabios-MacBook-Pro:examples fabiopoloni$ node images.js
/Users/fabiopoloni/Desktop/pdfmake/src/imageMeasure.js:11
image = pdfKit.PDFImage.open(src);
^
TypeError: Cannot call method 'open' of undefined
at ImageMeasure.measureImage (/Users/fabiopoloni/Desktop/pdfmake/src/imageMeasure.js:11:27)
at DocMeasure.measureImage (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:107:36)
at /Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:57:30
at StyleContextStack.auto (/Users/fabiopoloni/Desktop/pdfmake/src/styleContextStack.js:122:15)
at DocMeasure.measureNode (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:40:25)
at DocMeasure.measureVerticalContainer (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:139:19)
at /Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:47:30
at StyleContextStack.auto (/Users/fabiopoloni/Desktop/pdfmake/src/styleContextStack.js:122:15)
at DocMeasure.measureNode (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:40:25)
at DocMeasure.measureDocument (/Users/fabiopoloni/Desktop/pdfmake/src/docMeasure.js:27:14)
I already tried downgrading pdfkit
to version 0.2.7 which is declared in package.json
but it won't work. Where's the problem?
Hello,
I make a website based on node.js. I give ability to users to download server-side generated pdf. If I put an image in header, first document generated is ok, but when I try to generate another one I got an exception (I do not have it if there is only text in header but I'd rather put a brand logo here) :
Error: ENOENT, no such file or directory '$$pdfmake$$1'
at Object.fs.openSync (fs.js:432:18)
at Object.fs.readFileSync (fs.js:289:15)
at Function.PDFImage.open (/Volumes/Dev/www/chat-poc/node_modules/pdfmake/node_modules/pdfmake-pdfkit/js/image.js:27:19)
at ImageMeasure.measureImage (/Volumes/Dev/www/chat-poc/node_modules/pdfmake/src/imageMeasure.js:14:27)
at DocMeasure.measureImage (/Volumes/Dev/www/chat-poc/node_modules/pdfmake/src/docMeasure.js:121:36)
at /Volumes/Dev/www/chat-poc/node_modules/pdfmake/src/docMeasure.js:59:30
at StyleContextStack.auto (/Volumes/Dev/www/chat-poc/node_modules/pdfmake/src/styleContextStack.js:122:15)
at DocMeasure.measureNode (/Volumes/Dev/www/chat-poc/node_modules/pdfmake/src/docMeasure.js:42:25)
at DocMeasure.measureColumns (/Volumes/Dev/www/chat-poc/node_modules/pdfmake/src/docMeasure.js:230:21)
at /Volumes/Dev/www/chat-poc/node_modules/pdfmake/src/docMeasure.js:47:30
I try to require pdfmake locally in the function which generate pdf, but this didn't help.
Is it possible to assign background color to a table cell?
thanks, library is awesome
I have a document that uses a lot of superscripted numbers (verse markings for scripture text). If it isn't possible, I could make them smaller and italicized, but the ability to make them superscript would be great.
As in the topic, I want to know if there is a possibility of adding a header/footer on each page?
Is it possible to in the same paragraph put a link to some url, for example:
'Lorem ipsum http://www.google.com some more text'
and google be a link to the page in some other colour?
Hi.
I'm trying to get pdfmake working with Angularjs, but when I try to use the minified version it is not working.
With createPdf(dd).open() is not working (No error message)
With createPdf(dd).print() I have this error message:
Error: No unicode cmap for font
at a.registerTTF (pdfmake.min.js:3:10521)
at new a (pdfmake.min.js:3:8885)
at d.b.exports.font (pdfmake.min.js:5:506)
at n.provideFont (pdfmake.min.js:7:5740)
at pdfmake.min.js:7:13190
at Array.forEach (native)
at i (pdfmake.min.js:7:13048)
at c.buildInlines (pdfmake.min.js:7:13653)
at c.measureLeaf (pdfmake.min.js:6:13905)
at build/pdfmake.min.js:6:13070
With no-minified version is working fine.
So if the print() or download() methods only work with Chrome. How do I use modernizr to test if these features are supported in the current browser?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.