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. [Solved] Convert Text file to pdf file in Qt
QtWS25 Last Chance

[Solved] Convert Text file to pdf file in Qt

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 5.2k Views
  • 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.
  • B Offline
    B Offline
    beemaneni
    wrote on last edited by
    #1

    Hi Friends ,
    How do i convert text file to pdf file in Qt C++ ?
    What are the classes involved in it ?
    I need to convert text file to pdf file and print it ?

    Can Anyone help me please?

    Thanks in advance

    Bala Beemaneni

    Bala B
    Infinite Computer systems
    Chennai

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      There is no direct way to do this.

      @Either use the Poppler "here ":http://doc.qt.digia.com/qq/qq27-poppler.html

      or

      Use PdfWriter class like a paint device, read the contents of text file and write them to paint device using QPainter->drawText(...).@

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • IamSumitI Offline
        IamSumitI Offline
        IamSumit
        wrote on last edited by
        #3

        hii
        and also you can use QPrinter class.

        http://qt-project.org/doc/qt-4.8/qprinter.html

        Be Cute

        1 Reply Last reply
        0
        • B Offline
          B Offline
          beemaneni
          wrote on last edited by
          #4

          Hi Dheerendra , Iamsumit

          Thanks for the reply

          Do u mean C++ qt Cannot convert text file to pdf on its own?
          can u provide little more information on other ways of doing if u dont mind?

          Thanks
          Bala Beemaneni

          Bala B
          Infinite Computer systems
          Chennai

          1 Reply Last reply
          0
          • M Offline
            M Offline
            mikeosoft
            wrote on last edited by
            #5

            It's fairly well documented but this is how I would do it?

            This is just an off the top of my head, typed directly in rather than tried out attempt.

            Assume that doc_content is a QString variable that contains an HTML formatted string, if it isn't HTML formatted you could load it with .setPlainText().

            @QTextDocument doc;
            doc.setHtml(doc_content);

            QPrinter file;
            file.setOutputFormat(QPrinter::PdfFormat);
            file.setOutputFileName("myfile.pdf"); // better to use full path
            doc.print(file);@

            This isn't tested by me, so the capitalisation of the methods might not be right, but is should give an idea.

            1 Reply Last reply
            0
            • B Offline
              B Offline
              beemaneni
              wrote on last edited by
              #6

              hi mikesoft

              Thanks for ur reply.
              i could do with the help of this link.
              "Your text to link here...":http://www.essentialunix.org/index.php?option=com_content&view=article&id=47:generating-pdf-files&catid=34:qttutorials&Itemid=53

              Thanks
              Bala Beemaneni

              Bala B
              Infinite Computer systems
              Chennai

              1 Reply Last reply
              0
              • IamSumitI Offline
                IamSumitI Offline
                IamSumit
                wrote on last edited by
                #7

                This is nice link...
                hope your problem is solved .
                Pls don't forget to prepend your title as SOLVED.

                Be Cute

                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