AdvancedPdf::PaperSize AdvancedPdf::paperSize(QPrinter::PaperSize paperSize)
{
    QPrinter pr;
    pr.setOutputFormat(QPrinter::PdfFormat);
    pr.setPaperSize(paperSize);
    QSizeF s = pr.paperSize(QPrinter::Point);
    PaperSize p = { qRound(s.width()), qRound(s.height()) };
    return p;
}
Example #2
0
//-------------------------------------------------------------------------
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);
}
Example #3
0
void SvgCanvas::export_to_pdf_ps(int width, int height, QString filename)
{
	QPainter plot;
	QPrinter p;
	p.setFullPage(true);
	p.setPageSize(QPrinter::Custom);
	if( filename.endsWith(".pdf") )
		p.setOutputFormat(QPrinter::PdfFormat);
	else
		p.setOutputFormat(QPrinter::PostScriptFormat);
	p.setOutputFileName(filename);
	plot.begin(&p);
	svg_plot->renderer()->render(&plot);
	plot.end();
}
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);
}
Example #5
0
int Printer::setOutputFormat(lua_State * L) // (  OutputFormat format )
{
	QPrinter* lhs = ValueBinding<MyQPrinter>::check( L, 1 );
	QPrinter::OutputFormat f=(QPrinter::OutputFormat)Util::toInt( L, 2 );
	lhs->setOutputFormat( f );
	return 0;
}
Example #6
0
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();
}
Example #7
0
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();
}
Example #8
0
/**
 * Methode permettant d'imprimer un document
 */
void ValidDocument::print(){

    QWebView webView;
    QPrinter printer ;

    printer.setPageSize(QPrinter::A4);
    printer.setFullPage(true);
    QString type=(docType==Document::Facture)?QObject::trUtf8("Facture"):QObject::trUtf8("Devis");
    printer.setDocName(type+"_"+QString::number(id) );
    printer.setCreator(QObject::trUtf8("QFacturation"));
    printer.setOutputFormat(QPrinter::NativeFormat);

    webView.setHtml(view);
    webView.show();
    QPrintDialog printDialog(&printer);
    if(printDialog.exec() == QDialog::Accepted) {
        qDebug("Ne fonctionne pas sous windows")<<" Hack ....";

        #if defined(Q_WS_WIN)
            QTextDocument text;
            text.setHtml(view);
            text.print(&printer);
        #endif
        #if defined(Q_WS_QWS)
            webView.print(&printer);
        #endif
        #if defined(Q_WS_X11)
            webView.print(&printer);
        #endif
    }

}
Example #9
0
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();
}
Example #10
0
bool ignsystem::print(const QVariant &config) {
  QVariantMap configuration = jsonParse->jsonParser(config).toVariantMap();
  QPrinter printer;
  QTextDocument *document = new QTextDocument();
  QPrintDialog *printDialog = new QPrintDialog(&printer);

  QString type = configuration[QStringLiteral("type")].toString();
  QString content = configuration[QStringLiteral("content")].toString();
  QString output = configuration[QStringLiteral("out")].toString();

  if (type == QLatin1String("html")) {
    document->setHtml(content);
  } else {
    document->setPlainText(content);
  }

  if (output == QLatin1String("pdf")) {
    printer.setOutputFormat(QPrinter::PdfFormat);
  }

  if (printDialog->exec() == QDialog::Accepted) {
    document->print(&printer);
    delete document;
    return true;
  } else {
    return false;
  }
}
Example #11
0
void MainWindow::saveAllSheetsToPDF(QString &fileName)
{
    QPrinter *printer = new QPrinter(QPrinter::PrinterResolution);
    printer->setOutputFormat(QPrinter::PdfFormat);
    printer->setOutputFileName(fileName);
    printAllSheets(printer);
}
Example #12
0
bool ignsystem::print(const QVariant &config){
    QVariantMap conf = jsonParse->jsonParser(config).toVariantMap();
    QPrinter print;
    QTextDocument *doc = new QTextDocument();

    QString type = conf["type"].toString();
    QString txt = conf["content"].toString();
    QString out = conf["out"].toString();

    if(type == "html")
    {
        doc->setHtml(txt);
    }
    else
    {
        doc->setPlainText(txt);
    }

    if(out == "pdf"){
        print.setOutputFormat(QPrinter::PdfFormat);
    }

    QPrintDialog *dialog = new QPrintDialog(&print);
    if (dialog->exec() != QDialog::Accepted)
    {
        return false;
    }
    else
    {
        doc->print(&print);
        delete doc;
        return true;
    }
}
Example #13
0
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);
        }
   }
}
Example #14
0
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();
}
Example #15
0
//-------------------------------------------------------------------------
void QGuidoItemContainer::exportToPdf(const QString& fileName)
{
	QPrinter printer;
	printer.setFullPage(true);
	printer.setOutputFileName( fileName );
	printer.setOutputFormat( QPrinter::PdfFormat );
	exportToPdf( &printer );
}
Example #16
0
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() );
}
Example #17
0
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 SchedulePrintDialog::setupPdfPrinter( QPrinter & printer )
{
	printer.setOutputFormat( QPrinter::PdfFormat );
	setupPrinter(printer);

	printer.setFullPage( true );
	printer.setResolution( mDpiSpin->value() );
	printer.setFontEmbeddingEnabled(false);
}
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);
	}
}
Example #20
0
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;
}
Example #21
0
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;
}
Example #22
0
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);
    }
}
Example #23
0
void PrintDialog::sPrint()
{
	QPrinter printer;
	printer.setOutputFormat(QPrinter::PdfFormat);
	QPrintDialog printDialog(&printer, this);
	printDialog.setWindowTitle(tr("Print Document"));
	if (printDialog.exec() != QDialog::Accepted)
		return;

	m_ui.m_text_edit->print(&printer);
}
Example #24
0
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;
}
Example #25
0
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();
}
Example #26
0
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);
	}
}
Example #27
0
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);
  }
}
Example #28
0
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);
  }
}
Example #29
0
/*!
 * \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;
}
Example #30
0
void printerInvoice::printf(const QString &html)
{
	QPrinter p;
	QTextDocument doc;
	QFont font = doc.defaultFont();
	font.setBold(true);
	font.setPointSize(font.pointSize());
	doc.setDefaultFont(font);
	QSizeF s = QSizeF(p.logicalDpiX() * 7.5, p.logicalDpiY() * 7.5);
	doc.setPageSize(s);
	p.setOutputFormat(QPrinter::NativeFormat);
	doc.setHtml(html);
	doc.print(&p);
}