Qt Forum

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

    Qt Academy Launch in California!

    Unsolved PDF with QWebView

    General and Desktop
    4
    7
    3831
    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.
    • L
      LucaLimido last edited by

      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-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @LucaLimido last edited by 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.)

        --- 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 Reply Quote 0
        • L
          LucaLimido @raven-worx last edited by

          @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-worx 1 Reply Last reply Reply Quote 0
          • raven-worx
            raven-worx Moderators @LucaLimido last edited by 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>
            

            --- 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 Reply Quote 0
            • L
              LucaLimido @raven-worx last edited by LucaLimido

              @raven-worx said:
              No error message.

              Even with html doesn't works.

              1 Reply Last reply Reply Quote 0
              • G
                Gaurav Badgujar last edited by

                give some solution to resolve this issue.

                jsulm 1 Reply Last reply Reply Quote -3
                • jsulm
                  jsulm Lifetime Qt Champion @Gaurav Badgujar last edited by

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