Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Print Diagram (Read 2607 times)
swapnil
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 9
Location: pune
Joined: Sep 14th, 2018
Print Diagram
Jan 22nd, 2020 at 7:08am
Print Post  
Hello Team,

Is there any API in Mindfusion diagrams in JavaScript to print the diagram in PDF?

Regards,
Swapnil Thosar
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: Print Diagram
Reply #1 - Jan 22nd, 2020 at 9:28am
Print Post  
Hi,

We have PdfExporter class in our Java and .NET libraries, you could use it on server side if running these platforms on the server.

Other than that you could add the diagram as bitmap to a PDF page as shown here -
https://stackoverflow.com/questions/23681325/convert-canvas-to-pdf

I've also played a bit with canvas2pdf library from second SO answer to export as vector graphics (the apply and lineWidth things are to work around some unimplemented method exceptions) -

Code
Select All
//Create a new PDF canvas context.
var pdfContext = new canvas2pdf.PdfContext(blobStream());
pdfContext.doc.lineWidth = function () { return 1; }

var canvasContext = diagram.context;
pdfContext.transform = { apply: function() {} };
diagram.context = pdfContext;
diagram.repaint();
diagram.context = canvasContext;

//convert your PDF to a Blob and save to file
ctx.stream.on('finish', function ()
{
	var blob = ctx.stream.toBlob('application/pdf');
	saveAs(blob, 'example.pdf', true);
});
ctx.end(); 



but then it crashes on some code for embedding font files into the PDF, maybe you could get that to run if you set up the font files along with you project.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint