Generated PDF different on arm linux than on desktop linux



  • Hello,
    I am generated a PDF file from a QTextDocument, inserting a rectangular image from a jpeg file.
    I am using Qt5.2 alpha on both platforms. The code used to insert the image and generate the pdf file is exactly the same also. They are compiled with (mostly) the same config options (using the binary provided for x86 64 linux Qt5.1.1 shows the same problem).

    The PDF file from the arm linux target is different from the one generated from the ubuntu desktop. The images are different sizes. I tried setting the resolution at 72, 96 and even 1200 but the two documents are never the same.

    Can anyone see how to fix this?

    Thanks!

    Here is all the code. I used a rectangular image in jpeg format that contained a circle and square:

    @
    #include <iostream>
    #include <QApplication>
    #include <QPrinter>
    #include <QTextDocument>
    #include <QAbstractTextDocumentLayout>
    #include <QTextCursor>
    #include <QTextCharFormat>
    #include <QImage>

    const float DPI=72.0; // 96.0 // 72.0; //1200.0;

    void initPrinter(QPrinter& _printer)
    {
    _printer.setResolution(DPI);
    _printer.setOutputFormat(QPrinter::PdfFormat);
    _printer.setFullPage(true);
    _printer.setPaperSize(QPrinter::Letter);
    _printer.setOrientation(QPrinter::Portrait);
    }

    void initDoc(QTextDocument& _doc,QPrinter& _printer)
    {
    _doc.setUseDesignMetrics(true);
    _doc.documentLayout()->setPaintDevice(&_printer);
    _doc.setPageSize(QSizeF(_printer.pageRect().size()));
    }

    void makeDoc(QTextDocument& doc )
    {
    QTextCursor cursor(&doc);

    cursor.movePosition(QTextCursor::Down);
    QTextBlockFormat blockFormat=cursor.blockFormat();
    blockFormat.setAlignment(Qt::AlignHCenter);
    cursor.insertBlock(blockFormat);

    const QImage _image("shapes.jpeg");
    const float aspectRatio=float(_image.width())/float(_image.height());

    {
    // use the rectangular image's natural pixel dimensions
    std::cerr<<"image: natural pixel w="<<_image.width()<<" h="<<_image.height()<<std::endl;
    cursor.insertImage(_image);
    }

    {
    // put the image again with a desired WIDTH of 1.0 inch
    const float desiredWidth=1.0;
    const float desiredHeight= desiredWidth/aspectRatio;

    const int w=desiredWidthDPI;
    const int h=desiredHeight
    DPI;
    std::cerr<<"desired: w="<<desiredWidth<<" h="<<desiredHeight<<" target: w="<<w<<" h="<<h<<std::endl;

    // attempt to show the calculation is correct for the w and h with respect to DPI by ignoring the scaled() option
    cursor.insertImage(_image.scaled(w,h,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
    }

    {
    // put the image again with a desired HEIGHT of 1.0 inch
    const float desiredHeight= 1.0;
    const float desiredWidth=desiredHeight*aspectRatio;

    const int w=desiredWidthDPI;
    const int h=desiredHeight
    DPI;
    std::cerr<<"desired: w="<<desiredWidth<<" h="<<desiredHeight<<" target: w="<<w<<" h="<<h<<std::endl;

    // attempt to show the calculation is correct for the w and h with respect to DPI by ignoring the scaled() option
    cursor.insertImage(_image.scaled(w,h,Qt::IgnoreAspectRatio,Qt::SmoothTransformation));
    }
    }

    void printPDF(QPrinter& _printer,const QTextDocument& _doc,const std::string& _filename)
    {
    _printer.setOutputFileName(QString::fromStdString(_filename));
    _doc.print(&_printer);
    }

    int main(int argc, char *argv[])
    {
    QApplication app(argc, argv);

    QPrinter myPrinter;
    initPrinter(myPrinter);

    QTextDocument myDoc;
    initDoc(myDoc,myPrinter);

    makeDoc(myDoc);
    printPDF(myPrinter,myDoc,"doc.pdf");
    return 0;
    }

    @



  • I have no idea what the problem is, but you could make it easier for someone to see the problem if you a) besides telling that the sizes are different would tell what the sizes are... and b) post the actual PDF files.



  • Here is a link to the image file and 2 pdfs... one from an x86_64 ubuntu desktop and one from an embedded arm:

    https://www.dropbox.com/sh/8gohv4gwx1z7ilo/X-Gi9GM-of

    Thanks



  • It was suggested that maybe the platform-specific qpa may be noodling up the resolution, but since this is a pdf printer I would not know what to do about it.

    Does anyone have a workaround? I have tried many things but no joy. It is urgent to find a fix.

    I filed a bug report because the output should be the same:
    https://exchange.brukeroptics.com/exchweb/bin/redir.asp?URL=https://bugreports.qt-project.org/browse/QTBUG-34335

    Thanks,
    Vic



  • Does anyone have a suggestion?



  • A workaround perhaps? Anybody?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.