Results 1 to 4 of 4

Thread: Decode base64 into PDF file

  1. #1
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default Decode base64 into PDF file

    I have a PDF file which has been encoded to base64. Now I want to convert these base64 script and write to a file to make a PDF file, I have try as following code:

    Qt Code:
    1. QByteArray data = QByteArray::fromBase64(ui->txtData->toPlainText().toAscii());
    2. QFile file("output.pdf");
    3. file.open(QIODevice::WriteOnly | QIODevice::Text);
    4. QTextStream out(&file);
    5. out << data;
    6. file.close();
    To copy to clipboard, switch view to plain text mode 

    It can create the PDF file but it can not be read, the Foxit Reader say that "format error". I check the data has been decoded and I found that some special character become "?". How could I get all the character out? Could anyone can give me a solution?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Decode base64 into PDF file

    QTextStream is for streaming textual data. PDF is binary data so it is not suited for QTextStream. Use QFile::write() instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    nhocjerry (31st July 2013)

  4. #3
    Join Date
    Jul 2013
    Posts
    9
    Thanks
    5

    Default Re: Decode base64 into PDF file

    Quote Originally Posted by wysota View Post
    QTextStream is for streaming textual data. PDF is binary data so it is not suited for QTextStream. Use QFile::write() instead.
    I use QFile::write() but it still error and I try QDataStream instead, it works fine now. Thank you!

  5. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Decode base64 into PDF file

    ... then you are doing it wrong. If QDataStream::writeRawData() works then QIODevice::write() must work: the former being a thin wrapper over the latter.

Similar Threads

  1. How can i decode binary base64
    By Askar in forum Qt Programming
    Replies: 1
    Last Post: 14th September 2009, 03:01
  2. QT Class to decode PDU data
    By cutie.monkey in forum Newbie
    Replies: 0
    Last Post: 4th July 2009, 05:52
  3. Replies: 5
    Last Post: 29th April 2009, 22:39
  4. Base64 vs Binay File format
    By rmagro in forum Qt Programming
    Replies: 4
    Last Post: 6th February 2009, 16:17
  5. To decode .ithmb files.
    By merry in forum Qt Programming
    Replies: 2
    Last Post: 10th January 2008, 07:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.