Adding detailed headers and footers with html

This article discusses creating PDFs in Bubble applications (using the 'Create PDF' plugin action). If you wish to create PDFs based on a template you have designed in our template editor, please see other sections of the documentation.

You can build your own headers/footers using custom HTML/CSS.


Adding custom HTML headers/footers

If you add text that begins with <html>   and ends with </html>   to any of the footer/header content fields, DocuPotion will automatically interpret it as a custom header/footer.


For example, you can add the below code to either the left/right footer field to get a custom footer with the company's logo, name, address, phone number and email.

<html>
<head>
    <style>
        body {
            margin: 0;
            padding: 20px;
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
        }
        
        .contact-info {
            background-color: #ffffff;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 10px 20px;
            border-top: 1px solid #e0e0e0;
            font-size: 11px;
            color: #666;
            line-height: 1.4;
            width: 100%;
            height: 50px;
            box-sizing: border-box;
        }
        
        .contact-info strong {
            color: #333;
            font-size: 12px;
        }
        
        .company-logo {
            height: 30px;
            width: auto;
        }
        
        .contact-text {
            text-align: right;
        }
        
        @media print {
            body {
                background-color: white;
                padding: 0;
            }
            .contact-info {
                background-color: white;
            }
        }
    </style>
</head>
<body>
    <div class="contact-info">
        <img src="https://imageurl.com" alt="Company Logo" class="company-logo">
        <div class="contact-text">
            <strong>Company Name</strong><br>
            123 Business Street, London, SW1A 1AA<br>
            Phone: +44 20 1234 5678 | Email: info@yourcompany.com | Web: www.yourcompany.com
        </div>
    </div>
</body>
</html>

We recommend using the Bubble arbitrary text operator to make it easier to see the custom code:

Please note that we've added in dynamic for the img src (which will be the company's logo) and the company's name.


Here's how the footer looks in the output PDF:

LLMs (ChatGPT, Claude) can generate excellent header/footer templates. If you want your own custom header/footer but are not a traditional developer, we recommend trying them out.


Page Numbers

You can include page numbers in your custom HTML header/footer in two ways:

  • Include the text page-counter   anywhere in the HTML. It is replaced with the current page number.
  • Include <span class="pageNumber"></span>   for the current page number and <span class="totalPages"></span>   for the total number of pages in the PDF.

For example, to show "Page 3 of 14", add this to your HTML:

Page <span class="pageNumber"></span> of <span class="totalPages"></span>

You can style these spans like any other element (for example, by wrapping them in a <div>   with its own class). See this article for complete examples.

The page number and total number of pages are filled in when the PDF is generated, so they only work inside headers and footers. They are not available on your Bubble page itself (for example, in a table of contents).


Order of priority

You can not show both a custom footer and a plain text footer in the same PDF.


If you add a custom footer to the left or right footer content field and ALSO add some plain text to the other footer content field, the custom footer will override the plain text.


The same principle applies to headers.

Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.