Results 1 to 6 of 6

Thread: PDF resize?

  1. #1
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default PDF resize?

    Hi,

    I've got following problem: My app creates several different kind of PDFs and problem is that file sizes are way too large. The PDFs include pictures that cause the problem. After debugging a while, I found out that if I just scaled the pictures into smaller size (scaledToWidth() ), the PDF size would be ok. Now the problem is that the PDF is created with "highResolution" which I think is 1200dpi and if I reduce the picture size, it will not fill the whole PDF width. As a result, I think I need to set the resolution of the QPainter for example to 600dpi, so that the picture can be scaled to smaller size and it will still fill the whole PDF width. But this is easier said than done because there are so much small details in the PDF, adjusted just in the correct place. I just would not like to do it all again, for every PDF type.

    Is there any other way? Something that crossed my mind:

    1. Could I somehow rescale the PDF after it's ready?
    2. Copy PDF to another file with lower resolution?
    3. Set the resolution to 600dpi in the beginning, but somehow change the coordinate system so that even text is written with the highResolution (1200dpi) coordinates, it would be written correctly to the 600dpi PDF?
    4. Some other way?

    PS. I'm using Qt's internal PDF libraries.

    Cheers!

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

    Default Re: PDF resize?

    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: PDF resize?

    Yes, I've seen those already - actually using them. The problem is that those are not much of help after the last detail/line is written to the PDF, right? If I set the resolution smaller in the end, at least the file size does not decrease. I have noticed that using setResolution() with smaller resolution decreases the file size only if used at the beginning of the PDF creation, not at the end which is my target.

    I hope someone knows solution for this, otherwise it will take many days to get the PDFs recreated.

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

    Default Re: PDF resize?

    Quote Originally Posted by Mobility View Post
    The problem is that those are not much of help after the last detail/line is written to the PDF, right?
    It only makes sense to call it before sending anything to QPrinter. I don't understand why you'd want to call it after you're done sending data to the printer.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Solved: PDF resize?

    Ok, I got it solved by my self without changing the PDF resolution from HighResolution.

    I noticed that using scaledToWidth() for pictures did not affect to the PDF file size, so I first resized the photos to 1/5 of the original "highResolution" size. Then the for the pic which was 1/5 of the PDF width I used the scaledToWidth function to make it fill the whole PDF width. Because the scaledToWidth() does not increase the PDF file size, as a result, the PDF size is the same as if it was created only with 1/5 size photos. And to my eyes it seems that the quality of the picture in the PDF is still very good if PDF is looked at 100% size. Only if zoomed a lot you can see the difference so this is good enough for my purposes.

  6. #6
    Join Date
    Sep 2012
    Posts
    34
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Solved: PDF resize?

    I'm sorry I didn't remember the solution correctly and gave some wrong information. Basically this is how I got it solved:

    Qt Code:
    1. painter.scale(5, 5); // scaling 5x
    2. QImage scaled = ScalePic(pic, QString("W"), 1600); //this function uses scaletoWidth function and 1600 is PDF width / 5
    3. painter.drawImage(20, 100, scaled); // using 1/5 coordinates due to 5x scaling
    4. painter.scale(0.2, 0.2); // scaling set back to default so that following text prints can use the high resolution coordinates.
    To copy to clipboard, switch view to plain text mode 

    As a result the image quality is still very good for my purposes and the PDF size is a lot smaller, just like the pics were just 1/5 sized. Btw, I tried to use pics that were resized to the wanted size before using them in PDF, but it did not make any difference to the PDF size for some reason (pic size 7mb vs 250kb -> no difference).
    Last edited by Mobility; 9th May 2013 at 07:02.

Similar Threads

  1. Replies: 3
    Last Post: 11th December 2011, 10:09
  2. Replies: 1
    Last Post: 9th May 2011, 20:45
  3. How to resize QlistWidgetItems??
    By druidamix in forum Qt Programming
    Replies: 2
    Last Post: 20th September 2010, 00:39
  4. Replies: 1
    Last Post: 1st May 2010, 23:03
  5. Replies: 2
    Last Post: 22nd January 2008, 16:10

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
  •  
Qt is a trademark of The Qt Company.