Create A PDF From QT Creator - QT Forum
Create A PDF From QT Creator - QT Forum
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 8:31 (/post/493499)
Hi,
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName("AAA.pdf");
QPainter painter;
return 1;
}
else {
msg.setText("Printer Begin");
msg.exec();
}
painter.drawText(10, 10, "Primo PDF Creato!");
painter.drawText(10, 30, "Test 1");
i've also tried with this other code (Declarated QPdfWriter and QPainter):
QFile f("AAA.pdf");
f.open(QIODevice::WriteOnly);
writer->setPageSize(QPagedPaintDevice::A4);
writer->newPage();
delete p;
delete writer;
f.close();
No errors but..
1 Respuesta
0
1 de 26
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 1/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
Accede para responder (/login)
(/user/jsulm)
jsulm (/user/jsulm)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 9:30 (/post/493508)
@TheCipo76 (https://forum.qt.io/uid/43214) Are you sure the PDF file was not created? You're using a relative path,
that means the file will be created in current working directory.
1 Respuesta
0
(/user/asperamanca)
Asperamanca (/user/asperamanca)
16 nov 2018 9:36 (/post/493509)
setOutputFileName
Interesting. I use the QPrinter way, and the only difference to my code I spotted was that I explicitly set the page
margins and resolution. Also, I assume that you open the file for writing in your first code just as you do it in the
second one, right?
But try out the Text Edit example (in widgets\richtext) - it contains a PDF export.
1 Respuesta
0
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 10:09 (/post/493524)
@jsulm (https://forum.qt.io/uid/23827) i've searhced with finder and this is the result
(https://ddgobkiprc33d.cloudfront.net/07417895-0fce-45fd-b5ef-821a989ada49.png)
0
1 de 26
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 2/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 10:13 (/post/493525)
@Asperamanca (https://forum.qt.io/uid/4934)
No, i've followed a Video Tutorial and copy the same code
(https://www.youtube.com/watch?v=lA5D8b_QPxo (https://www.youtube.com/watch?v=lA5D8b_QPxo))
the only differences is that i've done it in a Dialog and not in MainWindows
i've already tried to create a new project and do it in MainWindows but the result is the same..
2 Respuestas
0
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 10:17 (/post/493526)
@TheCipo76 (https://forum.qt.io/uid/43214)
Hi
https://wiki.qt.io/Exporting_a_document_to_PDF (https://wiki.qt.io/Exporting_a_document_to_PDF)
1 Respuesta
0
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 10:28 (/post/493531)
0
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 13:46 (/post/493576)
@TheCipo76 (https://forum.qt.io/uid/43214)
1 Respuesta
0
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 14:12 (/post/493582)
@TheCipo76 (https://forum.qt.io/uid/43214)
Hi
1 Respuesta
0
1 de 26
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 3/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 14:20 (/post/493583)
QPrinter printer(QPrinter::PrinterResolution);
if(dialog.exec() == QDialog::Accepted){
QPrinterInfo pinfo(printer);
Printer State: 0
Printer seem to be OK
1 Respuesta
0
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 14:23 (/post/493585)
@TheCipo76 (https://forum.qt.io/uid/43214)
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
1 de 26
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 4/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
p p (Q );
printer.setOutputFileName("e:/test.pdf");
QPainter painter;
painter.begin(&printer);
1 Respuesta
0
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 14:28 (/post/493586)
1 Respuesta
0
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 14:32 (/post/493588)
@TheCipo76 (https://forum.qt.io/uid/43214)
Yep and i get a e:/test.pdf so not really sure why you dont get any.
void printv3() {
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName("test.pdf");
QPainter painter;
painter.begin(&printer);
painter.end();
(http://imagizer.imageshack.com/img924/8069/z29uDz.png)
1 de 26
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 5/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
(http://imagizer.imageshack.com/img924/6228/743C0R.png)
1 Respuesta
0
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 14:44 (/post/493590)
1 Respuesta
0
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 14:48 (/post/493592)
@TheCipo76 (https://forum.qt.io/uid/43214)
1 Respuesta
0
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 14:49 (/post/493593)
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName("test.pdf");
QPainter painter;
painter.begin(&printer);
painter.end();
0
1 de 26
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 6/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 14:50 (/post/493595)
1 Respuesta
0
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 14:51 (/post/493596)
@mrjj (https://forum.qt.io/uid/18260)
(https://ddgobkiprc33d.cloudfront.net/d3f65aa3-087a-44b4-a02d-40c6fcbca320.png)
1 Respuesta
0
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 14:55 (/post/493597)
@TheCipo76 (https://forum.qt.io/uid/43214)
Very odd.
void printv4() {
QPrinter printer(QPrinter::HighResolution);
printer.setOrientation(QPrinter::Landscape);
1 de 26
printer.setOutputFormat(QPrinter::PdfFormat);
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 7/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(fileName);
QPainter painter;
painter.begin(&printer);
i d()
1 Respuesta
2
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16 nov 2018 14:59 (/post/493598)
@mrjj (https://forum.qt.io/uid/18260)
(https://ddgobkiprc33d.cloudfront.net/2064bfda-f9c3-49ac-88cf-a15dd9380674.png)
(https://ddgobkiprc33d.cloudfront.net/6635a87c-3a15-4e38-9796-365956d80408.png)
1 Respuesta
1
(/user/thecipo76)
TheCipo76 (/user/thecipo76)
16
12018
nov de 26
15:02 (/post/493599)
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 8/10
7/9/2021 Create a PDF from Qt Creator | Qt Forum
(/user/mrjj)
mrjj (/user/mrjj)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
16 nov 2018 15:06 (/post/493600)
Super :)
1 Respuesta
0
(/user/mpergand)
mpergand (/user/mpergand)
16 nov 2018 17:30 (/post/493610)
printer.setOutputFileName("PrimoPDF.pdf");
When launched from QtCreator, the default working directory is set to:
MyApp/Contents/MacOS/
When launched from the finder, the path is usely the user directory, but actualy it is the root directory (/) and
obviously nothing is written (wrong permissions)
2
(/user/j-hilk)
J.Hilk (/user/j-hilk)
MODERATORS (/groups/moderators)
16 nov 2018 18:06 (/post/493615)
Super :)
/Users/yourUserName/Library/Application Support
0
(/user/dan1973)
dan1973 (/user/dan1973)
27 mar 2021 7:47 (/post/651837)
Hi,
I was following your comments and conversation. I need to know how to draw lines in PDF document using Qt.
1 Respuesta
0
(/user/jsulm)
jsulm (/user/jsulm)
LIFETIME QT CHAMPION (/groups/lifetime-qt-champion)
29 mar 2021 1:57 (/post/652022)
https://doc.qt.io/qt-5/qpainter.html#drawLine-2 (https://doc.qt.io/qt-5/qpainter.html#drawLine-2)
1
Accede para responder (/login)
1 de 26
https://forum.qt.io/topic/96672/create-a-pdf-from-qt-creator 10/10