API Pdf Lib
PDF API HTML5 Web Apps
A condensed library designed to web modern applications, to quickly export your content html to pdf thanks the famous library in javascript: jsPDF. And a special thanks to the project canvg and html2canvas
Features library - Demo
-
HTML document PDF
HTML PDF - HTML to IMGLorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam sodales urna non odio egestas tempor. Nunc vel vehicula ante.
-
iFrame to PDF Document
IFRAME PDF - -
Convert form to PDF
FORM PDF - -
Export Image PDF
IMAGE PDF - -
IMAGE Converter
IMAGE - Export PNGYou can to export in png, jpg, tiff, bmp and webp
-
Export Canvas PDF
CAVAS PDF - -
Canvas to Image
CANVAS IMG - Export PNGYou can to export in png, jpg, tiff, bmp and webp
-
Export SVG
SVG PDF - Export PNGA special thanks to the project canvg for the realization of this function
-
Simple Text to PDF
Text PDF -Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum
-
PDF Viewer/Reader
Drag&Drop PDFSee in action PDF Viewer with an useful web app - click here
Doc - Examples
-
/** * File JavaScript - Example application interface * **/ /** * Examples to export * canvas, image and svg * to Cloud Print **/ // canvas to Cloud Print as PNG function canvcp() { var canvMain = document.getElementById('canvasimage'), title = 'Canvas-to-CloudPrint'; var ctx = canvMain.getContext('2d'), dataUrl = canvMain.toDataURL(); var imageData = dataUrl.split('data:image/png;base64,').join(''); pdfapihtml5.printbase64gcp(title, imageData); } // image to Cloud Print as PNG function imgcp() { var canvas = document.createElement("canvas"); var ctx = canvas.getContext('2d'); var image = document.getElementById('imagetoimg'); canvas.width = image.naturalWidth; canvas.height = image.naturalHeight; ctx.drawImage(image, 0, 0); var title = 'Image-to-CloudPrint', dataUrl = canvas.toDataURL(); var imageData = dataUrl.split('data:image/png;base64,').join(''); pdfapihtml5.printbase64gcp(title, imageData); } // SVG to Cloud Print as PDF function svgcp() { pdfapihtml5.printxtgcp("SVG_CP", document.getElementById("svgexport").outerHTML); } // SVG to Cloud Print as PNG format function svgcpng(){ var canvas = document.createElement('canvas'); var ctx = canvas.getContext('2d'); var svg = document.getElementById('svgexport'); var strxml = svg.outerHTML; canvg(canvas, strxml); var dataUrl = canvas.toDataURL(); var title = 'SVG-to-CloudPrint-as-PNG'; var imageData = dataUrl.split('data:image/png;base64,').join(''); pdfapihtml5.printbase64gcp(title, imageData); } // Iframe to Cloud Print as PDF format function iframecp(){ var frame = document.getElementById('iframe').contentWindow.document.body.outerHTML; pdfapihtml5.printxtgcp('iframe_cp', frame); } /** * Example function to convert * html to pdf **/ function convertHtmlToPdf(){ // Setting margins var mtop = 20, mbottom = 20, mleft = 20, w = 595.28; // Select id of element var outputpdf = 'lorem'; pdfapihtml5.fnhtmlPdf(outputpdf, mtop, mbottom, mleft, w); }; /** * Example function to use Google Cloud Print Api to * print web page with yours printers or to save PDF in * Google Drive **/ function printJob(){ pdfapihtml5.printgcp("mywebsite", "http://mediamaster.eu") } /** * Example function to use Google Cloud Print Api to * print html or text content node with yours printers or to save PDF in * Google Drive **/ function printTxtcp(){ pdfapihtml5.printxtgcp("mywebsite", document.getElementById("printsimpletxt").innerHTML); } /** * Example function to convert * iframe to pdf **/ function iframepdf(){ // Setting margins var mtop = 20, mbottom = 20, mleft = 20, w = 595.28; // Select id of element var outputpdf = 'iframe'; pdfapihtml5.iframePdf(outputpdf, mtop, mbottom, mleft, w); }; /** * Example function to convert * html to pdf in format img **/ function htmlpdfimg(){ var imghtml = 'lorem'; var orientation = "p"; var unitmeasure = "mm"; var q1 = 297; var q2 = 210; var m1 = 5; var m2 = 5; pdfapihtml5.HTMLPDFimg(imghtml, orientation, unitmeasure, q1, q2, m1, m2); }; /** * Example function to convert * form to pdf **/ function saveform() { var titleform = "Example form"; // Get informations form - example var getname = document.forms.profile.name.value; var getsurname = document.forms.profile.surname.value; var getaddress = document.forms.profile.address.value; var getcomments = document.forms.profile.comments.value; // Settings sheet and fonts var fontform = "helvetica"; var fontstyle = "bold"; var orientation = 'p'; var unitmeasure = 'mm'; var fontsize = 12; var q1 = 297; var q2 = 210; // Add variables to print in pdf var callfn = pdfapihtml5.sumvalues("Name: " + getname, "\n" + "Surname: " + getsurname, "\n" + "Address: " + getaddress, "\n" + "Comments: " + getcomments); pdfapihtml5.fnformpdf(callfn, titleform, fontform, fontstyle, fontsize, orientation, unitmeasure, q1, q2); }; /** * Example function to convert * image to pdf **/ function exportimage() { // Select id of element var img = 'imagex'; // Settings sheet var orientation = "p"; var unitmeasure = "mm"; var q1 = 297; var q2 = 210; var m1 = 5; var m2 = 5; pdfapihtml5.saveimagePdf(img, orientation, unitmeasure, q1, q2, m1, m2); }; /** * Example function to convert * canvas to pdf **/ function exportcanvas() { // Select id of element var canvas = 'canvasexample'; var orientation = "p"; var unitmeasure = "mm"; // Settings sheet var q1 = 297; var q2 = 210; var m1 = 5; var m2 = 5; pdfapihtml5.savecanvasPdf(canvas, orientation, unitmeasure, q1, q2, m1, m2); }; /** * Example function to convert * svg to pdf **/ function exportsvg() { // Select id of element var svg = 'svgexport'; var orientation = "p"; var unitmeasure = "mm"; // Settings sheet var q1 = 297; var q2 = 210; var m1 = 5; var m2 = 5; pdfapihtml5.savesvgPdf(svg, orientation, unitmeasure, q1, q2, m1, m2); }; /** * Example function to convert * simple text to pdf **/ function txtpdf() { // Settings properties pdf var titledoc = "Example", subjectdoc = "Example subject", authordoc = "Author Example", keywordsdoc = "simple, pdf, doc, pdf, example, library, pdf, android, hybridapps"; var creatordoc = "me"; // Get content and, if you want, more items var getcontent = document.getElementById("getext").textContent; var getcontent2 = document.getElementById("getext2").textContent; var textcontent = pdfapihtml5.sumvalues(getcontent, getcontent2); // Settings sheet and fonts var font = "helvetica"; var fontype = "bold"; var fontsize = 12 var orientation = 'p'; var unitmeasure = 'mm'; var q1 = 210; var q2 = 297; var wrapText = 180; pdfapihtml5.fntxtpdf(titledoc, subjectdoc, authordoc, keywordsdoc, creatordoc, textcontent, font, fontype, fontsize, orientation, unitmeasure, q1, q2, wrapText); }; /** * Example function to save * image in external storage * of the device mobile **/ function convimage() { // Get id image then set link and extension var img = "imagetoimg", ext = "png", link = document.getElementById("eximage"); pdfapihtml5.imageConverter(img, link, ext); }; /** * Example function to convert html to img and save * **/ function convhtmlimg(){ // Get id html then set link and extension var htmlcont = "lorem", link = document.getElementById("htmlimg"), ext = "png"; pdfapihtml5.exportHTMLImg(htmlcont, link, ext); }; /** * Example function to convert * canvas to image **/ function ctoimg(){ // Select id image then set link and extension var c = "canvasimage", link = document.getElementById("imgcanvas"), ext = "png"; pdfapihtml5.canvastoImg(c, link, ext); }; /** * Example function to convert * svg to image **/ function stoimg() { // Select id svg then set link and extension var s = "svgexport", link = document.getElementById("svgimg"), ext = "png"; pdfapihtml5.svgImg(s, link, ext); }; /** * Example function pdf reader * pdf reader **/ function pdfReader(){ var pdfviewer = document.getElementById("getpdf"); pdfapihtml5.dragdropPDF(pdfviewer); pdfapihtml5.styleDropzone(pdfviewer); pdfapihtml5.pdfFilesystem(pdfviewer); }