Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with image in PDF using QTextDocument.

Problem with image in PDF using QTextDocument.

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fahmy
    wrote on 21 Dec 2012, 08:11 last edited by
    #1

    I'm using QTextDocument to print PDF file from HTML. But, the image was broken in the PDF file.

    This is HTML syntax:
    @<html><head></head><body><img src="file:///home/user/Pictures/avatar.jpg"></body></html>@

    And my Qt/C++ code is:

    @QPrinter printer;
    printer.setOrientation(QPrinter::Portrait);
    printer.setPaperSize(QPrinter::A4);
    printer.setResolution(300);
    printer.setFullPage(true);
    printer.setCopyCount(1);
    printer.setOutputFormat(QPrinter::PdfFormat);
    printer.setOutputFileName(location);

    QTextDocument document;
    document.setHtml(htmlText);
    document.print(&printer);@

    How can I fix this?

    Stay hungry, stay foolish.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      master of disaster
      wrote on 25 Dec 2012, 11:34 last edited by
      #2

      Try using Portable Network Graphics (.png) instead of JPEGs. I had several problems with JPEGs, too, and using PNGs fixed the problem.

      To convert your image, you could use any image manipulation program (e.g. GIMP), load the image and export it as Portable Network Graphic.

      1 Reply Last reply
      0

      1/2

      21 Dec 2012, 08:11

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved