Make sure you open the file in binary mode. PS files are text, PDFs have both 
text and binary modes. Default is binary.

QFile f("file.pdf");
QByteArray ba;

if (f.open (QIODevice::ReadOnly))
{
   ba = file.readAll();
}

Should be all you need.




________________________________
 From: Marcelo Estanislau Geyer <estanisge...@hotmail.com>
To: "interest@qt-project.org" <interest@qt-project.org> 
Sent: Thursday, February 27, 2014 8:58 PM
Subject: Re: [Interest] PDF to QByteArray
 




So that they can understand, I need to put the contents of a pdf file into a 
QByteArray, as this QByteArray is used as an attachment in the email sending 
process.

I did a test with a postscript file (.ps file) and it worked perfectly. I only 
have this problem with pdf files.
How can I read and properly store the content (binary) of a pdf file into a 
QByteArray?


_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest
_______________________________________________
Interest mailing list
Interest@qt-project.org
http://lists.qt-project.org/mailman/listinfo/interest

Reply via email to