简体   繁体   中英

missing explicit frame definition for content or just static frames

I am converting HTML to pdf in Django app and using xhtml2pdf. Given is my HTML template.

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <meta http-equiv="x-ua-compatible" content="ie=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>Certificate</title>
        <!-- Style sheets -->
        <link href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600" rel="stylesheet">
        <link rel="stylesheet" type="text/css" href="/static/css/main.css">
    </head>
    <body>
        <div class="container">
            <img class="banner-top" src="/static/images/top.jpg"><br>
            <div class="inner-container">
                <h2 style="letter-spacing:5;">WINNER'S</h2>
                <h1 style="letter-spacing:5;">CERTIFICATE</h1>
                <p class="client-name">Paul</p>
                <p>This is to acknowledge that you won the competition.</p>
                <h3>
                  <img class="star" src="/static/images/star.jpg">
                  4 TIME
                </h3>
                <p>Congratulations on winning Challenge.</p>
                <div class="row">
                    <div class="six columns">
                        <p class="date">2018-09-20</p>
                        <p class="date-label">Date</p>
                    </div>
                    <div class="six columns">
                    </div>
                </div>
            </div>
            <img class="banner-bottom" src="/static/images/bottom.jpg">
        </div>
    </body>
</html>

I am using pisa.CreatePDF to generate pdf and CSS is not loading properly. I tried default_css and got this error.

missing explicit frame definition for content or just static frames

Here is the snippet of my python code

        pisa.CreatePDF(io.BytesIO(html.encode('utf-8')),
                   dest=result, link_callback=fetch_resources,
                   default_css="/static/css/main.css")

I had a similar problem when used @page background-image by url.

After a few hours of testing different variants, I have fixed this warning by adding tag @frame in tag @page . But no need to use this frame in html(for me it is dummy tag only to exclude this warning).

<style type="text/css">
@page {
  size: A4;
  @frame content_frame {          /* Content Frame */
    left: 0pt; width: 620pt; top: 0pt; height: 877pt;
  }
  background-image: url({{ SITE_URL }}/media/img/dsg/backgrounds/featured_ft_pdf_3.png?v=1.02);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM