C++ (Qt)#include <QApplication>#include <QPrinter>#include <QTextEdit>#include <QFile>#include <QTextCodec> int main(int argc, char *argv[]){ QApplication a(argc, argv); QTextCodec::setCodecForCStrings(QTextCodec::codecForName("UTF-8")); QTextEdit te; QFile file("C:\\bash.txt"); if (file.open(QFile::ReadOnly)) te.setText(QString(file.readAll())); QPrinter printer; printer.setOutputFileName( "C:\\bash.pdf" ); printer.setFromTo(2, 2); te.print( &printer ); return 0; //return a.exec();}
public slots: void print();private slots: void preview(QPrinter *printer);
void zakaz::print() //печать{ ////---печать---//// QPrinter printer; printer.setOrientation(QPrinter::Portrait); printer.setPageSize(QPrinter::A4); printer.setPaperSize(QSize(210,297),QPrinter::Millimeter); printer.setPageMargins(20,10,0,0,QPrinter::Millimeter); printer.setFromTo(1,1); QPrintPreviewDialog previewD( &printer, this ); connect( &previewD, SIGNAL(paintRequested(QPrinter *) ), this, SLOT(preview(QPrinter *))); previewD.showMaximized(); previewD.setWindowTitle("Предпросмотр"); previewD.exec();
void zakaz::preview(QPrinter *printer){QPainter painter; painter.begin(printer); painter.setRenderHint(QPainter::Antialiasing, true);//здесь рисую текст painter.end();