1

I'm trying to use a Thymeleaf html template and transform it into a PDF using Flying Saucer PDF, however I am having issue with the html content being push far right. Below is an example of the generated PDF.

enter image description here

I'm using Bootstrap CSS v4 and a bit of inline styles. Below is a screenshot of the HTML rendered in the browser. Notice that the content is centered in the view and elements and text aren't cut off.

enter image description here

Here's my HTML template:

<html xmlns:th="http://www.thymeleaf.org">
    <head>
        <title></title>
        <link rel="stylesheet" type="text/css" href="/webjars/bootstrap/4.5.3/css/bootstrap.min.css" />
        <link rel="stylesheet" href="/css/styles.css" />
    </head>
    <body>
        <div class="container">
            <h3 class="display-4 text-center">MY FIRST THYMELEAF TO PDF PROJECT. HAVING ISSUE WITH PDF FORMATTING THOUGH.............</h3>
            <div class="text-center inline-flex">
                <span style="font-size: 2.5rem; letter-spacing: 0">Thymeleaf Template Engine</span>
                <span style="font-size: 2.0rem; opacity: 1; color: #707070; padding-left: 20px">Flying Saucer PDF</span>
            </div>
            <div class="jumbotron">
                <h2 class="display-2 float-right">Some Jumbo Text</h2>
            </div>
        </div>
    </body>
</html>

And here some CSS that I attempted to apply with no success.

@font-face {
    font-family: Lato;
    src: url("../fonts/Lato-Regular.ttf") format('truetype');
}

/*@page {*/
/*    margin: 0;*/
/*}*/

/*@page :right {*/

/*    @right-middle {*/
/*        padding-right: 200vw;*/
/*        padding-left: 200vw;*/
/*    }*/

/*    @top-right {*/
/*        content: "My Quote";*/
/*        margin: 30pt 0 10pt 0;*/
/*    }*/
/*}*/

/*@page :right {*/
/*    margin-right: 1cm;*/
/*}*/

/*@page {*/
/*    !*size: 5.5in 8.5in;*!*/
/*    margin: 0;*/

/*    @right-middle {*/
/*        !*margin: 30pt 0 10pt 0;*!*/
/*    }*/

/*    !*@top-left-corner {*!*/
/*    !*    content: url("/images/logo.png");*!*/
/*    !*    width: 200px;*!*/
/*    !*    height: 50px;*!*/
/*    !*}*!*/

/*    @top-right {*/
/*        content: "My PDF";*/
/*        !*margin: 30pt 0 10pt 0;*!*/
/*    }*/
/*}*/

I've tried formatting the page margins with the @page css annotation be nothing above helped adjust the content. Any help would be absolutely fantastic! Thanks!

Joseph Freeman
  • 1,644
  • 4
  • 24
  • 43

0 Answers0