Save as PDF WordPress Plugin

The plugin adds the "Save as PDF" button to your WordPress web site. The button allows to save a web page as PDF or send it by email in one click.

Samples

Installation

  • You can install the plugin using one of the following options:
  • Activate the plugin in the dashboard.

License

The plugin runs in a demo mode by default, you do not need to register to try it out. The demo mode is fully functional, it just adds a watermark to the output PDF.

If you want to remove the watermark, you can purchase our API license and set your Pdfcrowd username and API key in the plugin settings.

A single API license can be used for both our WordPress plugins on multiple web sites. The API license also allows to use our Conversion API directly.

Preview

Enter a web page or upload an HTML file to get a preview of the plugin output. The preview will also show the corresponding plugin settings, a shortcode or a PHP function call.

You can also interactively explore all plugin options in our API Playground.

Getting Started

There are three ways to add the button to your web site.

Automatic

The button is added to your pages automatically after the plugin is installed. On the Appearance tab in the plugin settings, you can can select the pages to which you want to add the button.

Shortcode

You can add the button with a plain or block shortcode.

  • [save_as_pdf_pdfcrowd] - Saves the entire web page as PDF.
  • [block_save_as_pdf_pdfcrowd] - Saves just the enclosed code block as PDF.

The examples below show how to use the shortcodes and override the defaults set in the plugin settings.

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

The button is put in the middle
[save_as_pdf_pdfcrowd \
    use_print_media=1 \
    output_name='inline.pdf' \
    button_text='Save printable 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 browser page to PDF']


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

[block_save_as_pdf_pdfcrowd \
    output_name='just_div.pdf' \
    button_text='Save just a part of the page' \
    page_size='letter' \
    button_background_color='green' \
    button_alignment='left']
<style>
 .invoice {
     font-size: 150%;
 }
</style>
<div class="invoice">
 Save this div and its descendants only.
</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

The conversion button can be added directly from your PHP code with this helper function:

create_save_as_pdf_pdfcrowd_button($options = array())

The $options argument is an array containing settings which override the defaults set in the plugin settings. An example:

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

Server-initiated conversion

The plugin offers a PHP function that runs the conversion synchronously. This may be useful if your want to initiate a conversion based on an event other than a plugin button click.

pdfcrowd_save_as_pdf($options = array())

The $options argument is an array containing conversion settings independent of the settings set on the plugin settings page. It must contain at least your Pdfcrowd username and the API key. An 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;
    }
?>

Examples

Integration Examples

The plugin can be easily integrated into your environment. You can have our interactive API Playground autogenerate the integration code for you:

Common Customizations

You can find the most common customizations in the table below.

Page size Change the page size with Page Size option or Page Dimensions option . Pass -1 to Page Height option to get a single page PDF containing the whole document.
Page orientation Change the page orientation to landscape with Orientation option.
Page margins Adjust the page margins with Page Margins option.
Headers and footers Add headers and footers with Header Html option and Footer Html option. Set the height with Footer Height option and Header Height option.
You can learn more in this tutorial.
Zoom Scale the HTML contents with Scale Factor option.
Hide or remove elements You can use the following classes in your HTML code to hide or remove elements from the output:
  • pdfcrowd-remove - sets display:none!important on the element
  • pdfcrowd-hide - sets visibility:hidden!important on the element
Learn about other options.
Use @media print You can switch to the print version of the page (if it exists) with Use Print Media option.
Force page break You can force a page break with
<div style="page-break-before:always"></div>
Avoid page break You can avoid a page break inside an element with the following CSS
th, td, img { page-break-inside:avoid }
Run custom JavaScript You can use On Load Javascript option or Custom Javascript option to alter the HTML contents with a custom JavaScript. In addition to the standard browser APIs, the custom JavaScript code can use helper functions from our JavaScript library .
Custom CSS styling You can alter CSS styling used during conversion with a custom JavaScript or using the pdfcrowd-body CSS class, which is automatically set on the HTML <body> element. You can, for example, set the H1 height to 48px by adding the following line to your CSS:
.pdfcrowd-body h1 { font-size: 48px; }
Add PDF signature You can create PDF containing a digital signature field. Such PDF can be digitally signed in, for example, Adobe Acrobat or Preview. Learn more in Create Digital Signature in PDF .
Fillable PDF form You can create fillable PDF containing interactive fields and buttons. Learn more in Create Fillable PDF Form.

Troubleshooting

Option Reference

Refer for details to the Option Reference.