Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QPdfWriter convert html without breaking pages
Qt 6.12 LTS is out! See what's new in the release blog

QPdfWriter convert html without breaking pages

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 365 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Z Offline
    Z Offline
    zandarina
    wrote on last edited by zandarina
    #1

    Hello,

    I have a problem i define the margin with QPdfWriter and i create a html document but it does not break the pages when we reach out of the margins. I have defined the margins in thousands of ways but the method does not break the html when it reaches the margin. It goes out of the margins. and if i break the line using html with <div style="page-break-after:always"></div>, from this point it's not shown in the pdf. It is very weird. Is it a bug? . Thank you very much.

    QPdfWriter pdfWriter("pdf_generated.pdf");
    pdfWriter.setPageSize(QPagedPaintDevice::A4);
    pdfWriter.setPageMargins(QMargins(30, 30, 30, 30));
    const qreal horizontalMarginMM = 2.0;     // 2mm margin on each side
    const qreal verticalMarginMM = 2.0;
    QPagedPaintDevice::Margins margins;
    margins.left = margins.right = horizontalMarginMM;
    margins.bottom = margins.bottom = verticalMarginMM;
    pdfWriter.setMargins(margins);
    
    document.setHtml(html);
    QFont font;
    font.setPointSize(8);
    document.setDefaultFont(font);
    QPainter painter;
    painter.begin(&pdfWriter);
    document.drawContents(&painter);
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What version of Qt are you using ?
      Can you provide a complete minimal compilable exemple showing that behaviour ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt
      • Unsolved