简体   繁体   中英

QPrinter's PDF data, how to grab it?

As the title says, how do i grab the internal PDF data from QPrinter without going the extra mile of outputting to a temporary file and reading that in for further processing?

I have checked the documentation and found nothing what would let me do something like

QPrinter printer(QPrinter::HighResolution);
printer.setPageSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);

QTextDocument doc;    
doc.setHtml("<p>Test me!</p>");
doc.print(&printer);

QByteArray foo = printer.data();

Any ideas? :)

The only way I know would be by using QTemporaryFile

QPrinter printer(QPrinter::HighResolution);
printer.setPageSize(QPrinter::A4);
printer.setOutputFormat(QPrinter::PdfFormat);
QTemporaryFile pdf;
pdf.open();
printer.setOutputFileName(pdf.fileName());

QTextDocument doc;    
doc.setHtml("<p>Test me!</p>");
doc.print(&printer);

QByteArray foo = pdf.readAll();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM