[Interest] PDF creation issues with QT5
Israel Brewster
israel at eraalaska.net
Thu Apr 4 19:48:46 CEST 2013
I am trying to create a PDF document using QT5 on Mac OS X 10.8. In Qt 4 I had the following code to accomplish this, which worked perfectly:
QPrinter *pdfPrinter=new QPrinter;
pdfPrinter->setOutputFileName(pdfFileName);
pdfPrinter->setPaperSize(printSize,QPrinter::Millimeter); //print size is determined from a QPageSetup dialog on a native printer
pdfPrinter->setPageMargins(.25, 1, .25, 1, QPrinter::Inch);
formattedReport->print(pdfPrinter); //formattedReport is a QTextDocument
delete pdfPrinter;
As I said, this code worked perfectly in Qt 4.x, allowing me to create a PDF of the QTextDocument at whatever paper size I want. I have now started working on moving this application to Qt5, and that section of code has stopped working. Depending on what I try, I get various different results:
1) use QPrinter without setting the page size.
Result: empty A4 sized PDF
2) use QPrinter, setting the paper size (using any combination of setPageSizeMM() and/or setPageSize(), attempting to get letter sized page).
Result: blank PDF of the proper page size
Note that in both of the cases above I verified my QTextDocument did contain the desired content by creating a QTextEdit, setting my QTextDocument as the document, and calling show on the QTextEdit.
3) use QPdfWriter without setting the page size.
Result: PDF with proper content, but A4 paper size. Closer, but no cigar as they say. I need to be able to select the paper size/orientation, not to mention that A4 paper is virtually unheard of around here (I believe it is standard in some parts of the world, but not mine :) )
4) use QPdfWriter, setting paper size using any combination of setPageSizeMM() and/or setPageSize(), attempting for letter.
Result: PDF containing the correct (I think) content, but with a page size of 1.02"x1.46" (I believe that roughly corresponds to A10 paper size, or 26x37 mm)
Some additional notes on that last test: When setting the paper size using the setPageSizeMM() function, I used a QSizeF object with values of ht=279.39 and wd=215.89. For the setPageSize() function I used the QPagedPaintDevice::Letter constant. In both cases I verified the size actually set by viewing the results of the pageSizeMM() function in the debugger. Before calling the sizing function, my QPdfWriter returned a size of 297x210, or A4 (as expected from result of test 3). After using the setPageSizeMM() function, the pageSizeMM() function returns the correct values of 279.39x215.89. After a call to setPageSize() with the Letter constant, pageSizeMM() shows the default value of 297x210 again (perhaps that's expected, in that the MM sizes are only used for custom paper size?). Regardless, in all cases where I set the page size, the final output ends up at 26x37mm, in spite of what the pageSizeMM() function shows.
So what am I missing here? What do I need to change to get my code that worked in Qt4 to work in Qt5? Thanks.
-----------------------------------------------
Israel Brewster
Computer Support Technician II
Era Alaska
5245 Airport Industrial Rd
Fairbanks, AK 99709
(907) 450-7250 x7293
-----------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130404/676ed722/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Israel Brewster.vcf
Type: text/directory
Size: 417 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130404/676ed722/attachment.bin>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20130404/676ed722/attachment-0001.html>
More information about the Interest
mailing list