Generate a PDF Report from Forge Viewer

May 1, 2018

Here is a quick way to generate a PDF report of the LMV canvas through the browser.
It uses the [jsPDF](https://parall.ax/products/jspdf) library.

DEMO  https://wallabyway.github.io/forge-pdf-report/

Result:  Floor1-report.PDF

How to use:

Steps:

1. Add this to your `index.html` ...

<script src="https://unpkg.com/jspdf/dist/jspdf.min.js"></script>

 
2. Take a screenshot of LMV canvas using `getScreenShotBuffer()`, like this ...

viewer.getScreenShotBuffer(
 viewer.canvas.width,
 viewer.canvas.height, 
 img => createPDF(img)); 
});

        

3. Then add the PNG into a new PDF using jsPDF, like this...

 

function createPDF(imgData) {
    var doc = new jsPDF()
    doc.setFontSize(40)
    doc.text(35, 25, 'ForgeViewer PDF report');
    doc.addImage(imgData, 'JPEG', 10, 40, 180, 80);
    doc.save('report-floor1.pdf')
}

All done !

You can find a complete example on GitHub here: https://github.com/wallabyway/forge-pdf-report

Feel free to add any issues you find to the Github issues repo.

Follow me on Twitter @micbeale

Posts by author

Michael Beale
Autodesk

Michael Beale works for Autodesk Cloud Rendering team and focuses on client/server mashups that make the web-browser appear super-powered.