Created
March 29, 2017 15:37
-
-
Save davidjgraph/9cbd386d63ed6289fec017f016c728d3 to your computer and use it in GitHub Desktop.
test code for jspdf.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Exports the graph to a PDF and displays it in a new tab via data URL | |
function exportPdf(graph) | |
{ | |
// Prepare document | |
var pdfCanvas = new jsPDF(); | |
pdfCanvas.scale(1 / graph.pageScale); | |
// Render graph | |
var imgExport = new mxImageExport(); | |
imgExport.includeOverlays = true; | |
imgExport.drawState(graph.getView().getState(graph.model.root), pdfCanvas); | |
// Display result | |
// Optional - set properties on the document | |
pdfCanvas.setProperties( | |
{ | |
title : 'Title', | |
subject : 'This is the subject', | |
author : 'John Doe', | |
keywords : 'images, gradients, opacity, vertical text', | |
creator : 'mxGraph' | |
}); | |
// Asynchronous handling of output (required for images) requires | |
// the window to be opened in the event handling code so that it | |
// is not getting blocked and displayed as a tab (not a window). | |
var wnd = window.open('about:blank'); | |
pdfCanvas.finish(function() | |
{ | |
var pdf = pdfCanvas.output(); | |
wnd.location.href = 'data:application/pdf;base64,' | |
+ Base64.encode(pdf, true); | |
// Save via Flash or Servlet (if binary transmission may | |
// be used then the binary data can be sent "as-is") | |
// mxUtils.submit('SaveServlet', 'pdf=' + data); | |
// mxLog.show(); | |
// mxLog.debug(pdf); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment