Results 1 to 17 of 17

Thread: Why QPrinter always generates PDF docs with the same size?

  1. #1
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Why QPrinter always generates PDF docs with the same size?

    Hi, I need to use QPrinter to generate a PDF doc with several images (one image for page). I use the code below to generate a PDF doc with one image in one page, the problem is that the size of the resulting doc is extremely big (7 MB ). I've tried to set the resolution to the minimum resolution (72dpi) that supports the printer driver (PDFCreator) and the printer mode to "ScreenResolution" but it doesn't works. I also have tried to set to the maximum compresion of images in PDFCreator but it neither works. Very strange. Somebody could suggest me something else? Thanks.

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. QApplication a(argc, argv);
    4.  
    5. QPrinter printer(QPrinter::ScreenResolution);
    6. printer.setResolution(72);
    7. printer.setOutputFormat(QPrinter::PdfFormat);
    8. printer.setOutputFileName("../test.pdf");
    9. printer.setFullPage( TRUE );
    10. printer.setPageSize(QPrinter::A4);
    11. printer.setOrientation(QPrinter::Landscape);
    12.  
    13. QPainter painter;
    14. painter.begin(&printer);
    15. painter.drawImage(printer.pageRect(), QImage("../proba.jpg");
    16. painter.end();
    17.  
    18. return 0;
    19. }
    To copy to clipboard, switch view to plain text mode 

    PD: The original size of the test image ("proba.jpg") is 3368x2440 pix and it's in grayscale. But I also have tried to set the colorMode of the printer to graysCale but the resulting size is always the same
    Last edited by SkripT; 21st April 2006 at 10:09.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QPrinter always generates PDF docs with the same size?

    What is the volume of the image file? And in what format does the image get saved into the pdf? Maybe it's a png (don't ask me why)?

  3. #3
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Quote Originally Posted by wysota
    What is the volume of the image file?
    1,36 MB

    Quote Originally Posted by wysota
    And in what format does the image get saved into the pdf? Maybe it's a png (don't ask me why)?
    Maybe that's the problem: that it's saved in png or bmp. Is it a parameter that can be fixed with Qt or I have to set it with PDFCreator?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QPrinter always generates PDF docs with the same size?

    I don't know that. First check if it's saved as png/bmp. There are surely applications which can check that.

    Another possibility could be that the font embedding bloated the size a little too.

    Which Qt version do you use?

  5. #5
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    As I commented before I have set the option in PDFCreator to compress the PDF images in color and grayscale to "JPEG-Maximum" but it's like QPrinter doesn't use them because the final document is always the same (PDFCreator is the only driver that I have installed to do the conversion, so it has to use it ) Maybe QPrinter with QPainter uses some particular method to "insert" the images?

    PD: I use Qt4.1.1
    Last edited by SkripT; 21st April 2006 at 11:15.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QPrinter always generates PDF docs with the same size?

    I don't get one thing... If you're printing directly to PDF, what do you need PDFCreator for?

  7. #7
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Quote Originally Posted by wysota
    I don't get one thing... If you're printing directly to PDF, what do you need PDFCreator for?
    I thought it too, but I've tried to run the code above without having installed PDFCreator and I get a warning that QPrinter didn't found any correct driver

  8. #8
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Well I tried it by scaling the image to the correct size before painting it and the size of the final doc has been reduced a lot. The problem is that If I try to zoom the image, it loses a lot of quality. So I don't know why painting it directly in the correct rect dosen't works. All I want is have the original image fitting all the page in the final PDF doc and zoom it if it's greater than the page without losing quality (it's possible because if I enable setFullPage with QPrinter, the image is painted fitting all the page and it doesn't loses quality if I try to zoom it, the problem is that the resulting doc has a big size ). I think that internally the document stores the original image and shows it scaled fitting all the avaiable page space. Anybody knows how to make it?

    PD: Maybe the problem is that painting to a printer with QPainter is different than "inserting" directly an image to the PDF doc....
    Last edited by SkripT; 21st April 2006 at 14:23.

  9. #9
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Does anybody knows if there's some another way to print an image using QPrinter than painting it with QPainter. I'm almost sure that the problem that the final doc has a big size is caused by painting the image using QPainter. I think it "stores" it like if the images has no compression or something similar... All I want is have the same image than the original in the final PDF doc filling all the page space.
    Last edited by SkripT; 21st April 2006 at 17:54.

  10. #10
    Join Date
    Mar 2006
    Location
    Mountain View, California
    Posts
    489
    Thanks
    3
    Thanked 74 Times in 54 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Quote Originally Posted by SkripT
    I thought it too, but I've tried to run the code above without having installed PDFCreator and I get a warning that QPrinter didn't found any correct driver
    That's sounds very wrong to me. I just uninstalled my PDF driver (pdf995), then ran the Text Edit demo. I'm not having any problems exporting to PDF without a separate PDF driver.

  11. #11
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Quote Originally Posted by Brandybuck
    That's sounds very wrong to me. I just uninstalled my PDF driver (pdf995), then ran the Text Edit demo. I'm not having any problems exporting to PDF without a separate PDF driver.
    I don't understand this. What I'm sure is that before installing PDFCreator there wasn't any printer in my system and I've tried to run the code above and it alerted me that no driver was found (for sure). But nevermind, my real problem is that, with or without a printer driver, if i try to paint an image with QPainter under a QPrinter, the resulting doc has a big size
    I would like to know if there's some other way to convert a succesion of images into a PDF doc?
    Last edited by SkripT; 22nd April 2006 at 09:53.

  12. #12
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Well, I add a new post but I don't know if anyone can help me . I've installed Adobe Acrobat Reader 7.0 and has an option that allows working with the images of a PDF document. If I open the document created with Qt, the option is disabled. Otherwise, if I open another doc not created with Qt where the images are compressed, the option is enabled and allows extract the images of the doc. Maybe the problem is the driver that I use (PDfCreator). Anyone knows if there's some way to generate docs with QPrinter where the images are compressed? Can anyone check if, using Qt, can generate docs where the images are compressed using the code that I've posted above or some other way?
    Last edited by SkripT; 22nd April 2006 at 15:47.

  13. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QPrinter always generates PDF docs with the same size?

    It might be a good idea to take a look at the source code responsible for generating images in pdf files in Qt4. The answer for your problem may be there. If that doesn't help, writing to Trolltech is an option too. I doubt we'll be able to help much here...

  14. The following user says thank you to wysota for this useful post:

    SkripT (22nd April 2006)

  15. #14
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    If anybody is interested, I have asked my problem in Qt Interest mailing list, and the response from a trolltech's member is the following:
    The problem is not compression but the fact that the image is embedded
    multiple times, even though it is the same. You can either wait until Qt
    4.1.3, which will contain a fix for that, or you can try the current
    snapshots which should have it, too
    .
    So, finally seems that's just a bug... Does anybody knows how much should I have to wait until the next release?

  16. #15
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Why QPrinter always generates PDF docs with the same size?

    You can always use a snapshot as suggested.

  17. #16
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Quote Originally Posted by wysota
    You can always use a snapshot as suggested.
    Yes but I'm a little lazy to build it all (> 2hrs)

  18. #17
    Join Date
    Jan 2006
    Location
    Catalonia
    Posts
    266
    Thanks
    44
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Why QPrinter always generates PDF docs with the same size?

    Finally the Trolls have opened a new task tracker with my bug (ID: 111669): http://www.trolltech.com/developer/t...9&method=entry.
    I hope it will be fixed soon.

Similar Threads

  1. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 22:14

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.