PDF with QWebView

  • 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);


    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!

  • Moderators

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

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

  • Moderators

    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'>
    Can't display PDF file

  • @raven-worx said:
    No error message.

    Even with html doesn't works.

  • give some solution to resolve this issue.

  • Moderators

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

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.