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. How to reading PDF file with QTextEdit

How to reading PDF file with QTextEdit

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 3.0k Views 3 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.
  • R Offline
    R Offline
    Renn
    wrote on last edited by Renn
    #1

    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

    kshegunovK 1 Reply Last reply
    0
    • R Renn

      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

      kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

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

      Read and abide by the Qt Code of Conduct

      1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

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