导出文本pdf文件

时间:2022-04-11 23:09:46

出口手续往往是一些数据需求,学习文本导出到今天pdf文件。主要用于QPrinter,QPainter

TextEditToPdf::TextEditToPdf(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
ui.setupUi(this);
int ret = connect(ui.m_pExportBtn,SIGNAL(clicked()),this,SLOT(exportSlot()));
} TextEditToPdf::~TextEditToPdf()
{ } void TextEditToPdf::exportSlot()
{ QTextDocument textDocument;
QPrinter printer(QPrinter::ScreenResolution);
printer.setPaperSize(QPrinter::A4);
printer.setPageMargins(30,30,30,30,QPrinter::DevicePixel);
printer.setOutputFormat(QPrinter::PdfFormat);
printer.setOutputFileName(QString("11") + ".pdf");
QPainter painter( &printer );
QFont font;
font.setPixelSize(15);
painter.setFont(font);
QTextOption textOption( Qt::AlignCenter);
QPen pen;
pen.setColor(Qt::black);
pen.setWidth(1);
painter.setPen(pen); int paperWidth = printer.width();
int paperHeigth = printer.height(); painter.drawText( QRect(QPoint( 30,30),QPoint(paperWidth - 30,paperHeigth- 20)),ui.m_pTextEdit->toPlainText (),textOption);
textDocument.print(&printer); }

导出文本pdf文件

导出文本pdf文件

版权声明:本文博客原创文章。博客,未经同意,不得转载。