jspdf

jsPDF with Cordova - Adding images

廉价感情. 提交于 2019-12-07 07:57:22
问题 I am trying to generate a PDF using the jsPDF library (https://github.com/MrRio/jsPDF) from within a mobile Cordova app. I am currently testing the app on an Android 4.0.4 device but it also needs to run on Windows mobile 8. The text in the PDF document is shown correctly however any images are scrambled. See image below I did find this page (https://coderwall.com/p/nc8hia) that seemed to indicate there is a problem with jsPDF displaying images in Cordova (see comments) but the author never

How encode in base64 a file generated with jspdf and html2canvas?

人走茶凉 提交于 2019-12-07 06:19:40
问题 i'm trying encode the document generated in the attached code, but nothing happens, not generate error but neither encodes the file, and the ajax request is never executed what is the correct way? html2canvas(document.getElementById("workAreaModel"), { onrendered: function(canvas) { var img = canvas.toDataURL("image/png"); var doc = new jsPDF("l", "pt", "letter"); doc.addImage(img, 'JPEG',20,20); var fileEncode = btoa(doc.output()); $.ajax({ url: '/model/send', data: fileEncode, dataType:

Create and download pdf from div on angular 2

感情迁移 提交于 2019-12-07 03:46:31
问题 I'm trying to create and download an PDF from an existing div with jsPDF. I have tried many ways but I can't achieve it. My last try was with @ViewChild and ElementRef but doesn't work to. detail-devis.component.ts: import {Component, ElementRef, ViewChild} from "angular2/core"; declare let jsPDF; @Component({ selector: 'my-app', template: `<div #test> Hello world </div> <button type="button" (click)="test()">pdf</button> <button (click)="download()">download</button>` }) export class App {

jsPDF - I need help embedding a pdf onto a web page

倾然丶 夕夏残阳落幕 提交于 2019-12-07 02:49:31
I'm using jsPDF to create a pdf that will be displayed on a web page but I can't seem to get it to embed correctly. The pdf does load if I put in doc.output('dataurl'); but it loads in a new window (I know that is what it's supposed to do). I made a div that uses object tags to hold the pdf and it does load a pdf file but it wont the load the jsPDF. What I'm trying to do is make an embedded pdf like the one on their main page, https://parall.ax/products/jspdf . What code would I need to add in order to get it to load in the object tags? It has to be possible since they have a working version.

jsPDF + rasterizeHTML not working?

♀尐吖头ヾ 提交于 2019-12-07 02:21:43
问题 jsPDF's addHTML requires html2canvas.js or rasterizeHTML.js . I want to use rasterizeHTML.js but it doesn't work. Couldn't find any example online. Working with html2canvas.js : html <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script> <body> <p id="to-pdf">HTML content...</p> </body> js var pdf = new jsPDF('p','pt','a4'); pdf.addHTML(document.body,function()

jsPDF fromHTML images cause the pdf to be empty

為{幸葍}努か 提交于 2019-12-06 19:15:12
问题 I'm trying to generate a pdf out of Tinymce Content, which I access with AngularJS. For This I use the from_html plugin inside jspdf. First the relevant code parts. Relevant Function & Index.ejs jspdf includes //relevant function var specialElementHandlers = { '#bypassme': function(element, renderer) { return true; } }; var margin = { top: 0, left: 0, right: 0, bottom: 0 }; var tinymceToJSPDFHTML = document.createElement("body"); tinymceToJSPDFHTML.innerHTML = $scope.selectedItem.content; var

how to replace undefined with a empty string

▼魔方 西西 提交于 2019-12-06 18:13:54
问题 I am using jsPdf. When a field has been left blank "undefined" is printed on the pdf. I would like to replace that with a empty string. I am trying to use a if statement but I am not getting it. doc.text(30, 190, "Budget : $"); if ($scope.currentItem.JobOriginalBudget == "undefined") { doc.text(50, 190, " "); } else { var y = '' + $scope.currentItem.JobOriginalBudget; doc.text(50, 190, y); }; 回答1: undefined is a primitive value. Instead of comparing against the identifier undefined , you're

jsPDF justify text

十年热恋 提交于 2019-12-06 18:06:21
问题 I'm trying to apply some changes on jsPDF library to be able to justify text. I'm having trouble to find the right value for Tw (word spacing). In jspdf.js (L:1413) I have added this code: if (align) { ... else if (align === 'justify') { left = x; } else { throw new Error('Unrecognized alignment option, use "center" or "right".'); } prevX = x; text = '(' + da[0]; let pdfPageWidth = this.internal.pageSize.width; let wordSpacing; if( align === 'justify' ) { let fontSize = this.internal

Convert a image url to pdf using jspdf

限于喜欢 提交于 2019-12-06 15:26:01
function convertImgToBase64(url) { var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); img = document.createElement('img'), img.src = url; canvas.height = img.height; canvas.width = img.width; var dataURL = canvas.toDataURL('image/jpeg') alert(dataURL); canvas = null; return dataURL; } var imageurl = 'http://qph.is.quoracdn.net/main-qimg-ca033a73e2ea858908c44905d4c25f4b?convert_to_webp=true'; var som =convertImgToBase64(imageurl); doc.addImage(som, 'JPEG', 15, 40, 180, 180); doc.output('datauristring'); but nothing happens no pdf is generated ? I am getting the

Does external css get applied to the pdfs generated by jsPDF

隐身守侯 提交于 2019-12-06 15:24:38
I have started making some demos using jspdf. I have a html file and my css is in external file. I have written the below code to generate my pdf $('#pdfButton').on('click', function(){ var pdf = new jsPDF('p','in','letter') , source = $('#main')[0] , specialElementHandlers = { '#bypassme': function(element, renderer){ return true } } pdf.fromHTML( source // HTML string or DOM elem ref. , 0.5 // x coord , 0.5 // y coord , { 'width':700 // max width of content on PDF , 'elementHandlers': specialElementHandlers } ) pdf.output('dataurl'); }); }); where main is the id of the div whose content I