PDA

View Full Version : How to print pdf file?



surwassu
6th June 2011, 08:53
Hi ,
I want to print pdf file using QPrintDialog .
I have a file menu in which two actions are :open & print
alongwith i have a text editor to display contents of file to be printed
open action will open document eg.text,pdf,html ..& set text editor value to contents of file..& then I am using following code to print
<code>

QTextDocument *document = editor->document();//line 1
//editor is QTextedit object used to show contents of file ...
QPrinter printer;
QPrintDialog *dlg = new QPrintDialog(&printer, this);
if (dlg->exec() != QDialog::Accepted)
return;

document->print(&printer);




<\code>

line 1 is working fine for text document
for pdf doc it shows some junk things ,according to me it is not properly converting pdf to textedit...
In this case is there any way??
otherwise any api which accepts file location for printing so that i can directly give file location & use print function.

Thanking you.
Regards,
Sumit

ChrisW67
6th June 2011, 09:09
QTextDocument is for editing text documents. A PDF file is not a text document. If you want to render a PDF file to a printer then you will need to use a third-party library (e.g. Poppler) to read the PDF file and produce something you can print. The answer hasn't really changed since the first time you asked: 42061

BTW: They should be
tags

surwassu
6th June 2011, 09:43
42061[/thread]





hi ChrisW67,
The thread http://www.qtcentre.org/showthread.php?t=42061 is another its not same.
It was about postscript conversion ,here my point is how should messaged my printer to accept pdf file like
document() function will return QTextdocument pointer to hold text data,like wise is there any function to
hold pdf data that can be directly send via print() function.


You have suggested me third party library poppler can u give any links or forum toknow more about poppler
easily?

thanks.