How to reading PDF file with QTextEdit



  • Hello friends, I want to ask you, I want to read the text contained in the PDF file. How do I do that? Previously I've tried using QByteArray, it can not. This code uses QByteArray:

    QString getFile = "/home/rnd/Instalasi.pdf";
    QFile file(getFile);
    QByteArray pdfFile = file.readAll();
    qDebug() << pdfFile;

    Output:

    "%PDF-1.4
    %äüöß
    2 0 obj
    <</Length 3 0 R/Filter/FlateDecode>>
    stream
    x��W�n�0 ��+|.0�H-���{�������n��@s���%y��L�9�X��G���D�c���c


  • Qt Champions 2016

    @Renn
    Hello,
    PDFs are binary structured files, so you'll have to parse the contents to extract the text. Wikipedia provides an overview of the file structure for different versions. There might be some packages (libraries) that could be used to read PDF contents, and my advice is to research which one of them might (possibly) be of use to you.

    Kind regards.


  • Qt Champions 2016

    HI
    Besides uses a library as @kshegunov suggest, you could also use
    cmdline tool to run on pdf and it saves text to file.
    This one
    http://www.foolabs.com/xpdf/download.html
    has pdftotext tool.


  • Lifetime Qt Champion

    Hi,

    There's an interesting Wiki article here about PDF handling.


Log in to reply
 

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