jspdf

Is there any way to center text with jsPDF?

瘦欲@ 提交于 2019-12-03 04:46:07
问题 I'm trying to create a simple pdf doc using javascript. I found jsPDF but I don't figure out how to center text. Is it possible? 回答1: Yes it's possible. You could write a jsPDF plugin method to use. One quick example is this: (function(API){ API.myText = function(txt, options, x, y) { options = options ||{}; /* Use the options align property to specify desired text alignment * Param x will be ignored if desired text alignment is 'center'. * Usage of options can easily extend the function to

HTML5 canvas, convert canvas to PDF with jspdf.js

谁都会走 提交于 2019-12-03 00:16:08
I am trying to convert HTML5 canvas to PDF in JavaScript but I get a black background PDF. I tried to change the background color but still get black. The following is code I am trying: Canvas = document.getElementById("chart"); Context = Canvas.getContext("2d"); var imgData = Canvas.toDataURL('image/jpeg'); var pdf = new jsPDF('landscape'); pdf.addImage(imgData, 'JPEG', 0, 0, 1350, 750); pdf.save('download.pdf'); If you have any idea, I'd appreciate it very much. A good approach is to use combination of jspdf.js and html2canvas. I have made a jsfiddle for you. <canvas id="canvas" width="480"

Is there any way to center text with jsPDF?

牧云@^-^@ 提交于 2019-12-02 17:56:59
I'm trying to create a simple pdf doc using javascript. I found jsPDF but I don't figure out how to center text. Is it possible? Tsilis Yes it's possible. You could write a jsPDF plugin method to use. One quick example is this: (function(API){ API.myText = function(txt, options, x, y) { options = options ||{}; /* Use the options align property to specify desired text alignment * Param x will be ignored if desired text alignment is 'center'. * Usage of options can easily extend the function to apply different text * styles and sizes */ if( options.align == "center" ){ // Get current font size

How to give width, height, x and y coordinates in generating pdf from html using JSPDF new html API

若如初见. 提交于 2019-12-02 14:59:56
问题 I have been using JSPDF to generate pdf document based on some html. Earlier using jspdf fromHTML Api, we could give margins like this var margins2 = { top: 415, bottom: 10, left: 55, width: 300 }; doc.fromHTML(reactListContent, margins2.left, margins2.top, { 'width': margins2.width, 'elementHandlers': specialElementHandlers }, margins2); But, in the new .html API , how can i provide margins, width and height. The new API is like var pdf = new jsPDF('p', 'pt', 'letter'); pdf.html(document

How to send a jsPDF converted pdf file to backend server?

故事扮演 提交于 2019-12-02 09:06:49
I need to send a png file to the backend server. I converted it to pdf using jsPDF: var doc = new jsPDF('l', 'mm', [210, 210]); doc.addImage(myPngData, 'PNG', 0, 0, 210, 210); Now I need to send it to the server using my old-school JQuery project: $.post(url, { key1: val1, key2: val2, pdf: //pdf file goes here, will doc work?, }, But what should I really send? Cause sending doc just won't work? Unfortunately I cannot just send and check it as the backend is not ready yet. You can use doc.output('datauristring') and send it to your server. Below is my code to send the whole html page to the

How to give width, height, x and y coordinates in generating pdf from html using JSPDF new html API

和自甴很熟 提交于 2019-12-02 07:21:25
I have been using JSPDF to generate pdf document based on some html. Earlier using jspdf fromHTML Api, we could give margins like this var margins2 = { top: 415, bottom: 10, left: 55, width: 300 }; doc.fromHTML(reactListContent, margins2.left, margins2.top, { 'width': margins2.width, 'elementHandlers': specialElementHandlers }, margins2); But, in the new .html API , how can i provide margins, width and height. The new API is like var pdf = new jsPDF('p', 'pt', 'letter'); pdf.html(document.getElementById('html'), { callback: function (pdf) { console.log("how to get margins"); } }); If you look

Portuguese/Spanish accents with jsPDF

此生再无相见时 提交于 2019-12-02 03:49:32
问题 How can I manage to get special characters in a PDF file generated with jsPDF? The texts are dynamically loaded through AJAX. Some possible chars are à , É , Ç and õ . I, up to now, didn't get how to do this. 回答1: You must download the last version of jsPDF, there will be a file called jspdf.plugin.standard_fonts_metrics.js, just reference that script from your html page and that would be more than enough to user special caracters would be a simple line like this: <script src="jspdf.plugin

How to reduce the file size created by JSPDF?

岁酱吖の 提交于 2019-12-02 01:20:17
I'm using jspdf.js to create pdf from HTML 5 canvas. However, regardless of what the contents are and how big the canvas size is, the generated file size is always 32,874 KB, even when the canvas is completey empty. Why the file size is always the same? jsPDF version is 1.1.135. My code is like this: var imgData = canvas.toDataURL("image/jpeg", 1.0); var width = $("canvas").attr('width'); var height = $("canvas").attr('height'); var pdf = new jsPDF('p', 'pt', [width,height]); pdf.addImage(imgData, 'JPEG', 0, 0, width, height); pdf.save("download.pdf"); UPDATE: Full code: $scope.rasterizePDF =

Portuguese/Spanish accents with jsPDF

試著忘記壹切 提交于 2019-12-01 23:53:47
How can I manage to get special characters in a PDF file generated with jsPDF? The texts are dynamically loaded through AJAX. Some possible chars are à , É , Ç and õ . I, up to now, didn't get how to do this. Cesar You must download the last version of jsPDF, there will be a file called jspdf.plugin.standard_fonts_metrics.js, just reference that script from your html page and that would be more than enough to user special caracters would be a simple line like this: <script src="jspdf.plugin.standard_fonts_metrics.js"></script> <script> doc.text(74, 25, 'Evaluación de prueba'); </script> This

jsPDF add chart

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 21:43:13
I am using jsPDF to generate PDF documents through Appcelerator's Titanium. Now i need to add a simple pie chart with two segments. How could i do that in simplest way? It doesn't need to be anything fancy. I am thinking about generating an image first, and add that image to the document. Maybe there's a library that could generate images of pie-chart's and save it to the phone. However, im not sure about jsPDF's support of images, i can't seem to find any good documentation of the library. arsenalist I know it has been inactive for almost a year, but since it doesn't have an accepted answer,