참고 페이지 : https://doc.qt.io/Qt-5/qtprintsupport-index.html / 

https://wiki.qt.io/Exporting_a_document_to_PDF  


#1 QTextDocument 를 생성하고 html 코드를 넣어준다.

QTextDocument doc;

doc.setHtml("<h1>Hello, World!2222</h1>\n<p>Lorem ipsum dolor sit amet, consectitur adipisci elit</p>");
//doc.setHtml(docString);

doc.setPageSize(printer.pageRect().size()); // This is necessary if you want to hide the page number


#2-1 생성한 doc를 가지고 pdf 저장하기.

QPrinter printer(QPrinter::PrinterResolution);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setPaperSize(QPrinter::A4);
printer.setOutputFileName(fileName);

doc.print(&printer);


#2-2 생성한 doc를 가지고 인쇄하기

QPrinter printer;
QPrintDialog popup(&printer);
if (popup.exec() == QDialog::Accepted) //인쇄 설정창에서 확인을 하면
{
    doc.print(&printer); //인쇄를 한다.
}




by 무위자연 2019. 2. 20. 15:25
| 1 |