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. PDF with QWebView
Forum Updated to NodeBB v4.3 + New Features

PDF with QWebView

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 4.5k 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
    LucaLimido
    wrote on last edited by
    #1

    Hi
    I need to display a PDF in a QWebView. I already tried various solutions proposed in other topic but i could not make them work.

    This is my code:

    QString strUrl = QString("file:///C:/pdf/pdf-test.pdf");
    QUrl xUrl (strUrl);

    QWebSettings * pxWebSettings = QWebSettings::globalSettings();
    pxWebSettings->setAttribute(QWebSettings::PluginsEnabled, true);
    pxWebSettings->setAttribute(QWebSettings::JavascriptEnabled, true);
    pxWebSettings->setAttribute(QWebSettings::LocalContentCanAccessFileUrls, true);

    m_pxRfmView->setUrl(xUrl);
    m_pxRfmView->show();

    N.B. m_pxRfmView is my QWebView and i user qt 5.3

    I create QTWEBKIT_PLUGIN_PATH and MOZ_PLUGIN_PATH environmental variables with "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Browser".
    I create MY_APP/plugins folder and i put in nppdf32.dll (is the same dll that is presnet into "Acrobat Reader DC\Reader\Browser" directory.

    I alo tried with QPrinter but doesn't work.

    can someone help me?
    Thanks in advanced!

    raven-worxR 1 Reply Last reply
    0
    • L LucaLimido

      Hi
      I need to display a PDF in a QWebView. I already tried various solutions proposed in other topic but i could not make them work.

      This is my code:

      QString strUrl = QString("file:///C:/pdf/pdf-test.pdf");
      QUrl xUrl (strUrl);

      QWebSettings * pxWebSettings = QWebSettings::globalSettings();
      pxWebSettings->setAttribute(QWebSettings::PluginsEnabled, true);
      pxWebSettings->setAttribute(QWebSettings::JavascriptEnabled, true);
      pxWebSettings->setAttribute(QWebSettings::LocalContentCanAccessFileUrls, true);

      m_pxRfmView->setUrl(xUrl);
      m_pxRfmView->show();

      N.B. m_pxRfmView is my QWebView and i user qt 5.3

      I create QTWEBKIT_PLUGIN_PATH and MOZ_PLUGIN_PATH environmental variables with "C:\Program Files (x86)\Adobe\Acrobat Reader DC\Reader\Browser".
      I create MY_APP/plugins folder and i put in nppdf32.dll (is the same dll that is presnet into "Acrobat Reader DC\Reader\Browser" directory.

      I alo tried with QPrinter but doesn't work.

      can someone help me?
      Thanks in advanced!

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @LucaLimido
      one idea to also explicitly set the mime-type:

      m_pxRfmView->setContent(pdfFiledata, "application/pdf");
      

      This has the disadvantage to load the whole PDF file into memory first. (Which is no problem for smaller sized PDF files.)

      --- 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

      L 1 Reply Last reply
      0
      • raven-worxR raven-worx

        @LucaLimido
        one idea to also explicitly set the mime-type:

        m_pxRfmView->setContent(pdfFiledata, "application/pdf");
        

        This has the disadvantage to load the whole PDF file into memory first. (Which is no problem for smaller sized PDF files.)

        L Offline
        L Offline
        LucaLimido
        wrote on last edited by
        #3

        @raven-worx Thank you for reply.
        I tried your solution but in my case doesn't work.
        With my code or with your solution i see only the background (dark grey) . it seems that QWebView load the pdf file but it can't display

        raven-worxR 1 Reply Last reply
        0
        • L LucaLimido

          @raven-worx Thank you for reply.
          I tried your solution but in my case doesn't work.
          With my code or with your solution i see only the background (dark grey) . it seems that QWebView load the pdf file but it can't display

          raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by raven-worx
          #4

          @LucaLimido
          i would then expect a error message inside the PDF plugin?
          But i don't know how the plugin behaves in such case.

          One last try using HTML:

          <object src="http://link.to/your.pdf" width="800" height="600" type='application/pdf'>
          <!---Fallback--->
          Can't display PDF file
          </object>
          

          --- 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

          L 1 Reply Last reply
          0
          • raven-worxR raven-worx

            @LucaLimido
            i would then expect a error message inside the PDF plugin?
            But i don't know how the plugin behaves in such case.

            One last try using HTML:

            <object src="http://link.to/your.pdf" width="800" height="600" type='application/pdf'>
            <!---Fallback--->
            Can't display PDF file
            </object>
            
            L Offline
            L Offline
            LucaLimido
            wrote on last edited by LucaLimido
            #5

            @raven-worx said:
            No error message.

            Even with html doesn't works.

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Gaurav Badgujar
              wrote on last edited by
              #6

              give some solution to resolve this issue.

              jsulmJ 1 Reply Last reply
              -3
              • G Gaurav Badgujar

                give some solution to resolve this issue.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Gaurav-Badgujar At least a "Please" would be nice - we are not in army here and people do it in their own time for free.

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                5

                • Login

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