public void TestInstantiatesCorrectly() { using (var pdfPrint = new PdfPrint()) { Assert.IsInstanceOfType(pdfPrint, typeof(PdfPrint)); } }
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 void TestThrowsIfFileNotFound() { using (var pdfPrint = new PdfPrint()) { pdfPrint.Print("C:\\nonexisting-file.nonexistent-extension", "out.pdf"); } }
public void TestThrowsIfPdfPrinterNotFound() { var dir = Directory.GetCurrentDirectory(); using (var pdfPrint = new PdfPrint(pdfPrinterName: "Nonexistent PDF printer")) { pdfPrint.Print($"{dir}\\sample.docx", "out.pdf"); } }
public static void Print(string printerName, PaperSize paperSize, byte[] data, bool landscape = false) { var printLib = new PdfPrint("Yoolis ICT Services", "5d565355345b555627535a5f335c52"); printLib.IsLandscape = landscape; printLib.PaperSize = paperSize; printLib.Scale = PdfPrint.ScaleTypes.None; printLib.PrinterName = printerName; printLib.Print(data); }
public static void Print(string printerName, PaperSize paperSize, byte[] data, bool landscape = false) { var printLib = new PdfPrint("Yoolis ICT Services", "5d565355345b555627535a5f335c52"); printLib.IsLandscape = landscape; printLib.PaperSize = paperSize; printLib.Scale = PdfPrint.ScaleTypes.None; printLib.PrinterName = printerName; printLib.Print(data); }
public override void OnPageFinished(WebView view, string url) { base.OnPageFinished(view, url); string jobName = "Document"; PrintAttributes attributes = new PrintAttributes.Builder() .SetMediaSize(PrintAttributes.MediaSize.IsoA4) .SetResolution(new PrintAttributes.Resolution("pdf", "pdf", 600, 600)) .SetMinMargins(PrintAttributes.Margins.NoMargins).Build(); PdfPrint pdfPrint = new PdfPrint(attributes); pdfPrint.Print(view.CreatePrintDocumentAdapter(jobName)); }
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); } }
public void PrintReport() { try { var pdfPrint = new PdfPrint("demoCompany", "demoKey"); pdfPrint.PrinterName = "XYZ"; pdfPrint.Watermark.Text = String.Empty; var status = pdfPrint.Print("D:\\Client Software\\DeskTopApplication\\StarEngineering\\SenseInventoryLogoUI\\bin\\Debug\\InvoiceReport.pdf"); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void TestPrintsPdfFromDocx() { var dir = Directory.GetCurrentDirectory(); var output = $"{dir}\\sample.pdf"; if (File.Exists(output)) { File.Delete(output); } using (var pdfPrint = new PdfPrint()) { pdfPrint.Print($"{dir}\\sample.docx", output); Assert.IsTrue(File.Exists(output)); } }
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 PrintPdf(string jobDescription, PrintQueue queue, byte[] pdfReport) { _progress.Report(new MonitorMessage(String.Format(Strings.PrintPdfNotify, queue.QueueName, queue.PrinterName))); var pdfPrint = new PdfPrint("Acumatica", "g/4JFMjn6KtGjMEKn2ZY1H6+hSqKUHU+273JkSGKwP0="); pdfPrint.PrinterName = queue.PrinterName; // Retrieve paper size, source and orientation var printerSettings = new System.Drawing.Printing.PrinterSettings(); printerSettings.PrinterName = queue.PrinterName; if (queue.PaperSize != PrintQueue.PrinterDefault) { bool paperSizeSet = false; foreach (PaperSize paperSize in printerSettings.PaperSizes) { if (paperSize.RawKind == queue.PaperSize) { pdfPrint.PaperSize = paperSize; paperSizeSet = true; break; } } if (!paperSizeSet) { _progress.Report(new MonitorMessage(String.Format(Strings.PaperSizeMissingWarning, queue.PrinterName, queue.PaperSize), MonitorMessage.MonitorStates.Warning)); } } if (queue.PaperSource != PrintQueue.PrinterDefault) { bool paperSourceSet = false; foreach (PaperSource paperSource in printerSettings.PaperSources) { if (paperSource.RawKind == queue.PaperSource) { pdfPrint.PaperSource = paperSource; paperSourceSet = true; break; } } if (!paperSourceSet) { _progress.Report(new MonitorMessage(String.Format(Strings.PaperSourceMissingWarning, queue.PrinterName, queue.PaperSource), MonitorMessage.MonitorStates.Warning)); } } if (queue.Orientation == PrintQueue.PrinterOrientation.Automatic) { pdfPrint.IsAutoRotate = true; } else if (queue.Orientation == PrintQueue.PrinterOrientation.Landscape) { pdfPrint.IsLandscape = true; } else if (queue.Orientation == PrintQueue.PrinterOrientation.Portrait) { pdfPrint.IsLandscape = false; } pdfPrint.Print(pdfReport, new PdfWatermark(), jobDescription); }
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 bool SetSettingsFromGUI(PdfPrint printLibrary) { if (!cbUsePrinterSettings.Checked) { if (cmbxPrinterNames.SelectedItem == null) { MessageBox.Show("Select printer."); return(false); } if (!cbDefaultPrintInColor.Checked) { printLibrary.PrintInColor = cbPrintInColor.Checked; } if (!cbDefaultCollate.Checked) { printLibrary.Collate = cbCollate.Checked; } if (!cbDefaultPrintOrientation.Checked) { if (rbLandscape.Checked) { printLibrary.IsLandscape = true; } if (rbPortrait.Checked) { printLibrary.IsLandscape = false; } } if (!cbDefaultDuplex.Checked) { if (rbDuplexHorizontal.Checked) { printLibrary.DuplexType = Duplex.Horizontal; } if (rbDuplexVertical.Checked) { printLibrary.DuplexType = Duplex.Vertical; } if (rbDuplexSimplex.Checked) { printLibrary.DuplexType = Duplex.Simplex; } } if (!cbDefaultNumCopies.Checked) { printLibrary.Copies = (short)numCopies.Value; } var printerSettings = new PrinterSettings(); var defaultPrinter = printerSettings.PrinterName; PdfPrintTest.SetDefaultPrinter(cmbxPrinterNames.SelectedItem.ToString()); var newPrinterSettings = new PrinterSettings(); if (!cbDefaultPaperSize.Checked) { if (cmbxPaperSize.SelectedItem == null) { MessageBox.Show("Select paper size"); return(false); } foreach (PaperSize size in newPrinterSettings.PaperSizes) { if (size.ToString().Equals(cmbxPaperSize.SelectedItem.ToString())) { printLibrary.PaperSize = size; break; } } } if (!cbDefaultPaperSource.Checked) { if (cmbxPaperSource.SelectedItem == null) { MessageBox.Show("Select paper source"); return(false); } foreach (PaperSource paperSource in newPrinterSettings.PaperSources) { if (paperSource.ToString().Equals(cmbxPaperSource.SelectedItem.ToString())) { printLibrary.PaperSource = paperSource; break; } } } if (!cbDefaultPrintInColor.Checked) { printLibrary.PrintInColor = cbPrintInColor.Checked; } if (!cbDefaultPrinterResolution.Checked) { if (cmbxPrinterResolutions.SelectedItem == null) { MessageBox.Show("Select printer resolution"); return(false); } foreach (PrinterResolution printerResolution in newPrinterSettings.PrinterResolutions) { if (printerResolution.ToString().Equals(cmbxPrinterResolutions.SelectedItem.ToString())) { printLibrary.PrinterResolution = printerResolution; break; } } } printLibrary.PrinterName = cmbxPrinterNames.SelectedItem.ToString(); PdfPrintTest.SetDefaultPrinter(defaultPrinter); } printLibrary.IsContentCentered = cbCentered.Checked; printLibrary.IsAutoRotate = cbAutoRotate.Checked; if (rbScaleActualSize.Checked) { printLibrary.Scale = PdfPrint.ScaleTypes.None; } if (rbScaleFit.Checked) { printLibrary.Scale = PdfPrint.ScaleTypes.FitToMargins; } if (rbScaleShrink.Checked) { printLibrary.Scale = PdfPrint.ScaleTypes.Shrink; } printLibrary.Pages = tbPrintPages.Text; if (rbPrintEvenOdd.Checked) { printLibrary.RangeType = PdfPrint.RangeTypes.EvenAndOdd; } if (rbPrintEven.Checked) { printLibrary.RangeType = PdfPrint.RangeTypes.JustEven; } if (rbPrintOdd.Checked) { printLibrary.RangeType = PdfPrint.RangeTypes.JustOdd; } return(true); }
private void PrintPdf(PrintQueue queue, byte[] pdfReport) { _progress.Report(new MonitorMessage(String.Format(Strings.PrintPdfNotify, queue.QueueName, queue.PrinterName))); var pdfPrint = new PdfPrint("demoCompany", "demoKey"); pdfPrint.PrinterName = queue.PrinterName; // Retrieve paper size, source and orientation var printerSettings = new System.Drawing.Printing.PrinterSettings(); printerSettings.PrinterName = queue.PrinterName; if (queue.PaperSize != PrintQueue.PrinterDefault) { bool paperSizeSet = false; foreach (PaperSize paperSize in printerSettings.PaperSizes) { if (paperSize.RawKind == queue.PaperSize) { pdfPrint.PaperSize = paperSize; paperSizeSet = true; break; } } if (!paperSizeSet) { _progress.Report(new MonitorMessage(String.Format(Strings.PaperSizeMissingWarning, queue.PrinterName, queue.PaperSize), MonitorMessage.MonitorStates.Warning)); } } if (queue.PaperSource != PrintQueue.PrinterDefault) { bool paperSourceSet = false; foreach (PaperSource paperSource in printerSettings.PaperSources) { if (paperSource.RawKind == queue.PaperSource) { pdfPrint.PaperSource = paperSource; paperSourceSet = true; break; } } if (!paperSourceSet) { _progress.Report(new MonitorMessage(String.Format(Strings.PaperSourceMissingWarning, queue.PrinterName, queue.PaperSource), MonitorMessage.MonitorStates.Warning)); } } if (queue.Orientation == PrintQueue.PrinterOrientation.Automatic) { pdfPrint.IsAutoRotate = true; } else if (queue.Orientation == PrintQueue.PrinterOrientation.Landscape) { pdfPrint.IsLandscape = true; } else if (queue.Orientation == PrintQueue.PrinterOrientation.Portrait) { pdfPrint.IsLandscape = false; } pdfPrint.Print(pdfReport); }