How to write test into PDF file
Dear Experts,
I want to create a pdf file and the contents will vry dynamically. e.g i want to write like below
HEADINGS
1
DESCRIPTION
My description for 1
HEADINGS
2
DESCRIPTION
My description for 2 goes here
DESCRIPTION & HEADING are static text and description is dynamic input provided by user. it may b mail id or description about . i've a textedit control where user will provide the description.
Please let me know how to generate a pdf file and write my text into it.
I used QPrnter class. but i dont know when my text is exceeding a page, so that i can create a new page.
Thanks in advance for your help
Re: How to write test into PDF file
Refer this link... do similarly... http://doc.qt.digia.com/4.6/printing...ng-onto-a-page
Refer this link... do similarly... http://doc.qt.digia.com/4.6/printing...ng-onto-a-page
Added after 4 minutes:
QTextEdit from 4.3 onwards also has a convenience function QTextEdit::print(QPrinter *printer)Use something like, (not tested)
Code:
printer.setOutputFileName("print.ps");
painter.begin(&printer);
text.setText("ur text here");
text.print(&printer);
Re: How to write test into PDF file
Quote:
Originally Posted by
pkj
Hi,
Thanks for the reply. I tried like above code. I've passes .pdf instead of .ps file format. Though its generating file its not appending the text "ur text here inside the file.
If i go as per link, i've to draw text in my pdf file and i dont know when to create a new page, as the input text is dynamic for me. Please help.
Re: How to write test into PDF file
Just tried a simple example...
Code:
void MainWindow::printPdf()
{
printer.setOutputFileName("print.pdf");
ui->textEdit->print(&printer);
}
textEdit is a object in ui designer file mainWindow. Text edit is not a must. You can use QPainter or refer to the source of Qt to see how a QTextDocument is being used to print.