Am 26.02.2014 04:02, schrieb Marcelo Estanislau Geyer:
It's possible load pdf file to QByteArray? The simple code below is not
work:

QFile file("/home/marcelo/Documents/test.pdf");
if (!file.open(QIODevice::ReadOnly)) {
    qDebug() << "file open error";
    return;
}

QByteArray ba_pdf = file.readAll();
qDebug() << ba_pdf;
file.close();

The output is:
"%PDF-1.4
1 0 obj
<<
/Title (þÿ)
/Creator (þÿ)
/Producer (þÿ

As you did not tell what you expected, I guess the character encoding differs, and the strings for /Creator, /Producer, ... should look different.

You might give this snippet a try:

    QFile file("/home/marcelo/Documents/test.pdf");
    if (!file.open(QIODevice::ReadOnly)) {
        qDebug() << "file open error";
        return;
    }

    // QByteArray ba_pdf = file.readAll();
    // qDebug() << ba_pdf;
    QTextStream ts(&file);
    ts.setCodec ("UTF-8");
    QString s_pdf = ts.readAll();
    qDebug() << s_pdf;

    file.close();

The "UTF-8" might need to be replaced by something else, depending on the encoding your file uses.

Best Regards / Mit freundlichen Grüßen
Rainer Wiesenfarth

--
Software Engineer | Trimble Imaging Division
Rotebühlstraße 81 | 70178 Stuttgart | Germany
Office +49 711 22881 0 | Fax +49 711 22881 11
http://www.trimble.com/imaging/ | http://www.inpho.de/

Trimble Germany GmbH, Am Prime Parc 11, 65479 Raunheim
Eingetragen beim Amtsgericht Darmstadt unter HRB 83893,
Geschäftsführer: Dr. Frank Heimberg, Hans-Jürgen Gebauer

Attachment: smime.p7s
Description: S/MIME Cryptographic Signature

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

Reply via email to