Puppeteer challenge with breaking images

When generating a PDF from HTML, I am facing an issue where the signature image breaks on another page. Is there a way to ensure that if content or images break, they will move to another PDF page?

Puppeteer version - 3.3.0 Node version - 12.16.1

Check the image here

Code:

await page.pdf({
                    path: pdfPath,
                    format: 'A4',
                    printBackground: true,
                    displayHeaderFooter: true,
                    headerTemplate: '<div id="header-template" style="font-size:10px !important; color:#808080; padding-left:10px"><span class="">Production</span></div>',
                    footerTemplate: '<div id="footer-template" style="font-size:10px !important; color:#808080; padding-left:10px"><span class="">Production</span><span class="pageNumber" style="font-size:10px !important; color:#808080; padding-left:200px"></span></div>',
                    margin: {
                        top: '100px',
                        bottom: '100px',
                        right: '30px',
                        left: '30px',
                    },
                });
html:
<div style="float: left; margin-top: 5px;width: 98.5%;">
                <div id="signature">
                    <div class="sign">
                        <img src="{{signature}}" alt="sign"
                            style="margin-top: 10px;width: 120px;height: 120px;float: right;" />
                    </div>
                    <span>Signature By {{ signature_by }}<br>({{ signature_by_role }})</span>
                </div>
            </div>

CSS:

#signature {
            float: right;
            width: auto;
            margin-right: 1%;
        }
        #signature img {
            width: 100%;
        }
        #signature span {
            text-align: center;
            width: 100%;
            color: #000;
            float: left;
            font-size: 11px;
            font-weight: 500;
        }
        .sign {
            min-height: 50px;
            text-align: center;
            margin: 0 auto;
        }

Answer №1

To prevent signature from breaking, apply the break-inside: avoid; CSS property

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Videos embedded using the React HTML video tag are not automatically playing on mobile devices

I have implemented a jsx variable to insert a video into my html. Despite following the advice to include muted defaultMuted, and playsinline (which I have already done), the videos autoplay on safari, chrome, and firefox on my computer but not on mobile ...

Avoiding the use of HTTPOnly cookie in production sites

Utilizing firebase along with session cookies for user authentication on my react website, with the backend using google cloud functions. Successful login occurs on localhost where my react app runs on localhost:3000 and the cloud functions on localhost:50 ...

What could be causing the distance between the image and the navigation bar?

Hey there, I'm struggling with a pesky little gap that's sneaking in between an image and my navigation bar. I've exhausted all my usual tricks like setting inline-blocks on the ul and li levels, and trying to align everything left with text ...

Simple Way to Modify Color of Active Page Link - HTML, CSS, and JavaScript

I found a helpful example on how to change link colors for the current page here. Here is the script I added: <script> // current page highlight $(document).ready(function() { $("[href]").each(function() { if (this.href == window.l ...

Node.js is known for its unreliable promise returns

Currently, I have a function in place that establishes a connection with a sql database. After querying the database and formatting the results into an HTML table, the function returns the variable html: function getData() { return new Promise((resolv ...

Utilizing MongoDB and Mongoose to access a single database and authenticate against a separate one in a NodeJS application

Managing multiple databases can be a hassle, especially when it comes to creating separate user accounts for each one. Luckily, MongoDB offers the option of authenticating access to a database using accounts defined in another database. However, finding ex ...

Looking to attach the "addEventListener" method to multiple elements that share the same class?

I'm trying to use an event listener in JS to handle the logic in the "onClick" function, but it's only executing once. I've applied the same class to all four buttons, so I'm not sure why it's only working for the first one. HTML: ...

"Error: React dotenv is unable to access the .env configuration file

My React and Node project has a .env file in the root directory, along with other important files like .eslint and .gitignore. The .env file contains 6 lines of code such as APIKEY=aeofiunoief, without any special symbols. Within the src/ directory, there ...

Extract specific data points from external API responses on a webpage crafted in HTML

I require assistance on how to extract individual values from an HTML page. I received a response from the PAYU payment gateway team in HTML format, but I need to retrieve specific attribute values related to the transaction details. Below is the response ...

Utilizing NodeJS REST API to seamlessly add new events with the Google Calendar API

I am looking to transfer data to my NodeJS backend (using the Express framework) and then trigger an event on Google Calendar through the Google Calendar API. The data is being received via the POST method from express.Router() Currently, when I make a r ...

Discovering visible ID numbers on the screen

My content includes the following: <div id="sContainer"> <div class="message0" id="l0">Initial Content 111</div> <div class="message1" id="l1">Initial Content 222</div> <div class="message2" id="l2">Initial ...

The Passport deserialization process is eliminating the user from the current session

Today marks the beginning of my journey with Passport. I feel like I'm starting to grasp some aspects of how it functions, but there's still a lot to learn. The issue I'm facing is that my user keeps getting removed from the session, which i ...

How can the distinctions between two bars be illustrated in high charts?

Is there a way to display different values on a new line between two bar charts using Highcharts plugins? I have created a simple bar chart in Highcharts, but I am looking to show the difference between the two bars on a new line. The concept is illustrate ...

Leveraging Generic Types in React with TypeScript for Dynamically Assigning HTML Props based on Element Tags

I am frequently in need of a component that is essentially just a styled HTML tag. A good example is when I want to create beautifully styled div elements: // Definitions const styledDiv = (className: string) => { const StyledDiv = React.FC<HTMLA ...

How should I refer to this style of font?

After trying to implement a font from bulletproof @font-face as a template for my website, I am facing issues. My goal is to utilize the perspective-sans black regular font. Despite uploading the necessary files - including the css style sheet provided in ...

Issue with sending data through $http PUT

I am currently in the process of developing a basic auction platform. After displaying my products on the website, I now want to introduce a new feature - making offers. In order to implement this functionality, I have used ng-dialog in my controller to op ...

Is there a way to automatically change the display of an element once the user has closed the menu?

How can I ensure that the display of an element remains unchanged when a user opens and closes my website menu using JavaScript? ...

Discover the secrets to showcasing just the vivid hues of red and green based on a specific threshold with the HTML Meter component

Hello Team, I am trying to use a Meter Element in HTML and I want to display either Red or Green color depending on the value change. When the Value is less than 20, I want the Meter color to be RED, and if the Value is greater than 20, then the Meter col ...

I'm having trouble with the routing of a Node.js REST API built with Express and Mongoose

I am currently in the process of constructing a RESTful webservice by following a tutorial that can be found at: However, I have encountered an issue where it is returning a CANNOT GET/ reports error. Despite my efforts to troubleshoot and rectify the pro ...

Every time an input field is clicked, an email is sent

I'm struggling with the contact form on my website. Instead of sending an email after clicking on each input field, I want it to send only one email after hitting the submit button. Currently, it sends a total of 5 emails - 1 with user inputs and 4 wi ...