public Boolean PrintDocument() { var di = new DirectoryInfo(@"C:\FTP_Location"); var pdfPrint = new PdfPrint("Project", "12345"); PdfPrint.Status result = PdfPrint.Status.OK; bool PrintStatus = false; try { //result = pdfPrint.Print(FileLoc, printDialog.PrinterSettings); PrintStatus = true; if (result == PdfPrint.Status.OK) { //Delete all files in the FTP File Location foreach (FileInfo file in di.EnumerateFiles()) { file.Delete(); } PrintStatus = true; return(PrintStatus); } return(PrintStatus); } catch (Exception ex) { result = PdfPrint.Status.UNKNOWN_ERROR; MessageBox.Show("Error." + ex.Message, "Printer Status", MessageBoxButtons.OK, MessageBoxIcon.Error); return(PrintStatus); } }
public static string DecodeStatusCode(PdfPrint.Status status) { switch (status) { case PdfPrint.Status.OK: return("OK"); case PdfPrint.Status.FILE_DOESNT_EXIST: return("Filename doesn't exist"); case PdfPrint.Status.CANNOT_PRINT_FILE: return("Cannot print file"); case PdfPrint.Status.PRINTER_DOESNT_EXIST: return("Printer doesn't exist"); case PdfPrint.Status.INVALID_DEVMOD: return("Invalid printer properties structure."); case PdfPrint.Status.NOT_AVAILABLE_PRINTER_PROPERTIES: return("Not available printer properties"); case PdfPrint.Status.CANT_INITIALIZE_PRINTER: return("Can't initialize printer"); case PdfPrint.Status.PASSWORD_INVALID: return("Invalid password"); case PdfPrint.Status.INVALID_PDF: return("Invalid pdf"); case PdfPrint.Status.FILENAME_NOT_SET: return("File name not set"); case PdfPrint.Status.PASSWORD_NOT_PROVIDED: return("PDF is password protected and password isn't provided."); case PdfPrint.Status.UNKNOWN_ERROR: return("Unknown error"); case PdfPrint.Status.INVALID_PRINT_RANGE: return("Invalid print range"); case PdfPrint.Status.INVALID_ADOBE_PRINT_RANGE: return("Invalid print range for adobe. It could be from-to, single page or empty."); case PdfPrint.Status.PAGE_NUMBER_DOESNT_EXIST: return("Page number doesn't exist"); case PdfPrint.Status.PRINTING_CANCELLED: return("Printing cancelled"); case PdfPrint.Status.INVALID_IMAGE_TYPE: return("Invalid image type."); case PdfPrint.Status.NOT_32_BIT: return("Printing with Adobe is supported only in 32 bit application."); } return("Unknown error."); }
public Boolean PrintDocument(bool IsColor, short NoOfCopies) { var di = new DirectoryInfo(@"C:\FTP_Location"); //Using PDFPrinting var pdfPrint = new PdfPrint("Project", "12345"); //Using Spire var pdfPrintUsingAcrobat = new PrintPDFwithAcrobat(); PdfPrint.Status result = PdfPrint.Status.OK; bool PrintStatus = false; try { //var res = pdfPrintUsingAcrobat.Print(FileLoc); //Pdf Printing Method result == PdfPrint.Status.OK //result = pdfPrint.Print(FileLoc, printDialog.PrinterSettings); PdfDocument pdfdocument = new PdfDocument(); pdfdocument.LoadFromFile(FileLoc); pdfdocument.PrintDocument.PrinterSettings.Copies = NoOfCopies; //pdfdocument.PrintSettings.Color = printDialog.PrinterSettings.SupportsColor; if (!IsColor) { pdfdocument.PrintSettings.Color = false; } pdfdocument.Print(); pdfdocument.Dispose(); PrintStatus = true; if (true) { //Delete all files in the FTP File Location foreach (FileInfo file in di.EnumerateFiles()) { file.Delete(); } PrintStatus = true; return(PrintStatus); } return(PrintStatus); } catch (Exception ex) { result = PdfPrint.Status.UNKNOWN_ERROR; MessageBox.Show("Error." + ex.Message, "Printer Status", MessageBoxButtons.OK, MessageBoxIcon.Error); return(PrintStatus); } }
private void btnPrintWithAdobe_Click(object sender, EventArgs e) { try { if (!PdfPrintTest.IsFileNameCorrect(tbFileName.Text)) { return; } var printLibrary = PdfPrintTest.GetPdfPrint(_configFile); if (!SetSettingsFromGUIAdobe(printLibrary)) { return; } var resultMessage = ""; PdfPrint.Status result = PdfPrint.Status.OK; if (cbUsePrinterSettingsAdobe.Checked) { if (_printerSettingsAdobe == null) { MessageBox.Show("PrinterSettings not set. Press Set Printer Settings button"); return; } result = printLibrary.PrintWithAdobe(tbFileName.Text, _printerSettingsAdobe, ref resultMessage); } else { result = printLibrary.PrintWithAdobe(tbFileName.Text, ref resultMessage); } MessageBox.Show("Result message=" + resultMessage); if (result == PdfPrint.Status.OK) { MessageBox.Show("Done successfully."); } else { MessageBox.Show("Error. " + PdfPrintTest.DecodeStatusCode(result)); } } catch (Exception ex) { MessageBox.Show("Exception " + ex.Message); } }
private void btnPrintDocument_Click(object sender, EventArgs e) { PdfPrint.Status result = PdfPrint.Status.OK; if (printDialog.ShowDialog() == DialogResult.OK) { //Open ComputeSummary form var CompSum = new ComputationSummary(); //Returns a value of number of copies to be printed CompSum.txtNoOfCopies.Text = Convert.ToString(printDialog.PrinterSettings.Copies); CompSum.txtNoOfPages.Text = Convert.ToString(pdfViewer1.NumberOfPages); //Returns a boolean value if the item to be printed is colored or grayscale PrintColor = printDialog.PrinterSettings.DefaultPageSettings.Color; decimal costPerImage = 0; //Compute Cost var cal = new PrintCalculation(); if (!pdfPrinting.ExcelFormat) { costPerImage = cal.CalculateImageInFile(pdfPrinting.FileInDocFormat); } if (PrintColor == true) { //Return a value of cost per page and if colored CompSum.txtTotalAmount.Text = Convert.ToString(costPerImage + ((printDialog.PrinterSettings.Copies * 2) * pdfViewer1.NumberOfPages)); CompSum.txtColored.Text = "Yes"; } else { //Return a value of cost per page and if not colored CompSum.txtTotalAmount.Text = Convert.ToString(costPerImage + ((printDialog.PrinterSettings.Copies * 1) * pdfViewer1.NumberOfPages)); CompSum.txtColored.Text = "No"; } CompSum.FileLocFromMain = FileLoc; CompSum.ShowDialog(); if (CompSum.PrintSuccess) { pdfViewer1.CloseDocument(); btnPrintDocument.Enabled = false; } } else { pdfViewer1.CloseDocument(); result = PdfPrint.Status.PRINTING_CANCELLED; } if (result == PdfPrint.Status.OK) { /*MessageBox.Show("Done Successfully", "Printing Transaction Status", MessageBoxButtons.OK, MessageBoxIcon.Information);*/ } else if (result == PdfPrint.Status.PRINTING_CANCELLED) { var MsgAlerts = new MessageAlerts(); MsgAlerts.ExceptionMessage(pdfPrinting.DecodeStatusCode(result)); } else { var MsgAlerts = new MessageAlerts(); MsgAlerts.ExceptionMessage("Error." + pdfPrinting.DecodeStatusCode(result)); } }
public Dictionary <string, object> Execute(OutputDocument document, Dictionary <string, object> namedPassThroughParameters) { Dictionary <string, object> results = new Dictionary <string, object>(); try { if (document.MetaParameters[StdMetaParamNames.DocumentIDKey] != "GenericReport") { throw new Exception("Report must be of type GenericReport."); } document.Data.Seek(0, SeekOrigin.Begin); using (XmlReader reader = XmlReader.Create(document.Data)) { reader.ReadToFollowing("Data"); byte[] pdfDoc = new byte[0]; int bytesRead = 0; byte[] buf = new byte[65536]; while ((bytesRead = reader.ReadElementContentAsBase64(buf, 0, 65536)) > 0) { int oldEndIndex = pdfDoc.Length == 0 ? 0 : (pdfDoc.Length - 1); Array.Resize <byte>(ref pdfDoc, (pdfDoc.Length + bytesRead)); Array.Copy(buf, 0, pdfDoc, oldEndIndex, bytesRead); } if (pdfDoc.Length == 0) { throw new Exception("The report has no content."); } if (Convert.ToBoolean(_configurationParameters[_OUTPUTENABLE])) { PdfPrint pdfPrint = new PdfPrint("Aptean AB", "g/4JFMjn6KvRA39zUa4QClRtNo6h5TnW273JkSGKwP0="); pdfPrint.PrinterName = document.PrinterDeviceName; pdfPrint.Copies = Convert.ToInt16(document.MetaParameters[StdMetaParamNames.NumberOfCopiesKey]); PdfPrint.Status status = pdfPrint.Print(pdfDoc); if (status != PdfPrint.Status.OK) { throw new Exception("Error printing PDF report: " + status.ToString()); } } if (results.ContainsKey(StdResultParamNames.BinaryResultKey)) { results.Remove(StdResultParamNames.BinaryResultKey); } results.Add(StdResultParamNames.BinaryResultKey, pdfDoc); } } catch (Exception ex) { throw new Exception("Error printing PDF report.\r\n" + ex.Message); } return(results); }
private void btnPrint_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(tbFileName.Text)) { MessageBox.Show("Filename not set."); return; } if (!File.Exists(tbFileName.Text)) { MessageBox.Show("Filename doesn't exist."); return; } var pdfPrint = new PdfPrint(_company, _password); pdfPrint.IsContentCentered = cbIsContentCentered.Checked; if (cmbxScale.Text == "None") { pdfPrint.Scale = PdfPrint.ScaleTypes.None; } if (cmbxScale.Text == "Shrink") { pdfPrint.Scale = PdfPrint.ScaleTypes.Shrink; } if (cmbxScale.Text == "FitToMargins") { pdfPrint.Scale = PdfPrint.ScaleTypes.FitToMargins; } PdfPrint.Status result = PdfPrint.Status.OK; if (!_is64) // in 32 bit PrintDialog could be used { PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == DialogResult.OK) { try { result = pdfPrint.Print(tbFileName.Text, printDialog.PrinterSettings, tbPassword.Text); } catch (Exception ex) { result = PdfPrint.Status.UNKNOWN_ERROR; MessageBox.Show("Error." + ex.Message); } } else { result = PdfPrint.Status.PRINTING_CANCELLED; } } else { pdfPrint.SettingDialog = true; try { result = pdfPrint.Print(tbFileName.Text, tbPassword.Text); } catch (Exception ex) { result = PdfPrint.Status.UNKNOWN_ERROR; MessageBox.Show("Error." + ex.Message); } } if (result == PdfPrint.Status.OK) { MessageBox.Show("Done successfully."); } else if (result == PdfPrint.Status.PRINTING_CANCELLED) { MessageBox.Show(DecodeStatusCode(result)); } else { MessageBox.Show("Error. " + DecodeStatusCode(result)); } }
private void btnPrint_Click(object sender, EventArgs e) { if (!PdfPrintTest.IsFileNameCorrect(tbFileName.Text)) { return; } var printLibrary = PdfPrintTest.GetPdfPrint(_configFile); if (!SetSettingsFromGUI(printLibrary)) { return; } PdfPrint.Status result = PdfPrint.Status.OK; if (cbUsePrintDialog.Checked) { printLibrary.SettingDialog = true; } if (!cbIsStream.Checked) { string jobName = string.IsNullOrEmpty(tbDocumentName.Text.Trim()) ? tbFileName.Text : tbDocumentName.Text.Trim(); if (cbUsePrinterSettings.Checked) { if (cbUseWatermark.Checked) { result = printLibrary.Print(tbFileName.Text, _printerSettings, tbPassword.Text, _watermark, jobName); } else { result = printLibrary.Print(tbFileName.Text, _printerSettings, tbPassword.Text, jobName); } } else { if (cbUseWatermark.Checked) { result = printLibrary.Print(tbFileName.Text, tbPassword.Text, _watermark, jobName); } else { result = printLibrary.Print(tbFileName.Text, tbPassword.Text, jobName); } } } else { if (cbUsePrinterSettings.Checked) { if (cbUseWatermark.Checked) { result = printLibrary.Print(PdfPrintTest.GetStream(tbFileName.Text), _printerSettings, tbPassword.Text, tbDocumentName.Text, _watermark); } else { result = printLibrary.Print(PdfPrintTest.GetStream(tbFileName.Text), _printerSettings, tbPassword.Text, tbDocumentName.Text); } } else { if (cbUseWatermark.Checked) { result = printLibrary.Print(PdfPrintTest.GetStream(tbFileName.Text), tbPassword.Text, tbDocumentName.Text, _watermark); } else { result = printLibrary.Print(PdfPrintTest.GetStream(tbFileName.Text), tbPassword.Text, tbDocumentName.Text); } } } if (result == PdfPrint.Status.OK) { MessageBox.Show("Done successfully."); } else { MessageBox.Show("Error. " + PdfPrintTest.DecodeStatusCode(result)); } }