=== HTML to PDF Converter ===

Contributors: html2pdfapp
Tags: pdf, page to pdf, save to pdf, convert to pdf, html2pdf
Requires at least: 5.0
Requires PHP: 7.0
Tested up to: 7.0
Stable tag: 1.1.0
License: GPLv2 or later
License URI: https://www.gnu.org/licenses/gpl-2.0.html

Convert any WordPress page or post to PDF with the html2pdf.app API — via a shortcode or an automatic "Save as PDF" button.

== Description ==

The "HTML to PDF Converter" plugin, created by [html2pdf.app](https://html2pdf.app), lets your visitors save any WordPress page or post as a PDF. Install the plugin, add your API key, and either drop a shortcode where you want the download link — or switch on the automatic button to add a "Save as PDF" link to every post and page with no shortcode at all.

Conversions are handled by the html2pdf.app cloud API, the same engine used by the standalone service, so PDFs render with full CSS, web fonts, and images.

= Features =

* **One shortcode** — add a download button anywhere with `[html2pdf text="Save as PDF"]`.
* **Automatic button** — show a "Save as PDF" button on chosen post types automatically, with no shortcode. Choose the position (before, after, or both) and the button text.
* **Print-ready output** — set the CSS media type to `screen` or `print` (globally or per shortcode) to use your theme's `@media print` styles and hide unwanted sections.
* **Full conversion control** — page format (A4, Letter, Legal, and more), portrait/landscape orientation, custom margins, and custom width/height.
* **Test your connection** — validate your API key from the settings page in one click before you go live.
* **Styled, theme-friendly button** — ships with a clean default style that your theme can override, and is hidden automatically in the PDF when converting with print media.

= Why a PDF plugin? =

PDF downloads are useful for invoices, receipts, documentation, recipes, event tickets, knowledge-base articles, and any content your visitors want to save or print. This plugin gives them a one-click way to do it.

== External services ==

This plugin relies on the third-party html2pdf.app API to generate PDFs. When a visitor clicks a conversion link, the URL of the page being converted (together with your conversion settings) is sent to `https://api.html2pdf.app/v1/generate`, which fetches that public URL, renders it, and returns the PDF. Your API key is sent with the request for authentication.

Because the API fetches the page itself, the page being converted must be publicly accessible on the internet.

* Service: html2pdf.app — https://html2pdf.app
* Terms of Service: https://html2pdf.app/terms-of-service/
* Privacy Policy: https://html2pdf.app/privacy-policy/

== Installation ==

1. Upload the plugin files to `/wp-content/plugins/html-to-pdf-converter`, or install the plugin through the WordPress "Plugins" screen directly.
2. Activate the plugin through the "Plugins" screen in WordPress.
3. Go to **Settings → HTML to PDF** and enter your html2pdf.app API key. You can register for a free API key at https://dash.html2pdf.app/registration.
4. Click **Test connection** to confirm your key works.
5. Add the `[html2pdf text="Save as PDF"]` shortcode to a page or post — or enable the automatic button under "Automatic Save as PDF button".

== Plugin Settings ==

Go to **Settings → HTML to PDF** to configure:

* **API Key** — your html2pdf.app key (with a "Test connection" button to verify it).
* **Page Format** — Letter, Legal, Tabloid, Ledger, or A0–A6.
* **Landscape** — switch orientation to landscape.
* **Media** — `screen` or `print`. Choose "print" to apply your theme's `@media print` styles. This is the default for every button and can be overridden per shortcode.
* **Margins** — top, right, bottom, and left margins in pixels.
* **Width / Height** — optional custom page size in pixels.
* **Automatic button** — enable it, choose which post types it appears on, its position, and the button text.

== Usage ==

**Shortcode**

Add the shortcode to any page or post:

`[html2pdf text="Save as PDF"]`

Supported attributes:

* `text` — the button label (default: "Generate PDF").
* `media` — `screen` or `print` (defaults to the Media setting).

Example: `[html2pdf text="Download PDF" media="print"]`

**Automatic button (no shortcode)**

Under **Settings → HTML to PDF → Automatic Save as PDF button**, enable the button and pick the post types, position, and label. The button is then added to that content automatically.

== Examples ==

**Hide parts of the page from the PDF.** Add the `html2pdf_hide` class to any element (header, footer, sidebar, etc.) and it will be excluded from the generated PDF, while still showing normally to your visitors:

<pre>
&lt;div class="html2pdf_hide"&gt; ... not included in the PDF ... &lt;/div&gt;
</pre>

No extra CSS or print media is required — the conversion button is hidden automatically too.

**For full control**, the page `<body>` receives a `html2pdf-rendering` class while it is being converted, so you can target anything from your theme's stylesheet:

<pre>
.html2pdf-rendering .site-header,
.html2pdf-rendering .site-footer {
    display: none !important;
}
</pre>

You can also use the "media" parameter (or the Media setting) to activate your theme's print styles: `[html2pdf text="Save as PDF" media="print"]`.

== Frequently Asked Questions ==

= Do I need an API key? =

Yes. The plugin uses the html2pdf.app API to render PDFs. Register for a free API key at https://dash.html2pdf.app/registration and paste it into the plugin settings.

= My page won't convert or the PDF is empty. Why? =

The html2pdf.app API fetches your page over the internet, so the page must be publicly accessible. Conversions will not work on local development sites (e.g. `localhost`), staging behind HTTP authentication, or password-protected/private posts. Use a publicly reachable URL.

= How do I check that my API key is correct? =

On the settings page, click **Test connection** next to the API Key field. You'll get an immediate success or error message.

= Can I add the button without using a shortcode? =

Yes. Enable the automatic button under **Settings → HTML to PDF**, choose the post types and position, and the "Save as PDF" button is added to your content automatically.

= How do I hide the header, footer, or other parts of the page in the PDF? =

Add the `html2pdf_hide` class to any element you want to exclude — it stays visible to visitors but is removed from the PDF. For custom rules, the `<body>` gets a `html2pdf-rendering` class during conversion. See the Examples section.

= Can I change the page size, margins, or orientation? =

Yes — all of these are configurable on the settings page, including A4/Letter/Legal and other formats, landscape mode, custom margins, and a custom width/height.

= Where is my content sent? =

The URL of the page being converted and your conversion settings are sent to the html2pdf.app API. See the "External services" section above for details.

== Screenshots ==

1. Plugin settings page: API key with "Test connection", conversion options, and the automatic button settings.
2. A "Save as PDF" button rendered on a page.
3. Example of a generated PDF.

== Changelog ==

= 1.1.0 =
* Confirm compatibility with WordPress 7.0
* Add automatic "Save as PDF" button insertion on selected post types (no shortcode required), with position and button text options
* Add a default Media (screen/print) setting, overridable per shortcode
* Add a "Test connection" button on the settings page to validate the API key
* Mask the API key field with a Show/Hide toggle
* Add usage examples directly in the plugin settings page
* Ship default button styling, and hide the conversion button in the generated PDF automatically (any media type)
* Add an html2pdf_hide class and an html2pdf-rendering body class to exclude any element from the generated PDF
* Redesign the settings page with grouped, card-style sections for clearer separation
* Restrict conversions to pages on the same site to prevent misuse of the API key
* Send API key via the X-API-Key header instead of a request body parameter
* Identify plugin requests for monitoring with an X-Source header
* Sanitize server-provided URL values

= 1.0.8 =
* Use page URL instead of persisted one, add settings link in a plugins page

= 1.0.7 =
* Update icon, increase compatibility with the latest wordpress version

= 1.0.6 =
* Update readme file with examples

= 1.0.5 =
* Add possibility to pass media parameter through the shortcode

= 1.0.4 =
* Improve error reporting

= 1.0.3 =
* Icon, author URI and support email added

= 1.0.2 =
* Initial version

== Upgrade Notice ==

= 1.1.0 =
Adds an automatic "Save as PDF" button, a default Media setting, an API key "Test connection" check, and button styling. Confirmed compatible with WordPress 7.0.
