void MultiLayer::exportToEPS(const QString& fname, int res, QPrinter::Orientation o, QPrinter::PageSize pageSize, QPrinter::ColorMode col) { QPrinter printer; printer.setResolution(res); printer.setPageSize(pageSize); printer.setColorMode(col); printer.setOrientation(o); printer.setFullPage(TRUE); printer.setOutputToFile (TRUE); printer.setOutputFileName(fname); QPainter paint(&printer); QPaintDeviceMetrics pdmTo(&printer); int dpiy = pdmTo.logicalDpiY(); int margin = (int) ( (0.5/2.54)*dpiy ); // 5 mm margins QSize size = canvas->size(); double scaleFactorX=(double)(pdmTo.width() - 2*margin)/(double)size.width(); double scaleFactorY=(double)(pdmTo.height() - 2*margin)/(double)size.height(); for (int i=0;i<(int)graphsList->count();i++) { Graph *gr=(Graph *)graphsList->at(i); Plot *myPlot= (Plot *)gr->plotWidget(); PrintFilter filter(myPlot); filter.setOptions(QwtPlotPrintFilter::PrintAll | QwtPlotPrintFilter::PrintTitle | QwtPlotPrintFilter::PrintCanvasBackground); QPoint pos=gr->pos(); pos=QPoint(int(margin + pos.x()*scaleFactorX),int(margin + pos.y()*scaleFactorY)); int width=int(myPlot->frameGeometry().width()*scaleFactorX); int height=int(myPlot->frameGeometry().height()*scaleFactorY); QRect rect = QRect(pos,QSize(width,height)); if (myPlot->paletteBackgroundColor() != QColor(white)) paint.fillRect(rect, myPlot->paletteBackgroundColor()); int lw = myPlot->lineWidth(); if ( lw > 0) { myPlot->printFrame(&paint, rect); rect.moveBy ( lw, lw); rect.setWidth(rect.width() - 2*lw); rect.setHeight(rect.height() - 2*lw); } myPlot->print(&paint, rect, filter); } if (hasOverlapingLayers()) updateTransparency(); }
bool KDReports::Report::exportToFile( const QString& fileName, QWidget* parent ) { d->ensureLayouted(); QPrinter printer; d->setupPrinter( &printer ); printer.setOutputFileName( fileName ); const bool ret = d->doPrint( &printer, parent ); printer.setOutputFileName( QString() ); return ret; }
bool KDReports::Report::exportToFile( const QString& fileName, QWidget* parent ) { d->ensureLayouted(); QPrinter printer; printer.setOutputFileName( fileName ); // must be done before setupPrinter, since it affects DPI setupPrinter( &printer ); const bool ret = d->doPrint( &printer, parent ); printer.setOutputFileName( QString() ); return ret; }
int main(int argc, char** argv) { Genome* g(new Genome()); std::string fileName; if (argc > 1) { fileName = argv[1]; } else { fileName = "out.sam"; } g->read(fileName); QApplication app(argc, argv); LinearPlot lp(); auto seed = g->getReadAt(1, 1); assume(seed != nullptr, "Error, no read found!"); lp.setSceneRect(0, 0, 1200, 300); lp.fromRead(seed, g); QGraphicsView view(&lp); view.setWindowTitle("Chipboard demo v0.0.1"); view.show(); QPrinter printer; printer.setPaperSize(QSize(view.width(), view.height()), QPrinter::Point); printer.setFullPage(true); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName("plot.pdf"); QPainter pdfPainter; pdfPainter.begin(&printer); view.render(&pdfPainter); return app.exec(); }
void MultiLayer::exportVector(const QString &fileName, int res, bool color, bool keepAspect, QPrinter::PageSize pageSize, QPrinter::Orientation orientation) { Q_UNUSED(res); if (fileName.isEmpty()) { QMessageBox::critical(this, tr("Error"), tr("Please provide a valid file name!")); return; } QPrinter printer; printer.setDocName(this->name()); printer.setCreator("AlphaPlot"); printer.setFullPage(true); printer.setOutputFileName(fileName); if (fileName.contains(".eps")) printer.setOutputFormat(QPrinter::PostScriptFormat); if (color) printer.setColorMode(QPrinter::Color); else printer.setColorMode(QPrinter::GrayScale); if (pageSize == QPrinter::Custom) printer.setPaperSize(canvas->size(), QPrinter::Point); else { printer.setOrientation(orientation); printer.setPaperSize(pageSize); } exportPainter(printer, keepAspect); }
void KexiReportView::slotExportAsPdf() { QScopedPointer<KoReportRendererBase> renderer(m_factory.createInstance("print")); if (renderer) { KoReportRendererContext cxt; cxt.destinationUrl = getExportUrl(QLatin1String("application/pdf"), xi18n("Export Report as PDF"), "kfiledialog:///LastVisitedPDFExportPath/", "pdf"); if (!cxt.destinationUrl.isValid()) { return; } QPrinter printer; QPainter painter; printer.setOutputFileName(cxt.destinationUrl.path()); printer.setOutputFormat(QPrinter::PdfFormat); printer.setColorMode(QPrinter::Color); painter.begin(&printer); cxt.printer = &printer; cxt.painter = &painter; if (!renderer->render(cxt, m_reportDocument)) { KMessageBox::error(this, xi18n("Exporting the report as PDF to %1 failed.", cxt.destinationUrl.toDisplayString()), xi18n("Export Failed")); } else { openExportedDocument(cxt.destinationUrl); } } }
void ribi::braw::QtPrintRatingDialog::Print(const std::string& filename) { QPrinter printer; printer.setOrientation(QPrinter::Portrait); printer.setPaperSize(QPrinter::A4); printer.setFullPage(false); printer.setOutputFileName(filename.c_str()); //Draw the image to painter to printer (?must be done before printing) QPainter painter; painter.begin(&printer); { //Collect widgets to print const std::vector<QWidget *> widgets = CollectWidgets(); int y = 0; for (QWidget * const widget: widgets) { const int h = widget->height(); if (y+h > painter.window().height()) { printer.newPage(); y = 0; } widget->render(&painter,QPoint(0,y)); y+=h; } } painter.end(); }
void MainWindow::saveAllSheetsToPDF(QString &fileName) { QPrinter *printer = new QPrinter(QPrinter::PrinterResolution); printer->setOutputFormat(QPrinter::PdfFormat); printer->setOutputFileName(fileName); printAllSheets(printer); }
void MainWindowController:: exportToPDF() { QString fileName = QFileDialog::getSaveFileName(nullptr, tr("Choose PDF location"), "", tr("PDF File(*.pdf)")); QPrinter prn; prn.setOutputFileName(QString(fileName)); //QPrintDialog(&prn, mainWindow).exec(); prn.setOrientation(QPrinter::Landscape); QPainter painter; painter.begin(&prn); double x = this->view->getUi()->gameLayout_2->width(); painter.translate(prn.paperRect().x() + 20, prn.paperRect().y()+20); this->view->getUi()->gameLayout_2->render(&painter); painter.translate(prn.paperRect().x() + x, prn.paperRect().y()); QFont font; font.setPixelSize(12); painter.setFont(font); for (int i = 0 ; i < this->view->getUi()->definitionWidget->count() ; i++) { painter.drawText(QPoint(10,10),this->view->getUi()->definitionWidget->item(i)->text() ); if(i %40 == 0&&i>1) { painter.translate(QPoint(prn.paperRect().x()+200, -600)); } else { painter.translate(QPoint(prn.paperRect().x(), prn.paperRect().y()+15)); } } }
void MainWindow::doPrintParameterStatistic() { if ( gv_PS.count() > 0 ) { QTextDocument textDocu; QPrinter printer; QPrintDialog printDialog( &printer, this ); printer.setOrientation( QPrinter::Landscape ); if ( printDialog.exec() == QDialog::Accepted ) { QFileInfo fi( gsl_FilenameList.at( 0 ) ); QFont textFont = QFont( gf_HeaderTextFont.family(), 10, 0, false ); printer.setOutputFileName( tr( "" ) ); textDocu.setHtml( createParameterStatisticOutputText( fi.fileName(), gv_PS ) ); textDocu.setDefaultFont( textFont ); textDocu.print( &printer ); } update(); } setStatusBar( tr( "Done" ), 2 ); }
void PageScreen::saveAsDocument(const QString &format) { const QString &suffix = QLatin1Char('.') + format.toLower(); QString pathWithoutSuffix = ui->location->text(); if (pathWithoutSuffix.endsWith(suffix, Qt::CaseInsensitive)) { pathWithoutSuffix = pathWithoutSuffix.mid(0, pathWithoutSuffix.length() - suffix.length()); } QPrinter printer; printer.setCreator(QupZilla::tr("QupZilla %1 (%2)").arg(QupZilla::VERSION, QupZilla::WWWADDRESS)); printer.setOutputFileName(pathWithoutSuffix + suffix); printer.setOutputFormat(QPrinter::PdfFormat); printer.setPaperSize(m_pageImages.first().size(), QPrinter::DevicePixel); printer.setPageMargins(0, 0, 0, 0, QPrinter::DevicePixel); printer.setFullPage(true); QPainter painter; painter.begin(&printer); for (int i = 0; i < m_pageImages.size(); ++i) { const QImage &image = m_pageImages.at(i); painter.drawImage(0, 0, image); if (i != m_pageImages.size() - 1) { printer.newPage(); } } painter.end(); }
void Dialog::on_button_clicked() { const QString filename = "CppQPrinterExample2.pdf"; //Set up a QPrinter QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOrientation(QPrinter::Portrait); printer.setPaperSize(QPrinter::A4); printer.setFullPage(false); printer.setOutputFileName(filename); //Grab the window const QImage image = QPixmap::grabWindow(this->winId()).toImage(); //Draw the image to painter to printer QPainter painter; painter.begin(&printer); painter.drawImage(0,0,image); painter.end(); //Start the printer boost::shared_ptr<QPrintDialog> dialog(new QPrintDialog(&printer)); dialog->exec(); }
void Matrix::exportVector(const QString& fileName, int res, bool color) { if ( fileName.isEmpty() ){ QMessageBox::critical(this, tr("QtiPlot - Error"), tr("Please provide a valid file name!")); return; } QPrinter printer; printer.setCreator("QtiPlot"); printer.setFullPage(true); if (res) printer.setResolution(res); printer.setOutputFileName(fileName); if (fileName.contains(".eps")) printer.setOutputFormat(QPrinter::PostScriptFormat); if (color) printer.setColorMode(QPrinter::Color); else printer.setColorMode(QPrinter::GrayScale); printer.setOrientation(QPrinter::Portrait); int cols = numCols(); int rows = numRows(); QRect rect = QRect(0, 0, cols, rows); printer.setPaperSize(QSizeF(cols, rows), QPrinter::DevicePixel); QPainter paint(&printer); paint.drawImage(rect, d_matrix_model->renderImage()); paint.end(); }
void QgsComposition::beginPrintAsPDF( QPrinter& printer, const QString& file ) { printer.setOutputFormat( QPrinter::PdfFormat ); printer.setOutputFileName( file ); printer.setPaperSize( QSizeF( paperWidth(), paperHeight() ), QPrinter::Millimeter ); QgsPaintEngineHack::fixEngineFlags( printer.paintEngine() ); }
//------------------------------------------------------------------------- void QGuidoItemContainer::exportToPdf(const QString& fileName) { QPrinter printer; printer.setFullPage(true); printer.setOutputFileName( fileName ); printer.setOutputFormat( QPrinter::PdfFormat ); exportToPdf( &printer ); }
void SchedulePrintDialog::savePdf() { QPrinter printer; setupPdfPrinter(printer); QString fileName = QFileDialog::getSaveFileName(this, "Choose File Name for Pdf", QString(), "Pdf Documents (*.pdf)" ); printer.setOutputFileName( fileName ); doPrint(&printer); }
void StressPlotter::postscript(QString fname, float w, float h) { QPrinter printer; printer.setPaperSize(QSizeF(w, h), QPrinter::Point); printer.setOutputFormat(QPrinter::PostScriptFormat); printer.setOutputFileName(fname); // can override to pdf if not .ps QPainter p(&printer); drawStress(&p, (int)w, int(h), true); }
void OpenInfraPlatform::UserInterface::Alignment2DScene::exportToFile(QWidget* parent) { QString filter; QString fn = QFileDialog::getSaveFileName(parent, tr("Save Vertical Alignment as..."), QString(), tr("PNG File (*.png);; JPG File (*.jpg);; PDF File (*.pdf);; SVG File (*.svg)"), &filter); if(fn.isEmpty()) return; if(filter == "PNG File (*.png)" || filter == "JPG File (*.jpg)") { QImage image(sceneRect().size().toSize(), QImage::Format::Format_ARGB32); image.fill(Qt::darkGray); QPainter painter(&image); painter.setRenderHints(QPainter::Antialiasing); render(&painter); image.save(fn); } else { QPrinter printer; QSvgGenerator svgGen; QPaintDevice* device; if(filter == "PDF File (*.pdf)") { printer.setResolution(QPrinter::HighResolution); printer.setPageSize( QPrinter::A4 ); printer.setOrientation( QPrinter::Landscape ); printer.setOutputFormat( QPrinter::PdfFormat ); printer.setOutputFileName(fn); device = &printer; } else if(filter == "SVG File (*.svg)") { QRectF rect = sceneRect(); svgGen.setFileName(fn); svgGen.setSize(QSize(rect.width(),rect.height())); svgGen.setViewBox(QRect(0,0,rect.width(),rect.height())); svgGen.setTitle("Vertical Alignment"); device = &svgGen; } else { return; } QPainter painter(device); configureColors(A2D_DrawState::A2D_Print); render(&painter); configureColors(A2D_DrawState::A2D_Draw); } }
void KDReports::ReportPrivate::debugLayoutToPdf( const char* fileName ) { // for calling from gdb QFile html( QFile::decodeName( fileName ) + QLatin1String( ".html" ) ); Q_ASSERT( html.open( QIODevice::WriteOnly ) ); const QString htmlText = m_layout->toHtml(); html.write( htmlText.toUtf8() ); html.close(); bool oldLayoutDirty = true; m_pageContentSizeDirty = false; QPrinter printer; q->setupPrinter( &printer ); printer.setOutputFileName( QFile::decodeName( fileName ) ); doPrint( &printer, 0 ); printer.setOutputFileName( QString() ); m_pageContentSizeDirty = oldLayoutDirty; }
//------------------------------------------------------------------------- void MainWindow::exportRect(const QRectF& exportRectangle , const QString& fileName , const QString& fileType ) { QList<QLanguageItem*> selectedItems = selectedLanguageItems(); unselectAll(); QPainter painter; if ( fileType == PNG_FILE_FILTER ) { int result = QResolutionDialog( exportRectangle , EXPORT_MIN_DETAIL , EXPORT_MAX_DETAIL , EXPORT_DEFAULT_DETAIL , EXPORT_DETAIL_TO_SCALE_FACTOR ).exec(); if ( result ) { //Create a new QImage, with a size corresponding to the Guido Score page QSizeF size( exportRectangle.width() , exportRectangle.height() ); size.setWidth( result * EXPORT_DETAIL_TO_SCALE_FACTOR * size.width() ); size.setHeight( result * EXPORT_DETAIL_TO_SCALE_FACTOR * size.height() ); QImage image( size.width() , size.height() , QImage::Format_ARGB32); image.fill( QColor(Qt::white).rgb() ); painter.begin( &image ); //Paint in the QImage paintSceneRect( exportRectangle , &painter ); painter.end(); image.save( fileName , "PNG" ); } } else if ( ( fileType == PDF_FILE_FILTER ) || ( fileType == PS_FILE_FILTER ) ) { QPrinter printer; printer.setFullPage(true); printer.setOutputFileName( fileName ); if ( fileType == PS_FILE_FILTER ) { printer.setOutputFormat( QPrinter::PostScriptFormat ); } else if ( fileType == PDF_FILE_FILTER ) { printer.setOutputFormat( QPrinter::PdfFormat ); } printer.setPaperSize( QSizeF( exportRectangle.width() , exportRectangle.height() ) , QPrinter::Millimeter ); painter.setWindow( exportRectangle.toRect() ); painter.begin( &printer ); paintSceneRect( exportRectangle , &painter ); painter.end(); } for ( int i = 0 ; i < selectedItems.size() ; i++ ) selectedItems[i]->setSelected(true); }
bool UBExportPDF::persistsDocument(UBDocumentProxy* pDocumentProxy, const QString& filename) { QPrinter pdfPrinter; qDebug() << "exporting document to PDF" << filename; pdfPrinter.setOutputFormat(QPrinter::PdfFormat); pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); pdfPrinter.setOutputFileName(filename); pdfPrinter.setFullPage(true); //need to calculate screen resolution QDesktopWidget* desktop = UBApplication::desktop(); int dpiCommon = (desktop->physicalDpiX() + desktop->physicalDpiY()) / 2; float scaleFactor = 72.0f / dpiCommon; QPainter pdfPainter; bool painterNeedsBegin = true; int existingPageCount = pDocumentProxy->pageCount(); for(int pageIndex = 0 ; pageIndex < existingPageCount; pageIndex++) { UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex); UBApplication::showMessage(tr("Exporting page %1 of %2").arg(pageIndex + 1).arg(existingPageCount)); // set background to white, no crossing for PDF output bool isDark = scene->isDarkBackground(); bool isCrossed = scene->isCrossedBackground(); scene->setBackground(false, false); QSize pageSize = scene->nominalSize(); // set high res rendering scene->setRenderingQuality(UBItem::RenderingQualityHigh); scene->setRenderingContext(UBGraphicsScene::NonScreen); //setting page size to appropriate value pdfPrinter.setPaperSize(QSizeF(pageSize.width()*scaleFactor, pageSize.height()*scaleFactor), QPrinter::Point); if(painterNeedsBegin) painterNeedsBegin = !pdfPainter.begin(&pdfPrinter); //render to PDF scene->render(&pdfPainter, QRectF(), scene->normalizedSceneRect()); if (pageIndex < existingPageCount - 1) pdfPrinter.newPage(); //restore screen rendering quality scene->setRenderingContext(UBGraphicsScene::Screen); scene->setRenderingQuality(UBItem::RenderingQualityNormal); //restore background state scene->setBackground(isDark, isCrossed); } if(!painterNeedsBegin) pdfPainter.end(); return true; }
void UBExportFullPDF::saveOverlayPdf(UBDocumentProxy* pDocumentProxy, const QString& filename) { if (!pDocumentProxy || filename.length() == 0 || pDocumentProxy->pageCount() == 0) return; //PDF qDebug() << "exporting document to PDF Merger" << filename; QPrinter pdfPrinter; pdfPrinter.setOutputFormat(QPrinter::PdfFormat); pdfPrinter.setResolution(UBSettings::settings()->pdfResolution->get().toInt()); pdfPrinter.setOutputFileName(filename); pdfPrinter.setFullPage(true); QPainter* pdfPainter = 0; for(int pageIndex = 0 ; pageIndex < pDocumentProxy->pageCount(); pageIndex++) { UBGraphicsScene* scene = UBPersistenceManager::persistenceManager()->loadDocumentScene(pDocumentProxy, pageIndex); // set background to white, no grid for PDF output bool isDark = scene->isDarkBackground(); bool isCrossed = scene->isCrossedBackground(); scene->setBackground(false, false); // set high res rendering scene->setRenderingQuality(UBItem::RenderingQualityHigh); scene->setRenderingContext(UBGraphicsScene::PdfExport); QSize pageSize = scene->nominalSize(); UBGraphicsPDFItem *pdfItem = qgraphicsitem_cast<UBGraphicsPDFItem*>(scene->backgroundObject()); if (pdfItem) mHasPDFBackgrounds = true; pdfPrinter.setPaperSize(QSizeF(pageSize.width()*mScaleFactor, pageSize.height()*mScaleFactor), QPrinter::Point); if (!pdfPainter) pdfPainter = new QPainter(&pdfPrinter); if (pageIndex != 0) pdfPrinter.newPage(); //render to PDF scene->setDrawingMode(true); scene->render(pdfPainter, QRectF(), scene->normalizedSceneRect()); //restore screen rendering quality scene->setRenderingContext(UBGraphicsScene::Screen); scene->setRenderingQuality(UBItem::RenderingQualityNormal); //restore background state scene->setDrawingMode(false); scene->setBackground(isDark, isCrossed); } if (pdfPainter) delete pdfPainter; }
void CapturePrinter::print(const QImage &image, const QString &defaultPath) { QPrinter printer; printer.setOutputFileName(defaultPath); printer.setOutputFormat(QPrinter::NativeFormat); QPrintDialog printDialog(&printer, 0); if (printDialog.exec() == QDialog::Accepted) { printCapture(image, &printer); } }
bool Phantom::renderPdf(const QString &fileName) { QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); printer.setResolution(PHANTOMJS_PDF_DPI); QVariantMap paperSize = m_paperSize; if (paperSize.isEmpty()) { const QSize pageSize = m_page.mainFrame()->contentsSize(); paperSize.insert("width", QString::number(pageSize.width()) + "px"); paperSize.insert("height", QString::number(pageSize.height()) + "px"); paperSize.insert("border", "0px"); } if (paperSize.contains("width") && paperSize.contains("height")) { const QSizeF sizePt(ceil(stringToPointSize(paperSize.value("width").toString())), ceil(stringToPointSize(paperSize.value("height").toString()))); printer.setPaperSize(sizePt, QPrinter::Point); } else if (paperSize.contains("format")) { const QPrinter::Orientation orientation = paperSize.contains("orientation") && paperSize.value("orientation").toString().compare("landscape", Qt::CaseInsensitive) == 0 ? QPrinter::Landscape : QPrinter::Portrait; printer.setOrientation(orientation); static const struct { QString format; QPrinter::PaperSize paperSize; } formats[] = { { "A3", QPrinter::A3 }, { "A4", QPrinter::A4 }, { "A5", QPrinter::A5 }, { "Legal", QPrinter::Legal }, { "Letter", QPrinter::Letter }, { "Tabloid", QPrinter::Tabloid } }; printer.setPaperSize(QPrinter::A4); // Fallback for (uint i = 0; i < sizeof(formats) / sizeof(formats[0]); ++i) { if (paperSize.value("format").toString().compare(formats[i].format, Qt::CaseInsensitive) == 0) { printer.setPaperSize(formats[i].paperSize); break; } } } else { return false; } const qreal border = paperSize.contains("border") ? floor(stringToPointSize(paperSize.value("border").toString())) : 0; printer.setPageMargins(border, border, border, border, QPrinter::Point); m_page.mainFrame()->print(&printer); return true; }
void CapturePrinter::printPreview(const QImage &image, const QString &defaultPath) { QPrinter printer; printer.setOutputFileName(defaultPath); printer.setOutputFormat(QPrinter::NativeFormat); QPrintPreviewDialog printDialog(&printer); connect(&printDialog, &QPrintPreviewDialog::paintRequested, [this, image](QPrinter *p) { printCapture(image, p); }); printDialog.exec(); }
void Printer::createPdf() { QString fileName = QFileDialog::getSaveFileName(this, tr("export pdf file"), QString(), "* .pdf"); if (!fileName.isEmpty()) { if (QFileInfo(fileName).suffix().isEmpty()) { fileName.append(".pdf"); } QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); ui->textEdit->print(&printer); } }
void data_plot::savePDF() { if (save_file_name.length() > 0) { QPrinter printer; printer.setOutputFormat(QPrinter::PdfFormat); printer.setOrientation(QPrinter::Landscape); printer.setOutputFileName((save_file_name + ".pdf").c_str()); printer.setCreator("Aluminizer2"); myPlot.print(printer); } }
void MainWindow::on_actionSave_Document_triggered() { QString fileName = QFileDialog::getSaveFileName(this, "Save document...", qApp->applicationDirPath(), "*.pdf"); if (!fileName.isEmpty()) { QPrinter printer; printer.setFullPage(true); printer.setPaperSize(QPrinter::A4); printer.setOrientation(QPrinter::Portrait); printer.setOutputFormat(QPrinter::PdfFormat); printer.setOutputFileName(fileName); ui->textEdit->document()->print(&printer); } }
void GraphicsView::print() { QPrinter printer; if (QPrintDialog(&printer).exec() == QDialog::Accepted) { // printer自带的filedialog不能用, 原因未知, 所以手动加了一个 QString filename = QFileDialog::getSaveFileName(this,"filename",QString(),QString("pdf Files (*.pdf)")); printer.setOutputFileName(filename); QPainter painter(&printer); painter.setRenderHint(QPainter::Antialiasing); //开始打印 render(&painter); } }
/*! * \fn FormSimularCuotas::pdf() * Genera un pdf con las cuotas tal cual se ingresaron en los datos. */ void FormSimularCuotas::pdf() { this->generaReporte(); QPrinter *imp = new QPrinter( QPrinterInfo::defaultPrinter() ); imp->setOutputFormat( QPrinter::PdfFormat ); QString nombreArchivo = QFileDialog::getSaveFileName( this, "Guardar como pdf", QDir::homePath(), "Archivos PDF (*.pdf)" ); if( !nombreArchivo.isEmpty() ) { // ver que tenga la extension imp->setOutputFileName( nombreArchivo ); documento->print( imp ); } delete imp; }