How can I convert only part of a WordPress page to PDF?
Yes. There are several ways to do it. Choose the approach based on whether the section already exists on the page, is supplied inside a block shortcode, or is configured in a shortcode or theme template.
Use the Element To Convert option for an existing page section
If the section already exists on the page, set the
Element To Convert
option with a CSS selector such as #invoice, .print-area, or
main article. This is usually the best choice when the PDF should use a
section that is already visible on the page.
Set the selected section in a shortcode
To set the selected section directly in a shortcode, use the
element_to_convert parameter:
[save_as_pdf_pdfcrowd
element_to_convert="#invoice"
output_name="invoice.pdf"]
Use the block shortcode for self-contained HTML
Use the block shortcode when you want to provide the exact HTML that should become the PDF. The plugin converts only the HTML inside the block, so include any CSS the block needs inside the block content.
[block_save_as_pdf_pdfcrowd output_name="section.pdf"]
<div class="pdf-section">
This content becomes the PDF.
</div>
[/block_save_as_pdf_pdfcrowd]
If the block-shortcode output no longer matches the selected section as it appears on the page, switch to the Element To Convert option before changing layout settings.
Use PHP in a theme template
In a theme template, use the same option with the PHP helper:
echo create_save_as_pdf_pdfcrowd_button(array(
'element_to_convert' => '#invoice',
'output_name' => 'invoice.pdf'
));
Use cleanup rules when you need to remove page parts
If the PDF should contain most of the page but exclude headers, sidebars, cookie banners, ads, or similar page parts, selected-area conversion is usually the wrong tool. Use the cleanup methods in How can I remove headers, sidebars, cookie banners, or other content from the WordPress PDF? instead.