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. Need to partially convert HTML to PDF document
QtWS25 Last Chance

Need to partially convert HTML to PDF document

Scheduled Pinned Locked Moved Solved General and Desktop
webkitpdf5.5elementconvert
4 Posts 2 Posters 2.9k Views
  • 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.
  • S Offline
    S Offline
    Shidharth
    wrote on 1 Jun 2016, 09:04 last edited by
    #1

    Hi All,

    i am using qtwebkit 5.5 for convert HTML to PDF in that i want to partially convert HTML page to PDF by specifying HTML elements (div,Table,chart,image etc) instead of convert hole page for example i am having HTML page with more then one <div> content from that i want to convert any one of the div content as PDF by specifying its ID . please share your views .

    Thanks in advance.

    R 1 Reply Last reply 1 Jun 2016, 12:16
    0
    • S Shidharth
      1 Jun 2016, 09:04

      Hi All,

      i am using qtwebkit 5.5 for convert HTML to PDF in that i want to partially convert HTML page to PDF by specifying HTML elements (div,Table,chart,image etc) instead of convert hole page for example i am having HTML page with more then one <div> content from that i want to convert any one of the div content as PDF by specifying its ID . please share your views .

      Thanks in advance.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 1 Jun 2016, 12:16 last edited by
      #2

      @Shidharth
      The simplest solution would be to simply render the web widget (using QWidget::render() ) and print the resulting image. There is a lot of material about printing to PDF using Qt available on the web so i am sure you will find it yourself.

      QtWebKit: QWebView
      QtWebEngine:

      using QtWebKit (deprecated):

      QWebElement elem = myWebView->page()->mainFrame()->findFirstElement("#id");
      if( !elem.isNull() )
      {
           QPixmap pix( elem.geometry().size() );
           QPainter p( &pix );
           elem.render( &p );
           p.end();
      
          // print pixmap to pdf
      }
      

      using QtWebEngine:

      QWebEngineView* myWebView = new QWebEngineView;
      myWebView->load( url );
      
      // when loaded:
      QPixmap pix( myWebView->size() );
      myWebView->render( &pix );
      //print pixmap to pdf
      

      honestly i don't know if there is not a faster/better way using QtWebEngine though

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      1
      • S Offline
        S Offline
        Shidharth
        wrote on 2 Jun 2016, 09:34 last edited by
        #3

        @raven-worx

        Thanks for your replay

        is possible to convert particular HTML element to PDF without using pixmap because PDF text should be Selectable .

        R 1 Reply Last reply 3 Jun 2016, 05:49
        0
        • S Shidharth
          2 Jun 2016, 09:34

          @raven-worx

          Thanks for your replay

          is possible to convert particular HTML element to PDF without using pixmap because PDF text should be Selectable .

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 3 Jun 2016, 05:49 last edited by
          #4

          @Shidharth
          Maybe you can extract a QWebElement and insert it into a separate QWebView and use print(). But i think it may not look the same as in the origin QWebView.

          Also maybe there is a possible JavaScript way?

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0

          2/4

          1 Jun 2016, 12:16

          • Login

          • Login or register to search.
          2 out of 4
          • First post
            2/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved