[Interest] Creating pdf with QTextDocument with chart

Edward Sutton edward.sutton at subsite.com
Mon Oct 26 19:04:04 CET 2015


You can add image resources to a QTextDocument.



    QTextDocument textDocument;

    textDocument.setPageSize(QSizeF(m_pageWidth, m_pageHeight));


    QString htmlImageClient;

    QImage imageClient(this->m_model->jobInformation()->clientInfo.logoImagePath);

    if(false == imageClient.isNull())

    {

        htmlImageClient = QString("<img src=\"mydata://client.png\" align='left' height=\"%1\" />")

                          .arg(imageHeight);

        textDocument.addResource(QTextDocument::ImageResource,

                                 QUrl("mydata://client.png"), QVariant(imageClient));

    }

The QTextDocument to PDF approach works for Android, Windows, and OS X.  I expect Linux too.

If you need to generate PDF’s on iOS, you will need to find a non-Qt approach.  Unfortunately Qt PDF generation is implemented in QPrinter and iOS has no printer support.

-Ed


On Oct 26, 2015, at 11:28 AM, Duane <duane.hebert at group-upc.com<mailto:duane.hebert at group-upc.com>> wrote:

On 26/10/2015 12:07 PM, Jason H wrote:


I don't think 4.8 has the ability to paint images in a document.  It
looks like Qt5 would make a lot of this simpler.

If you read http://doc.qt.io/qt-4.8/richtext-html-subset.html You'll see it supports the <img> tag.


Yes but img requires a file name.  I'd have to create a png or jpg. Maybe.  I'll look into that.

_______________________________________________
Interest mailing list
Interest at qt-project.org<mailto:Interest at qt-project.org>
http://lists.qt-project.org/mailman/listinfo/interest

This email and any files transmitted with it from The Charles Machine Works, Inc. are confidential and intended solely for the use of the individual or entity to which they are addressed. If you have received this email in error please notify the sender. Our company accepts no liability for the contents of this email, or for the consequences of any actions taken on the basis of the information provided, unless that information is subsequently confirmed in writing. Please note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of the company. Finally, the recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20151026/d3313a27/attachment.html>


More information about the Interest mailing list