Create and write into a PDF File
-
@Eddy Yes.
@Wieland
Thanks for your answers.
I am not sure about the arguments in painter.drawText().
When i run the programm and press the button, QT says "QPainter::begin(): Returned false
Could you help me with that?void MainWindow::writePdf()
{
const QString filename("D://Programme/QT/MeineProjekte/Projekt/test.pdf");QString testData = "test"; QPdfWriter pdfwriter(filename); pdfwriter.setPageSize(QPageSize(QPageSize::A4)); QPainter painter(&pdfwriter); painter.drawText(0,0, testData);
}
-
Hi, it seems to be 2 slashes after D:, maybe try
``const QString filename("`D:/Programme/QT/MeineProjekte/Projekt/test.pdf");``` -
Hi, it seems to be 2 slashes after D:, maybe try
``const QString filename("`D:/Programme/QT/MeineProjekte/Projekt/test.pdf");```Thanks a lot. It works now.
-
Hi I want to create a program that will create a pdf file with a logo/image to it. using a QPrintPreviewDialog, QPixmap, QPrint, QDialog.
-
@mrjj
thanks
I still having error.
This is my code
void MainWindow::on_pushButton_createpdf_clicked()
{
QPrintPreviewDialog dialog;
QPainter painter(this);
connect(&dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
dialog.exec();
painter.setPen(Qt::black);
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");
painter.end();
painter.drawPixmap (C:\User\Downloads\logo.png);
} -
@mrjj
thanks
I still having error.
This is my code
void MainWindow::on_pushButton_createpdf_clicked()
{
QPrintPreviewDialog dialog;
QPainter painter(this);
connect(&dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
dialog.exec();
painter.setPen(Qt::black);
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");
painter.end();
painter.drawPixmap (C:\User\Downloads\logo.png);
} -
@mrjj
thanks
I still having error.
This is my code
void MainWindow::on_pushButton_createpdf_clicked()
{
QPrintPreviewDialog dialog;
QPainter painter(this);
connect(&dialog, SIGNAL(paintRequested(QPrinter*)), this, SLOT(print(QPrinter*)));
dialog.exec();
painter.setPen(Qt::black);
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");
painter.end();
painter.drawPixmap (C:\User\Downloads\logo.png);
}@drich said in Create and write into a PDF File:
painter.end();
painter.drawPixmap (C:\User\Downloads\logo.png);I guess
painter.end();
should be last line and
painter.drawPixmap (C:\User\Downloads\logo.png);
is not valid C++. Should be:
painter.drawPixmap ("C:/User/Downloads/logo.png");
-
@drich said in Create and write into a PDF File:
painter.end();
painter.drawPixmap (C:\User\Downloads\logo.png);I guess
painter.end();
should be last line and
painter.drawPixmap (C:\User\Downloads\logo.png);
is not valid C++. Should be:
painter.drawPixmap ("C:/User/Downloads/logo.png");
-
@drich Hi,
what kind of an error?
Have you read the QPainter documentation? -
@artwaw it says error: no matching function for call to 'QPainter::drawPixmap(const char [52])'
-
@artwaw hi, I remove the painter.Pixmap and I run my program I clicked the createpdf button and it show a blank paper it didn't show this
painter.setPen(Qt::black);
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila"); -
@artwaw in the painter.drawPixmap
drawPixmap was underlined and it note "Too few arguments"
what does it means?
@drich That means that you passed too few arguments to the method. Please refer to the documentation I linked in one of my previous posts - in that webpage together with a quite detailed overview on how to use QPainter there is also a list of the methods provided. You will see that QPainter::drawPixmap comes in many variants with different arguments list so you can choose the one that best suits your needs.
It seems to me that taking a look at Paint System would also bring you some significant benefits in terms of overall understanding how to accomplish what you aim for. -
@artwaw hi, I remove the painter.Pixmap and I run my program I clicked the createpdf button and it show a blank paper it didn't show this
painter.setPen(Qt::black);
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "Technological University of the Philipines - Manila");@drich I think that is because you have not had supplied a valid rectangle area which tells QPainter::drawText() where to draw. Please refer to the documentation I linked above to learn how to draw on widgets. It would be more helpful and consistent than explaining every detail in here.
-
@drich That means that you passed too few arguments to the method. Please refer to the documentation I linked in one of my previous posts - in that webpage together with a quite detailed overview on how to use QPainter there is also a list of the methods provided. You will see that QPainter::drawPixmap comes in many variants with different arguments list so you can choose the one that best suits your needs.
It seems to me that taking a look at Paint System would also bring you some significant benefits in terms of overall understanding how to accomplish what you aim for.