Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTextDocument, print image to fit page width
Forum Updated to NodeBB v4.3 + New Features

QTextDocument, print image to fit page width

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 2.9k Views 1 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.
  • L Offline
    L Offline
    luca
    wrote on last edited by
    #1

    Hi all,
    I need to print an image to a pdf page that fit the page width.

    this is my code (that doesn't works as expected):

    @
    QTextDocument document;
    QString html_document_str;
    QPrinter p;
    p.setOutputFormat(QPrinter::PdfFormat);
    QPrintDialog pd(&p, 0);
    pd.exec();

    html_document_str = "<img />";
    document.setHtml(html_document_str);
    document.print(&p);
    @

    The code create a pdf with an empty page. The html code I used works in a browser.

    Where do I wrong?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      luca
      wrote on last edited by
      #2

      EDIT (the code I pasted before was wrong. In the post I can't write the code I used with escape character) .

      To let you see the code I write it with some space characters:

      html_document_str = " < img src= " :/images/intestazionegw.jpg " width="100%" > " ;

      The proble in my application is that if I put " width =100% " in my html code I don't see the image in the pdf while if I remove the "width" :

      html_document_str = " < img src= " :/images/intestazionegw.jpg " > " ;

      I can see the image printed in the pdf but its dimension is too big and go uotside the page.

      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 Extensions
      • Unsolved