Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Need to partially convert HTML to PDF document

    General and Desktop
    webkit pdf 5.5 element convert
    2
    4
    2433
    Loading More Posts
    • 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
      Shidharth last edited by

      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.

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Shidharth last edited by

        @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 Reply Quote 1
        • S
          Shidharth last edited by

          @raven-worx

          Thanks for your replay

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

          raven-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @Shidharth last edited by

            @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 Reply Quote 0
            • First post
              Last post