Save as PDF WordPress Plugin

The plugin adds a "Save as PDF" button to your WordPress website, enabling your site visitors to save a webpage as a PDF or send it via email with just one click. This provides the option to read your content offline or share it easily with others. Whether it's articles, posts, or product pages, "Save as PDF" ensures your website's content is accessible in a widely used format.

Installation

The plugin is hosted on WordPress.org as Save as PDF by Pdfcrowd. Installing the plugin is straightforward and can be done in a few simple steps. Choose the method that works best for you:

  1. Log in to your WordPress dashboard.
  2. Navigate to `Plugins > Add New`.
  3. In the search field, type `Save as PDF by Pdfcrowd` and press Enter.
  4. Once the plugin appears, click the "Install Now" button next to it.
  5. After installation, click the "Activate" button to start using the plugin.
  1. Download the plugin ZIP file: save-as-pdf-pdfcrowd-3.2.3.zip.
  2. Log in to your WordPress dashboard.
  3. Navigate to `Plugins > Add New > Upload Plugin`.
  4. Click the "Choose File" button and select the downloaded ZIP file. Then, click "Install Now".
  5. Once the upload and installation are complete, click "Activate Plugin" to begin using it.

License

By default, the plugin operates in demo mode, which, while fully functional, adds a watermark and Pdfcrowd branding to the content.

To remove the demo watermark and Pdfcrowd branding, you can purchase an API license. Activate the license by entering your Pdfcrowd username and API key in the plugin settings under the License tab.

A Pdfcrowd API license is versatile, allowing use across multiple WordPress websites for our plugins. Additionally, the API license grants direct access to the Pdfcrowd API for a broader range of applications.

Plugin Output Preview

You can quickly preview the plugin output by entering a URL or uploading an HTML file below. This will generate previews with different plugin settings. You can then choose the one you prefer and configure the plugin using the respective settings.

Getting Started

Once activated, the "Save as PDF" button will automatically appear on all eligible content according to your settings. Users can click this button to save the current page as a PDF file.

To manually add the "Save as PDF" button to specific pages or posts, you can use either shortcode or PHP function.

The plugin offers various customization options accessible through the WordPress admin panel. You can change the PDF generation settings and button appearance. For more detailed customization, please refer to Customization, and to the Option reference.

Shortcode

You can add the button using either a plain or block shortcode.

  • [save_as_pdf_pdfcrowd] saves the entire webpage as PDF.
  • [block_save_as_pdf_pdfcrowd] saves only the enclosed code block as PDF. To style the block, include CSS rules within the shortcode.

The examples below demonstrate how to use the shortcodes and override the default settings configured in the plugin.

<h3>Save the print version of the page</h3>

The button is placed in the middle
[save_as_pdf_pdfcrowd \
    use_print_media=1 \
    output_name='inline.pdf' \
    button_text='Save print version to PDF']
of this sentence.


<h3>Save the screen version of the page</h3>

[save_as_pdf_pdfcrowd \
    use_print_media=0 \
    output_name='browser.pdf' \
    button_text='Save screen version to PDF']


<h3>Save only a code block</h3>

[block_save_as_pdf_pdfcrowd \
    output_name='just_div.pdf' \
    button_text='Download just this section as PDF' \
    page_size='letter' \
    button_background_color='green' \
    button_alignment='left']
<style>
 .invoice {
     font-size: 150%;
 }
</style>
<div class="invoice">
 Save only this div and its descendants.
</div>
[/block_save_as_pdf_pdfcrowd]


<h3>Convert any web page</h3>

[save_as_pdf_pdfcrowd \
    url='https://wikipedia.org' \
    output_name='wikipedia.pdf' \
    button_text='Save Wikipedia as PDF']

PHP Function

You can add the conversion button directly within your PHP code using the following helper function:

create_save_as_pdf_pdfcrowd_button($options = array())

Here, the $options argument is an array that contains settings to override the plugin's default configuration. For example:

echo create_save_as_pdf_pdfcrowd_button(array(
         'page_size' => 'Letter',
         'button_text' => 'Save as Letter'
));

Server-initiated Conversion

For scenarios where you need to initiate a conversion synchronously - perhaps in response to an event other than a button click - the plugin provides a PHP function.

pdfcrowd_save_as_pdf($options = array())

In this case, the $options argument is an array of conversion settings that are independent of the plugin's default settings. This array must at least include your Pdfcrowd username and API key. For example:

<?php
    $output = pdfcrowd_save_as_pdf(array(
        'username' => '',
        'api_key' => '',
        'page_size' => 'Letter',
        'url' => 'https://www.example.com/'
    ));
    if(!is_wp_error($output)) {
        echo $output;
    }
?>

Customization

The table below highlights the most common customizations you might find useful. Refer to the Option Reference for a detailed description of all available options. For an interactive experience, explore these options in the API Playground.

For additional customization options and troubleshooting, please visit the FAQ section of our website where you can find answers and help related to frequent queries and common issues.

Page Size Adjust the page size using Page Size. To create a single-page, set -1 to Page Height to consolidate all content onto one page.
Page Orientation Change the page orientation to landscape using Orientation.
Page Margins Adjust the page margins with Page Margins. To eliminate all margins use No Margins.
Headers and Footers Add custom headers and footers using Header Html and Footer Html. To adjust the height of headers or footers, use Footer Height and Header Height respectively.
Hide or Remove Contents Utilize the following classes in your HTML code to hide or remove elements from the output:
  • `pdfcrowd-remove`: This class applies `display:none!important` to the element, effectively removing it from the layout.
  • `pdfcrowd-hide`: This class applies `visibility:hidden!important` to the element, making it invisible but still occupying space in the layout.
For additional methods and detailed explanations, refer to this FAQ article.
Custom CSS Styling To customize CSS styling specifically for the conversion, use Custom Css to inject additional styles.

Alternatively, you can directly incorporate conversion-specific styling into your main stylesheet. Just prefix your CSS selectors with `.pdfcrowd-body` to ensure the styles apply only during the conversion process. For example:
.pdfcrowd-body h1 { font-size: 48px; }
.pdfcrowd-body footer { display: none; }
Avoid Page Break To prevent page breaks within specific elements, use the `page-break-inside:avoid;` CSS property. Apply this property to elements where you do not want a page break, such as tables, table cells, and images. Here is an example:
th, td, img { page-break-inside:avoid }
Force Page Break You can force a page break in your document by incorporating a specific style in an HTML div tag. Insert the following code where you want the page break to occur:
<div style="page-break-before:always"></div>
Zoom Adjust the zoom level of HTML contents by using Scale Factor. This allows you to scale the content up or down according to your preferences or needs.
Use `@media print` Activate the print version of a webpage (if available) using Use Print Media. This function instructs the plugin to apply the CSS rules defined within the `@media print` stylesheet, ensuring the output mirrors the print-optimized version of the webpage.
Inject Custom JavaScript Utilize Custom Javascript or On Load Javascript to modify HTML content using custom JavaScript scripts. These scripts run when the page loads, allowing you to dynamically alter elements, styles, or behavior. In addition to the standard browser JavaScript APIs, your scripts can leverage helper functions provided by our JavaScript library.

Troubleshooting

If the default plugin output does not meet your requirements, consider adjusting the following settings individually. You may need to activate the "Expert Settings" option to access some of these features.

  • Mode > Conversion Mode: Try switching it to either "Upload" or "Content".
  • Print Resolution > Viewport Width: Experiment with different widths to see which yields the best result.
  • Print Resolution > Viewport Height: Increase this value, for example, to 50000, to see if it improves the output.
  • Print Resolution > Smart Scaling Mode: Different scaling modes can significantly alter the PDF's page layout.
  • Print Resolution > Rendering Mode: This setting also impacts the layout of the PDF page.

Other troubleshooting steps:

  • If you are receiving an error, refer to the API Status Codes for more information.
  • Utilize Debug Log to obtain detailed information about the conversion process, including load errors, load times, browser console output, etc.
  • Consult the FAQ for answers to common questions.
  • Contact us if you need assistance or if there is a feature you are missing.

Option Reference

Refer to the Save as PDF WordPress Plugin Reference for a description of all options.