erbal
erbal

Reputation: 727

Generate a form to print out in Qt

I'm curious about how could I generate dinamically and programmatically a page to print out? I mean if I have strings, and for example a source image with a logo, how could I create a form?

Upvotes: 1

Views: 2017

Answers (4)

RobbieE
RobbieE

Reputation: 4360

If your code needs to add and remove details on the form, coding the low-level geometries for printing will be re-inventing the wheel. You can use the higher-level QTextDocument class to do all the layouts and resizing for you.

Once you've got that all coded in, you can convert to HTML or print to a QPrinter (including PDF).

Upvotes: 0

mhcuervo
mhcuervo

Reputation: 2660

If you're using Qt5 you can easily create a PDF file which I recommend. I include a very basic example but I recomend to check the documentation for QPainter and QPdfWriter.

QString fileName = tr("myfile.pdf");
QPdfWriter pdf(fileName);
QPainter painter(&pdf);
pdf.setPageSize(QPagedPaintDevice::Letter);

// Render whatever you want using the painter functions.

painter.end();

Upvotes: 1

gifnoc-gkp
gifnoc-gkp

Reputation: 1516

You don't have to reinvent the wheel. Many book writers including Beej use Apache FOP

Upvotes: 1

Pete
Pete

Reputation: 4812

You could either generate a PDF or an HTML webpage and print either (from withing Qt or externally).

Or you can directly print via QPainter.

Upvotes: 1

Related Questions