Generate PDF thumbnails using JavaScript
In addition to rendering PDFs in the viewer, you can use Nutrient Web SDK to render single PDF pages as images. This is useful when you want to display a thumbnail of a single PDF page, for example.
Saving a page as an image
Nutrient Web SDK’s renderPageAsImageURL method renders the page as an image and returns a URL you can use to fetch that image’s contents:
try { const instance = await NutrientViewer.load(myConfiguration); const src = await instance.renderPageAsImageURL({ width: 400 }, 0);} catch (error) { console.error("Failed to load document:", error.message);}To increase the quality of the resulting image, you can provide a greater width value — e.g. 400 * window.devicePixelRatio.
After this, you can save a single page as a PNG file to your users’ computers using the FileSaver.js(opens in a new tab) library:
npm install file-saverimport { saveAs } from "file-saver";
try { const instance = await NutrientViewer.load(myConfiguration);
// Renders the first page (page index 0). const src = await instance.renderPageAsImageURL({ width: 2000 }, 0); saveAs(src, "pdf-page.png");} catch (error) { console.error("Failed to load document:", error.message);}