[Interest] PDF to QByteArray

Constantin Makshin cmakshin at gmail.com
Fri Feb 28 04:48:51 CET 2014


If you want to test sending en email, send it an check what happens. Or,
at least, print the final (i.e. with all encoding and other things being
done, exactly what you'd send to an SMTP server) message. Don't try to
print a PDF file contents "as is" — it's not a 100% text-based format
and may contain anything, including null (\x00) bytes which would be
treated as string terminators by any conventional C/C++ string handling
functions, including [f]printf(), qDebug(), etc..

I looked inside a few PDF files found on my computer and in every file
containing those "/Title", "/Creator", ... tags they have the following
format:
/<tagName> (<bom><tagValue>)
where
<bom> — UTF-16 big-endian byte order mark "\xfe\xff" which, when printed
in CP1252 encoding [1], is seen as "þÿ" (exactly what you demonstrated
in your initial message);
<tagValue> — text in UTF-16 BE.

That means that your test file mentioned in OP has empty title and
creator fields, but when qDebug() reaches the producer field, it meets
the null byte from the first UTF-16 BE character, thinks it's a string
terminator and returns.

[1]
http://en.wikipedia.org/wiki/Byte_order_mark#Representations_of_byte_order_marks_by_encoding

On 02/28/2014 05:58 AM, Marcelo Estanislau Geyer wrote:
> 
> 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 (.psfile) 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?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20140228/f37e6297/attachment.sig>


More information about the Interest mailing list