hi
How do I set a custom page/paper size in QPrinter?
hi
How do I set a custom page/paper size in QPrinter?
What about using QPrinter::setPaperSize(const QSizeF &paperSize, Unit unit)?
Sorry for bringing this up, but I'm using QT 4.8 and it doesn't let me use that function, even though it's still present in the documentation.
¿Any clues? I've set my pagesize to A7, but it's a little large, and I would like to be able to customize it, in case I have to change it...
EDIT: I've just set my default printer to adobe pdf to see the output and it completely ignored the size settings I made.
Last edited by LautaroMed; 25th July 2013 at 05:47.
What does "it doesn't let me use that function" mean, especially give that your next sentence says you could set the page size?
This, for example, compiles and runs fine under Qt 4.8.4:
Qt Code:
#include <QApplication> #include <QPrinter> #include <QPainter> int main(int argc, char **argv) { QPrinter printer; printer.setOutputFileName("test.pdf"); p.end(); return 0; }To copy to clipboard, switch view to plain text modeQt Code:
$ pdfinfo test.pdf Title: Creator: Producer: Qt 4.8.4 (C) 2011 Nokia Corporation and/or its subsidiary(-ies) CreationDate: Thu Jul 25 05:16:10 2013 Tagged: no Form: none Pages: 1 Encrypted: no Page size: 144 x 144 pts Page rot: 0 File size: 1358 bytes Optimized: no PDF version: 1.4To copy to clipboard, switch view to plain text mode
Last edited by ChrisW67; 25th July 2013 at 06:18.
I was using setPageSize I think.
Anyway, I tried your code, and in my pc it generates an A4 size PDF:
Qt Code:
[QTCLASS]Title: Creator: Producer: Qt 4.8.1 (C) 2011 Nokia Corporation and/or its subsidiary(-ies) CreationDate: 07/25/13 05:36:18 Tagged: no Form: none Pages: 1 Encrypted: no Page size: 212 x 284 pts File size: 1348 bytes Optimized: no PDF version: 1.4[/QTCLASS]To copy to clipboard, switch view to plain text mode
Here's the code I was using earlier:
Qt Code:
[QTCLASS] QTextDocument document; document.setHtml(strStream); QPrinter printer; qDebug() << printer.paperSize(); printer.setFullPage(false); document.print(&printer); [/QTCLASS]To copy to clipboard, switch view to plain text mode
The qDebug line prints "30", whatever that means...
You are setting a paper size of A7 which may not be valid for the default system printer. What does paperRect() return afterward?QPrinter::Custom 30 Unknown, or a user defined size.
The PDF size you gave, 212 x 284 pts, is 74.8 x 100.2 mm... a shade wider and a few mm shorter than A7 portrait.
QTextDocument maintains its own page size that may be passed to the printer.
Have you tried the most recent Qt 4.8?
paperRect() returns "QRect(0,0 283x378)"
I am setting paper size like this now:
Qt Code:
To copy to clipboard, switch view to plain text mode
I am using QT 4.8.1 because it's the only SDK I could find...
http://qt-project.org/downloads
There's a Qt 4.8.4 bundle suitable for use with the old SDK's GCC 4.4, and the MingW builds of Qt 5.1 come with a MingW GCC 4.8 toolchain included.
Bookmarks