May 1, 2018

Generate a PDF Report from Forge Viewer

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

Related Posts

July 11, 2019

New Autodesk Forge Viewer 7.0 is Now Available

Autodesk Forge is our collection of Application Program Interfaces (APIs), documentation, sample code, and a community of cust

Read More

July 10, 2019

Look for exact property value and more

When using the search() function of the Viewer, you can only look for strings that at least partially match a given value.

Read More

July 9, 2019

Webpack and three.js in forge applications

In the newer versions of forge viewers( v6 and above) three.js is included in the forge viwer js file itself.

Read More