WebSave as Image is a JavaScript integration for adding an image download button to a website. When a visitor clicks the button, PDFCrowd creates an image from the webpage, using either its URL or the current page HTML.
Use this starter code to add the WebSave button.
The starter code includes PDFCrowd's demo key for testing. If you are signed in and have a WebSave key, the example uses your selected key instead. See key setup.
Paste this block where the Save as Image button should appear.
<!-- Button shown on your page --> <button class="pdfcrowd-websave pdfcrowd-websave-style" data-key="demo" data-config="webSaveConfig"> Save as Image </button> <!-- Required image settings --> <script> window.webSaveConfig = { apiSettings: { output_format: 'png' } }; </script> <!-- Load WebSave once, after the button and configuration --> <script src="https://edge.pdfcrowd.com/websave/1.4.2/websave.min.js" async></script>
pdfcrowd-websave enables WebSave on the button.pdfcrowd-websave-style adds default styling, icon, and spinner.data-config points to window.webSaveConfig.The starter code uses URL mode. Both modes work for public pages; use content mode when you need the visitor's current page content.
| Scenario | URL Mode (default) | Content Mode |
|---|---|---|
| Best for | Public pages | Forms, charts, and application results already loaded in the browser |
| How it works | PDFCrowd fetches the page URL | Browser sends current page HTML |
| Behind login | Does not share the visitor's login session | Sends the HTML already loaded in the browser; protected assets may need extra handling |
| Form values, user input | Visitor's current input is not sent | Includes current form values and selections |
See Data security for how PDFCrowd handles page content in both modes.
Set conversionMode: "content" in your
JavaScript configuration:
<!-- Button with content mode configuration --> <button class="pdfcrowd-websave pdfcrowd-websave-style" data-key="demo" data-config="webSaveConfig"> Save as Image </button> <script> window.webSaveConfig = { // Enable content mode to capture current DOM state conversionMode: "content", apiSettings: { output_format: 'png', } }; </script> <script src="https://edge.pdfcrowd.com/websave/1.4.2/websave.min.js" async></script>
Content mode captures the current page, including form values and visible canvas graphics. Load the content you want to include before conversion. PDFCrowd renders this captured content to create the output.
If the DOM is ready when the WebSave script runs, it initializes existing
buttons immediately. Otherwise, it waits for DOMContentLoaded.
For buttons added after this automatic initialization, call
WebSave.initButton() once the button is in the DOM:
This applies to React, Vue, Angular, Svelte, and other apps that create DOM elements after the initial page load.
Use these optional recipes when you need customization or advanced behavior.
Set the filename and image format and dimensions in your button's configuration.
WebSave options such as fileName and fileAction go at
the top level of the configuration object. Put conversion options inside
apiSettings.
<button class="pdfcrowd-websave pdfcrowd-websave-style" data-key="demo" data-config="webSaveConfig"> Save as Image </button> <script> window.webSaveConfig = { fileName: 'screenshot.jpg', fileAction: 'download', icon: 'image1', apiSettings: { output_format: 'jpg', screenshot_width: 1600 } }; </script> <script src="https://edge.pdfcrowd.com/websave/1.4.2/websave.min.js" async></script>
Common settings:
| Purpose | Settings |
|---|---|
| Output filename | fileName |
| Download or open the file | fileAction |
| Image format | output_format |
| Image dimensions |
screenshot_width,
screenshot_height
|
| Scaling | scale_factor |
For all available options, see the WebSave reference and the image conversion reference.
Use the Playground configuration tool to adjust format, dimensions, scaling, and other settings, then generate ready-to-use WebSave code. Best used on desktop.
Change the text inside the <button> element to set its label.
Use icon,
iconPosition,
and spinner
at the top level of the configuration object to adjust the built-in appearance.
To use your site's button styling, remove pdfcrowd-websave-style
and add your own CSS class. Keep pdfcrowd-websave so WebSave
recognizes the button.
Use custom_css
to hide navigation, sidebars, or other elements in the generated
image.
These styles apply only during conversion.
Replace .site-nav and .sidebar in this example
with CSS selectors for the elements on your page.
<button class="pdfcrowd-websave pdfcrowd-websave-style" data-key="demo" data-config="webSaveConfig"> Save as Image </button> <script> window.webSaveConfig = { icon: 'image1', apiSettings: { output_format: 'png', custom_css: ` .site-nav, .sidebar { display: none !important; } ` } }; </script> <script src="https://edge.pdfcrowd.com/websave/1.4.2/websave.min.js" async></script>
Other ways to choose what appears:
| Purpose | Approach |
|---|---|
| Use your print stylesheet |
Set use_print_media
to true to apply your site's @media print rules.
|
| Exclude selected elements | Add the pdfcrowd-remove class to those elements in your HTML. |
| Save only part of a page |
Set element_to_convert
to a selector such as #result.
Use element_to_convert_mode
with 'remove-siblings' to keep the element's ancestors
for CSS matching.
|
For content updated in the browser, use Content Mode. Element selection changes the output; Content Mode still sends the page HTML for conversion.
For advanced changes, custom_javascript
can modify content before rendering. In URL Mode,
onBeforeConversion
can select a print URL provided by your site.
Add callbacks to your configuration to update your page, record analytics, or handle the generated file yourself.
| Callback | Purpose |
|---|---|
onBeforeConversion |
Adjust settings before conversion, or return true to cancel it. |
onFileCreated |
Use the generated file or record a successful conversion. Return true to skip the default download or open action. |
onError |
Log an error or show your own message. Return true to hide the default error dialog. |
Return false or omit the return value to keep WebSave's normal
behavior. This example displays a message when the
image is ready and lets
WebSave download it.
<button class="pdfcrowd-websave pdfcrowd-websave-style" data-key="demo" data-config="webSaveConfig"> Save as Image </button> <p id="save-status" role="status"></p> <script> window.webSaveConfig = { icon: 'image1', onFileCreated: function() { document.getElementById('save-status').textContent = 'Your image is ready.'; return false; // Continue with the download. }, apiSettings: { output_format: 'png' } }; </script> <script src="https://edge.pdfcrowd.com/websave/1.4.2/websave.min.js" async></script>
For a custom error message, see Custom Error Handling.
With an active trial or paid license, you can create a WebSave key for your website. Each key is tied to the domain or subdomain you specify.
data-key attribute to that key.With Include subdomains enabled, the same key also works on subdomains of the site you enter.
See Authentication and API Keys for account setup and domain scope details.
WebSave shows an error dialog if a conversion fails after any automatic retries. Custom error handling is optional.
pdfcrowd-websave-style class during
conversion and re-enables them afterwards.
Use the onError
callback to display your own message. This example shows an inline message,
logs diagnostic details to the browser console, and clears the message when
a new conversion starts. Return true to suppress WebSave's
default error dialog.
<button class="pdfcrowd-websave pdfcrowd-websave-style" data-key="demo" data-config="webSaveConfig"> Save as Image </button> <p id="save-error" role="alert"></p> <script> const errorElement = document.getElementById('save-error'); window.webSaveConfig = { icon: 'image1', onBeforeConversion: function() { errorElement.textContent = ''; }, onError: function(message, status) { console.error('WebSave error:', message, status); errorElement.textContent = 'Unable to create the image. Please try again.'; return true; // Suppress the default error dialog. }, apiSettings: { output_format: 'png' } }; </script> <script src="https://edge.pdfcrowd.com/websave/1.4.2/websave.min.js" async></script>
For detailed error code information, see the Status Codes Reference.
This guide helps you diagnose and resolve common WebSave integration issues. For automatic error recovery and customization options, see the Error Handling section above.
pdfcrowd-websavedata-key attribute contains your WebSave keyexample.com works on www.example.com only when "Include subdomains" is enabledwww.example.com with "Include subdomains" covers deeper subdomains such as app.www.example.com, not sibling sites such as dev.example.com
WebSave key scope follows the exact site entered when the key is created.
A key for example.com with "Include subdomains"
works on www.example.com and dev.example.com. A key
for www.example.com works on www.example.com and,
with "Include subdomains", on deeper subdomains such as
app.www.example.com. It does not work on sibling sites such as
dev.example.com.
In URL mode, WebSave normally converts the current page URL. If your
JavaScript changes the URL to be converted, the browser same-origin check
still uses exact host matching. example.com and
www.example.com are different origins, even if the WebSave key
includes subdomains. Use content mode when you need to convert the current
browser page state.
WebSave cannot access localhost URLs as conversions happen on PDFCrowd servers. Use ngrok or localtunnel to create a temporary public HTTPS URL for your local development server.
Use content mode to include content from the visitor's logged-in session or current form values.
For content already loaded in the browser, use content mode. In URL mode, add javascript_delay to allow time for page scripts to finish:
window.webSaveConfig = { apiSettings: { javascript_delay: 2000, // Wait 2 seconds for JS/AJAX } }
Images may show mobile layout instead of desktop (or vice versa) based on viewport width. Set screenshot_width to control which responsive breakpoint is used:
window.webSaveConfig = { apiSettings: { screenshot_width: 1280, // Force desktop layout } }
Common widths: Mobile (375-414px), Tablet (768-834px), Desktop (1280-1920px).
WebSave provides two debugging options to help diagnose different types of issues:
verbosity logs WebSave events (button clicks, API calls, key validation) to your browser console - useful for integration and configuration issues.
debug_log captures what happens on PDFCrowd servers (resource loading, timeouts) - helpful for content and layout problems.
Find these logs in your conversion log.
window.webSaveConfig = { verbosity: 1, // Client-side: logs events to browser console apiSettings: { debug_log: true, // Server-side: saves details to conversion log } };
For more guidance, see the API FAQ and WebSave Reference.
We’re happy to help you add the button, choose the right settings and fine-tune the output for your site. When contacting us, include:
For conversion errors, include the error message and any available debug logs.