コード例 #1
0
bool MReportViewer::printGhostReport()
{
  if (report == 0)
    return false;

  int cnt = report->pageCount();

  if (cnt == 0)
    return false;

  QString outPsFile(AQ_DISKCACHE_DIRPATH + "/outprint.ps");
  QFile::remove(outPsFile);
  int backupNumCopies = numCopies_;
  numCopies_ = 1;
  if (!printReportToPS(outPsFile)) {
    numCopies_ = backupNumCopies;
    return false;
  }
  numCopies_ = backupNumCopies;

  bool gsPrintOk = false;
  QProcess *procTemp = new QProcess();
  procTemp->addArgument("gsprint");
  procTemp->addArgument("-help");
  gsPrintOk = procTemp->start();
  delete procTemp;

  QProcess *proc = new QProcess();
  if (gsPrintOk) {
    proc->addArgument("gsprint");
    proc->addArgument("-color");
    proc->addArgument("-query");
    proc->addArgument("-from");
    proc->addArgument("1");
    proc->addArgument("-to");
    proc->addArgument(QString("%1").arg(cnt));
    proc->addArgument("-copies");
    proc->addArgument(QString("%1").arg(numCopies_));
    //proc->addArgument("-q");
    //proc->addArgument("-dBATCH");
    //proc->addArgument("-dNOPAUSE");
    proc->addArgument(outPsFile);
  } else {
    QString setupPsFile(AQ_DISKCACHE_DIRPATH + "/setup.ps");
    QFile::remove(setupPsFile);
    QFile fileSetup(setupPsFile);

    if (fileSetup.open(IO_WriteOnly)) {
      QTextStream stream(&fileSetup);
      stream << "mark" << "\n";
      stream << "  /NoCancel      true" << "\n";
      if (!printerName_.isEmpty()) {
        QString pName("  /OutputFile      (%printer%");
        pName += printerName_ + ")";
        stream << pName << "\n";
      }
      stream << "  /BitsPerPixel  24" << "\n";
      stream << "  /UserSettings" << "\n";
      stream << "    <<" << "\n";
      stream << "      /DocumentName  (AbanQ document)" << "\n";
      stream << QString("      /DocumentRange [1 %1]").arg(cnt) << "\n";
      stream << QString("      /SelectedRange [1 %1]").arg(cnt) << "\n";
      stream << QString("      /MaxResolution %1").arg(dpi_) << "\n";
      stream << QString("      /Copies %1").arg(numCopies_) << "\n";
      stream << "    >>" << "\n";
      stream << "  (mswinpr2) finddevice" << "\n";
      stream << "  putdeviceprops" << "\n";
      stream << "setdevice" << "\n";
      if ((QPrinter::PageSize) report->pageSize() == QPrinter::Custom) {
        QSize sz(report->pageDimensions());
        stream << QString("<< /PageSize [%1 %2] /ImagingBBox null >> setpagedevice")
               .arg(sz.width())
               .arg(sz.height())
               << "\n";
      }
      fileSetup.close();
    }

    proc->addArgument(aqApp->gsExecutable());
    proc->addArgument("-q");
    proc->addArgument("-dBATCH");
    proc->addArgument("-dNOPAUSE");
    proc->addArgument("-dNODISPLAY");
    proc->addArgument(QString("-r%1").arg(dpi_));

    switch ((QPrinter::PageSize) report->pageSize()) {
      case QPrinter::A0:
        proc->addArgument("-sPAPERSIZE=a0");
        break;
      case QPrinter::A1:
        proc->addArgument("-sPAPERSIZE=a1");
        break;
      case QPrinter::A2:
        proc->addArgument("-sPAPERSIZE=a2");
        break;
      case QPrinter::A3:
        proc->addArgument("-sPAPERSIZE=a3");
        break;
      case QPrinter::A4:
        proc->addArgument("-sPAPERSIZE=a4");
        break;
      case QPrinter::A5:
        proc->addArgument("-sPAPERSIZE=a5");
        break;
      case QPrinter::B0:
        proc->addArgument("-sPAPERSIZE=b0");
        break;
      case QPrinter::B1:
        proc->addArgument("-sPAPERSIZE=b1");
        break;
      case QPrinter::B2:
        proc->addArgument("-sPAPERSIZE=b2");
        break;
      case QPrinter::B3:
        proc->addArgument("-sPAPERSIZE=b3");
        break;
      case QPrinter::B4:
        proc->addArgument("-sPAPERSIZE=b4");
        break;
      case QPrinter::B5:
        proc->addArgument("-sPAPERSIZE=b5");
        break;
      case QPrinter::Legal:
        proc->addArgument("-sPAPERSIZE=legal");
        break;
      case QPrinter::Letter:
        proc->addArgument("-sPAPERSIZE=letter");
        break;
      case QPrinter::Executive:
        proc->addArgument("-sPAPERSIZE=executive");
        break;
      default: {
        QSize sz(report->pageDimensions());
        proc->addArgument(QString("-dDEVICEWIDTHPOINTS=%1").arg(sz.width()));
        proc->addArgument(QString("-dDEVICEHEIGHTPOINTS=%1").arg(sz.height()));
      }
    }

    proc->addArgument(setupPsFile);
    proc->addArgument(outPsFile);
  }

  if (!proc->start()) {
    delete proc;
    return false;
  }

  //QProgressDialog *pd = new QProgressDialog(tr("Enviando a impresora..."), QString::null, 10000,  this, tr("sendprintprogress"), true );
  //int step = 0;
  //QApplication::setOverrideCursor(Qt::WaitCursor);
  while (proc->isRunning()) {
    //pd->setProgress(step++);
    qApp->processEvents();
    //if (step == 9999)
    // step = 0;
  }
  //QApplication::restoreOverrideCursor();

  delete proc;
  //delete pd;

  qApp->processEvents();

  return true;
}
コード例 #2
0
ファイル: mreportviewer.cpp プロジェクト: afibanez/eneboo
bool MReportViewer::printGhostReport()
{
  if (report == 0)
    return false;

  int cnt = report->pageCount();

  if (cnt == 0)
    return false;

  QString outPsFile(AQ_DISKCACHE_DIRPATH + "/outprint.ps");
  QFile::remove(outPsFile);
  if (!printReportToPS(outPsFile))
    return false;

  bool gsPrintOk = false;
  QProcess *procTemp = new QProcess();
  procTemp->addArgument("gsprint");
  procTemp->addArgument("-help");
  gsPrintOk = procTemp->start();
  delete procTemp;

  QProcess *proc = new QProcess();
  if (gsPrintOk) {
    proc->addArgument("gsprint");
    proc->addArgument("-color");
    proc->addArgument("-query");
    proc->addArgument(outPsFile);
  } else {
    QString setupPsFile(AQ_DISKCACHE_DIRPATH + "/setup.ps");
    QFile::remove(setupPsFile);
    QFile fileSetup(setupPsFile);

    if (fileSetup.open(IO_WriteOnly)) {
      QTextStream stream(&fileSetup);
      stream << "mark" << "\n";
      stream << "  /NoCancel      true" << "\n";
      if (!printerName_.isEmpty()) {
        QString pName("  /OutputFile      (%printer%");
        pName += printerName_ + ")";
        stream << pName << "\n";
      }
      stream << "  /BitsPerPixel  24" << "\n";
      stream << "  /UserSettings" << "\n";
      stream << "    <<" << "\n";
      stream << "      /DocumentName  (AbanQ document)" << "\n";
      stream << QString("      /DocumentRange [1 %1]").arg(cnt) << "\n";
      stream << QString("      /SelectedRange [1 %1]").arg(cnt) << "\n";
      stream << QString("      /MaxResolution %1").arg(dpi_) << "\n";
      stream << "    >>" << "\n";
      stream << "  (mswinpr2) finddevice" << "\n";
      stream << "  putdeviceprops" << "\n";
      stream << "setdevice" << "\n";
      fileSetup.close();
    }

    proc->addArgument("gswin32c");
    proc->addArgument("-q");
    proc->addArgument("-dBATCH");
    proc->addArgument("-dNOPAUSE");
    proc->addArgument("-dNODISPLAY");
    proc->addArgument(QString("-r%1").arg(dpi_));
    proc->addArgument(setupPsFile);
    proc->addArgument(outPsFile);
  }

  if (!proc->start()) {
    delete proc;
    return false;
  }

  while (proc->isRunning())
    qApp->processEvents();

  delete proc;

  qApp->processEvents();

  return true;
}