public void Print() { PrintDialog printDialog1 = new PrintDialog(); printDialog1.Document = new PrintDocument(); printDialog1.AllowPrintToFile = true; printDialog1.PrintToFile = false; if (printDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK) { printDialog1.Document.DefaultPageSettings.PaperSize = new PaperSize("Letter", 1700, 2339); printDialog1.Document.PrinterSettings.PrintToFile = true; printDialog1.Document.PrintPage += delegate(object sender1, PrintPageEventArgs e1) { RectangleF page = printDialog1.Document.DefaultPageSettings.PrintableArea; float x = 50; float y = 50; Font printFont = new Font("Times New Roman", 12); int count = 0; foreach (var record in PrintArray) { count++; if (count != 10) { e1.Graphics.DrawString(record.ToString(), printFont, new SolidBrush(Color.Black), new RectangleF(x, y, page.Width, page.Height)); y += printFont.Height; } } }; try { printDialog1.Document.Print(); } catch (Exception ex) { throw new Exception("Exception occurred while printing", ex); } } }
private void button2_Click(object sender, EventArgs e) { PrintDialog dlg = new PrintDialog(); dlg.ShowDialog(); }
void PrintOnClick(object sender, RoutedEventArgs e) { PrintDialog dlg = new PrintDialog(); if (dlg.ShowDialog().GetValueOrDefault()) { Grid grid = new Grid(); // make 5 cols, 5 rows for (int i = 0; i < 5; i++) { ColumnDefinition coldef = new ColumnDefinition() { Width = GridLength.Auto }; grid.ColumnDefinitions.Add(coldef); RowDefinition rowdef = new RowDefinition() { Height = GridLength.Auto }; grid.RowDefinitions.Add(rowdef); } // gradient fill grid.Background = new LinearGradientBrush( Colors.Gray, Colors.White, new Point(0, 0), new Point(1, 1)); Random rand = new Random(); // fill the grid with 25 buttons for (int i = 0; i < 25; i++) { Button btn = new Button() { FontSize = 12 + rand.Next(8), Content = "Button No. " + (i + 1), HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(6) }; grid.Children.Add(btn); Grid.SetRow(btn, i % 5); Grid.SetColumn(btn, i / 5); } Size sizeGrid = grid.DesiredSize; grid.Measure( new Size(Double.PositiveInfinity, Double.PositiveInfinity)); sizeGrid = grid.DesiredSize; // center the grid on page Point ptGrid = new Point( (dlg.PrintableAreaWidth - sizeGrid.Width) / 2, (dlg.PrintableAreaHeight - sizeGrid.Height) / 2); grid.Arrange(new Rect(ptGrid, sizeGrid)); dlg.PrintVisual(grid, Title); } }
public void Export(IEnumerable <IPdfModule> moduleList) { PrintDialog pd = new PrintDialog(); if ((pd.ShowDialog() == true)) { FlowDocument fd = new FlowDocument(); fd.PagePadding = new Thickness(48); fd.ColumnGap = 0; fd.ColumnWidth = pd.PrintableAreaWidth; fd.IsColumnWidthFlexible = true; foreach (IPdfModule module in moduleList) { BlockUIContainer bc = new BlockUIContainer(); if (module.GetType().Name == "RTFModule" || module.GetType().Name == "HeaderModule") { List <Block> fdBlocks = new List <Block>((module.Render() as RichTextBox).Document.Blocks); foreach (Block block in fdBlocks) { fd.Blocks.Add(block); } } else if (module.GetType().Name == "ShellbagTableModule") { Table table = new Table(); DataGrid data = (module.Render() as DataGrid); var headerList = data.Columns.Select(e => e.Header.ToString()).ToList(); TableColumn num = new TableColumn(); num.Width = new GridLength(20); table.Columns.Add(num); for (int j = 0; j < headerList.Count; j++) { TableColumn c = new TableColumn(); c.Width = new GridLength(175); table.Columns.Add(c); } table.RowGroups.Add(new TableRowGroup()); table.RowGroups[0].Rows.Add(new TableRow()); // Alias the current working row for easy reference. TableRow currentRow = table.RowGroups[0].Rows[0]; // Global formatting for the title row. currentRow.Background = Brushes.Silver; currentRow.FontSize = 24; currentRow.FontWeight = FontWeights.Bold; // Add the header row with content, currentRow.Cells.Add(new TableCell(new Paragraph(new Run("Filtered Shellbag Events")))); // and set the row to span all 6 columns. currentRow.Cells[0].ColumnSpan = 6; // Add the second (header) row. table.RowGroups[0].Rows.Add(new TableRow()); currentRow = table.RowGroups[0].Rows[1]; // Global formatting for the header row. currentRow.FontSize = 18; currentRow.FontWeight = FontWeights.Bold; currentRow.Cells.Add(new TableCell(new Paragraph(new Run("#")))); for (int j = 0; j < headerList.Count; j++) { currentRow.Cells.Add(new TableCell(new Paragraph(new Run(headerList[j])))); } List <IShellEvent> list = data.SelectedItems.OfType <IShellEvent>().ToList(); if (list.Count == 0) { list = data.Items.OfType <IShellEvent>().ToList(); } int k = 2; foreach (IShellEvent shell in list) { if (k == 32) { break; } table.RowGroups[0].Rows.Add(new TableRow()); currentRow = table.RowGroups[0].Rows[k]; currentRow.FontSize = 12; currentRow.FontWeight = FontWeights.Normal; currentRow.Cells.Add(new TableCell(new Paragraph(new Run((k - 1).ToString())))); currentRow.Cells.Add(new TableCell(new Paragraph(new Run(shell.TimeStamp.ToString())))); currentRow.Cells.Add(new TableCell(new Paragraph(new Run(shell.Place.Name)))); currentRow.Cells.Add(new TableCell(new Paragraph(new Run(shell.TypeName)))); currentRow.Cells.Add(new TableCell(new Paragraph(new Run(shell.User.Name)))); k++; } fd.Blocks.Add(table); } else { bc.Child = module.Render(); fd.Blocks.Add(bc); } } pd.PrintDocument(((IDocumentPaginatorSource)fd).DocumentPaginator, "SeeShellsReport"); } //Size pageSize = new Size(816, 1056); }
private void reprint3() { if (lstItems.Items.Count < Convert.ToInt32(txtTotal.Text)) { MessageBox.Show(LabelPrintGlobal.ShowWarningMessage("NOT_FULL_QUANTITY_ERROR"), "ERROR", MessageBoxButtons.OK); return; } PrintDialog dlg = new PrintDialog(); if (dlg.ShowDialog() != DialogResult.OK) { return; } PrinterSettings setting = dlg.PrinterSettings; PrintLabelData data = new PrintLabelData(); data.PCode = txtCode.Text; data.DataCode = GetCodeDate(); data.Total = Convert.ToInt32(txtTotal.Text); data.Date = GetDate(); TPCResult <int> result = Database.GetModuleCount(m_Mode, txtCode.Text); if (result.State == RESULT_STATE.NG) { MessageBox.Show(result.Message); return; } data.Quantity = result.Value; string label_nameFrist = ""; string label_nameSecond = ""; switch (m_Mode) { case PACK_MODE.Pack: label_nameFrist = "pack_fxzz"; label_nameSecond = "pack_wks"; break; case PACK_MODE.Carton: label_nameFrist = "carton_fxzz"; label_nameSecond = "carton_wks"; break; case PACK_MODE.Pallet: label_nameFrist = "pallet_fxzz"; label_nameSecond = "pallet_wks"; break; } //打印第一页信息 TPCPrintLabel labelFrist = LabelPrintGlobal.g_LabelCreator.GetPrintLabel(label_nameFrist); List <string> parametersFrist = MakePrintParameters(m_Mode, data); //打印第二页信息 TPCPrintLabel labelSecond = LabelPrintGlobal.g_LabelCreator.GetPrintLabel(label_nameSecond); List <string> parametersSecond = MakePrintParameters(m_Mode, data); switch (m_Mode) { case PACK_MODE.Pack: labelFrist.Print(setting, parametersFrist); labelSecond.Print(setting, parametersSecond); break; case PACK_MODE.Carton: labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); break; case PACK_MODE.Pallet: labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); break; } //这里需要写入pnt_mng表 TPCResult <bool> ret = Database.SetManagerData(m_Mode, data.PCode, Program.LoginUser, Convert.ToInt32(data.Total), PACK_ACTION.Register, PACK_STATUS.Completed); if (ret.State == RESULT_STATE.NG) { MessageBox.Show(ret.Message); return; } }
private void button1_Click(object sender, EventArgs e) { PrintDialog print = new PrintDialog(); print.ShowDialog(); }
private void menuitemFilePrint_Click(object IGNORE_sender, EventArgs IGNORE_e) { var PrintDialog = new PrintDialog(); if (Settings.MoreSettings.PrinterSettings != null) { PrintDialog.PrinterSettings = Settings.MoreSettings.PrinterSettings; } if (PrintDialog.ShowDialog(this) != DialogResult.OK) { return; } Settings.MoreSettings.PrinterSettings = PrintDialog.PrinterSettings; Settings.Save(); var PrintDocument = new PrintDocument(); PrintDocument.DefaultPageSettings = PageSettings; PrintDocument.PrinterSettings = Settings.MoreSettings.PrinterSettings; PrintDocument.DocumentName = DocumentName + " - Notepad Clone"; var RemainingContentToPrint = Content; var PageIndex = 0; PrintDocument.PrintPage += (sender, e) => { { // header var HeaderText = FormatHeaderFooterText(Settings.Header, PageIndex); var Top = PageSettings.Margins.Top; DrawStringAtPosition(e.Graphics, HeaderText.Left, Top, DrawStringPosition.Left); DrawStringAtPosition(e.Graphics, HeaderText.Center, Top, DrawStringPosition.Center); DrawStringAtPosition(e.Graphics, HeaderText.Right, Top, DrawStringPosition.Right); } { // body var CharactersFitted = 0; var LinesFilled = 0; var MarginBounds = new RectangleF(e.MarginBounds.X, e.MarginBounds.Y + /* header */ CurrentFont.Height, e.MarginBounds.Width, e.MarginBounds.Height - (/* header and footer */ CurrentFont.Height * 2)); e.Graphics.MeasureString(RemainingContentToPrint, CurrentFont, MarginBounds.Size, StringFormat.GenericTypographic, out CharactersFitted, out LinesFilled); e.Graphics.DrawString(RemainingContentToPrint, CurrentFont, Brushes.Black, MarginBounds, StringFormat.GenericTypographic); RemainingContentToPrint = RemainingContentToPrint.Substring(CharactersFitted); e.HasMorePages = (RemainingContentToPrint.Length > 0); } { // footer var FooterText = FormatHeaderFooterText(Settings.Footer, PageIndex); var Top = PageSettings.Bounds.Bottom - PageSettings.Margins.Bottom - CurrentFont.Height; DrawStringAtPosition(e.Graphics, FooterText.Left, Top, DrawStringPosition.Left); DrawStringAtPosition(e.Graphics, FooterText.Center, Top, DrawStringPosition.Center); DrawStringAtPosition(e.Graphics, FooterText.Right, Top, DrawStringPosition.Right); } PageIndex++; }; PrintDocument.Print(); }
public void Print() { if (!(Document is FlowDocument)) { throw new Exception("Document is not a FlowDocument"); } FlowDocument flow = (FlowDocument)Document; PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; PrintQueue pq = printService.GetPrintQueue(); if (pq != null) { // forget if this does anything useful, other than select the chosen printer. Duplex doesn't work. PrintTicket ticket = pq.DefaultPrintTicket; PrintCapabilities capable = pq.GetPrintCapabilities(); if (capable.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge)) { ticket.Duplexing = Duplexing.TwoSidedLongEdge; } ticket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4); if (Settings != null) { if (Settings.ToString().Contains("landscape")) { ticket.PageOrientation = PageOrientation.Landscape; } } if (Settings is PimpedPaginator.Definition) { if (((PimpedPaginator.Definition)Settings).Landscape) { ticket.PageOrientation = PageOrientation.Landscape; } } pDialog.PrintQueue = pq; pDialog.PrintTicket = ticket; } // Display the dialog. This returns true if the user presses the Print button. Nullable <Boolean> print = pDialog.ShowDialog(); if (print == true) { //DocumentPaginator paginator = ((IDocumentPaginatorSource)flow).DocumentPaginator; //paginator.PageSize = new Size(1122, 794); //paginator.PageSize = new Size(794, 1122); PimpedPaginator.Definition def = new PimpedPaginator.Definition(); if (Settings is PimpedPaginator.Definition) { def = (PimpedPaginator.Definition)Settings; } if (pDialog.PrintTicket.PageOrientation == PageOrientation.Landscape) { def.PageSize = new Size(pDialog.PrintTicket.PageMediaSize.Height.Value, pDialog.PrintTicket.PageMediaSize.Width.Value); } else { def.PageSize = new Size(pDialog.PrintTicket.PageMediaSize.Width.Value, pDialog.PrintTicket.PageMediaSize.Height.Value); } PimpedPaginator paginator = new PimpedPaginator(flow, def); pDialog.PrintDocument(paginator, flow.Name); } /* * System.Windows.Xps.XpsDocumentWriter docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(pq); * System.Printing.PrintTicket ticket = pq.DefaultPrintTicket; * PrintCapabilities capable = pq.GetPrintCapabilities(); * if (capable.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge)) * ticket.Duplexing = Duplexing.TwoSidedLongEdge; * ticket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4); * if (Settings != null) * { * if (Settings.ToString().Contains("landscape")) { ticket.PageOrientation = PageOrientation.Landscape; } * } * * if (docWriter != null) * { * DocumentPaginator paginator = ((IDocumentPaginatorSource)flow).DocumentPaginator; * // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device. * //paginator.PageSize = new Size(1122, 794); * //paginator.PageSize = new Size(794, 1122); * Thickness t = new Thickness(32, 30, 10, 10); // copy.PagePadding; * flow.PagePadding = new Thickness(t.Left,t.Top,t.Right,t.Bottom); * flow.ColumnWidth = double.PositiveInfinity; * //copy.PageWidth = 528; // allow the page to be the natural with of the output device * * // Send content to the printer. * docWriter.Write(paginator, ticket); * dialog.ShowTaskDialog("Printing complete", "Printed to " + pq.Name, ""); * } */ }
public void PrintRoundRobinOfMatchLijst(string title, List <string> headerList, List <List <string> > cellList, List <string> afwezigen = null) { if (afwezigen == null) { afwezigen = new List <string>(); } PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { FlowDocument fd = new FlowDocument(); Paragraph p = new Paragraph(new Run(title)); p.FontSize = 18; fd.Blocks.Add(p); Table table = new Table(); TableRowGroup tableRowGroup = new TableRowGroup(); TableRow r = new TableRow(); fd.PageWidth = printDialog.PrintableAreaWidth; fd.PageHeight = printDialog.PrintableAreaHeight; fd.BringIntoView(); fd.TextAlignment = TextAlignment.Center; fd.ColumnWidth = 500; table.CellSpacing = 0; for (int j = 0; j < headerList.Count; j++) { r.Cells.Add(new TableCell(new Paragraph(new Run(headerList[j])))); r.Cells[j].ColumnSpan = 4; r.Cells[j].Padding = new Thickness(4); r.Cells[j].BorderBrush = Brushes.Black; r.Cells[j].FontWeight = FontWeights.Bold; r.Cells[j].Background = Brushes.LightGray; r.Cells[j].Foreground = Brushes.Black; r.Cells[j].BorderThickness = new Thickness(1, 1, 1, 1); } tableRowGroup.Rows.Add(r); table.RowGroups.Add(tableRowGroup); for (int i = 0; i < cellList.Count; i++) { TableRowGroup g = new TableRowGroup(); TableRow ro = new TableRow(); if (cellList[i][0].StartsWith("Ronde ")) { Debug.WriteLine("dit is een ronde cell, voeg lege toe.."); foreach (var item in cellList[i]) { ro.Cells.Add(new TableCell(new Paragraph(new Run("")))); Debug.WriteLine("lege cell toegevoegd!"); } g.Rows.Add(ro); table.RowGroups.Add(g); g = new TableRowGroup(); ro = new TableRow(); } for (int j = 0; j < cellList[i].Count; j++) { ro.Cells.Add(new TableCell(new Paragraph(new Run(cellList[i][j])))); } for (int k = 0; k < cellList[0].Count; k++) { ro.Cells[k].ColumnSpan = 4; ro.Cells[k].Padding = new Thickness(4); ro.Cells[k].BorderBrush = Brushes.Black; ro.Cells[k].FontWeight = FontWeights.Bold; ro.Cells[k].BorderThickness = new Thickness(1, 1, 1, 1); Debug.WriteLine(cellList[i][k]); if (cellList[i][0].StartsWith("Ronde ")) { ro.Cells[k].Background = Brushes.AliceBlue; ro.Cells[2].Foreground = Brushes.AliceBlue; } } g.Rows.Add(ro); table.RowGroups.Add(g); } Table tableafw = new Table(); TableRowGroup tableRowGroupafw = new TableRowGroup(); TableRow rafw = new TableRow(); tableafw.CellSpacing = 0; rafw.Cells.Add(new TableCell(new Paragraph(new Run("")))); rafw.Cells.Add(new TableCell(new Paragraph(new Run("Afwezigen")))); rafw.Cells.Add(new TableCell(new Paragraph(new Run("")))); rafw.Cells[0].ColumnSpan = 4; rafw.Cells[0].Padding = new Thickness(4); rafw.Cells[1].ColumnSpan = 4; rafw.Cells[1].Padding = new Thickness(4); rafw.Cells[2].ColumnSpan = 4; rafw.Cells[2].Padding = new Thickness(4); rafw.Cells[1].BorderBrush = Brushes.Black; rafw.Cells[1].FontWeight = FontWeights.Bold; rafw.Cells[1].Background = Brushes.LightGray; rafw.Cells[1].Foreground = Brushes.Black; rafw.Cells[1].BorderThickness = new Thickness(1, 1, 1, 1); tableRowGroupafw.Rows.Add(rafw); tableafw.RowGroups.Add(tableRowGroupafw); for (int i = 0; i < afwezigen.Count; i++) { TableRowGroup g = new TableRowGroup(); TableRow ro = new TableRow(); ro.Cells.Add(new TableCell(new Paragraph(new Run("")))); ro.Cells.Add(new TableCell(new Paragraph(new Run(afwezigen[i].ToString())))); ro.Cells.Add(new TableCell(new Paragraph(new Run("")))); ro.Cells[0].Padding = new Thickness(4); ro.Cells[0].ColumnSpan = 4; ro.Cells[1].Padding = new Thickness(4); ro.Cells[1].ColumnSpan = 4; ro.Cells[2].Padding = new Thickness(4); ro.Cells[2].ColumnSpan = 4; ro.Cells[1].BorderBrush = Brushes.Black; ro.Cells[1].BorderThickness = new Thickness(1); ro.Cells[1].FontWeight = FontWeights.Bold; ro.Cells[1].Foreground = Brushes.Black; g.Rows.Add(ro); tableafw.RowGroups.Add(g); } fd.Blocks.Add(table); if (afwezigen.Count > 0) { fd.Blocks.Add(tableafw); } try { printDialog.PrintDocument(((IDocumentPaginatorSource)fd).DocumentPaginator, ""); } catch { MessageBox.Show("Probleem met afdrukken, herstart het programma en probeer het nog eens!", "Probleem met afdrukken"); } } }
public void printDG(DataGrid dataGrid, string title) { PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { FlowDocument fd = new FlowDocument(); Paragraph p = new Paragraph(new Run(title)); p.FontStyle = dataGrid.FontStyle; p.FontFamily = dataGrid.FontFamily; p.FontSize = 18; fd.Blocks.Add(p); Table table = new Table(); TableRowGroup tableRowGroup = new TableRowGroup(); TableRow r = new TableRow(); fd.PageWidth = printDialog.PrintableAreaWidth; fd.PageHeight = printDialog.PrintableAreaHeight; fd.BringIntoView(); fd.TextAlignment = TextAlignment.Center; fd.ColumnWidth = 500; table.CellSpacing = 0; var headerList = dataGrid.Columns.Select(e => e.Header.ToString()).ToList(); for (int j = 0; j < headerList.Count; j++) { r.Cells.Add(new TableCell(new Paragraph(new Run(headerList[j])))); r.Cells[j].ColumnSpan = 4; r.Cells[j].Padding = new Thickness(4); r.Cells[j].BorderBrush = Brushes.Black; r.Cells[j].FontWeight = FontWeights.Bold; r.Cells[j].Background = Brushes.DarkGray; r.Cells[j].Foreground = Brushes.White; r.Cells[j].BorderThickness = new Thickness(1, 1, 1, 1); } tableRowGroup.Rows.Add(r); table.RowGroups.Add(tableRowGroup); for (int i = 0; i < dataGrid.Items.Count; i++) { dynamic row = (DataRowView)dataGrid.Items.GetItemAt(i); table.BorderBrush = Brushes.Gray; table.BorderThickness = new Thickness(1, 1, 0, 0); table.FontStyle = dataGrid.FontStyle; table.FontFamily = dataGrid.FontFamily; table.FontSize = 13; tableRowGroup = new TableRowGroup(); r = new TableRow(); for (int j = 0; j < row.Row.ItemArray.Length; j++) { r.Cells.Add(new TableCell(new Paragraph(new Run(row.Row.ItemArray[j].ToString())))); r.Cells[j].ColumnSpan = 4; r.Cells[j].Padding = new Thickness(4); r.Cells[j].BorderBrush = Brushes.DarkGray; r.Cells[j].BorderThickness = new Thickness(0, 0, 1, 1); } tableRowGroup.Rows.Add(r); table.RowGroups.Add(tableRowGroup); } fd.Blocks.Add(table); printDialog.PrintDocument(((IDocumentPaginatorSource)fd).DocumentPaginator, ""); } }
private void PrintFileButton_Click(object sender, RoutedEventArgs e) { PrintDialog printDialog = new PrintDialog(); printDialog.ShowDialog(); }
public void GetPrintSetting(string computeName, int printerType = 0) { bool isExisted = false; SortedList chongfu = new SortedList(); chongfu.Add(1, computeName); chongfu.Add(2, printerType); // type string printName = string.Empty; string ss = _remotCall.RemotInterface.CheckSelectData("HCS-printer-sec002", chongfu); DataTable getdt = _remotCall.RemotInterface.SelectData("HCS-printer-sec002", chongfu); if (getdt == null || getdt.Rows.Count == 0) { if (IsAdoptPrinter(PrintDialog, printerType == 1)) { printName = UpdatePrinterSetting(computeName, PrintDialog.PrinterSettings.PrinterName, printerType); } else { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("printlist", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); PrinterDialogResult = PrintDialog.ShowDialog(); if (PrinterDialogResult == DialogResult.OK) { SetDefaultPrinter(PrintDialog.PrinterSettings.PrinterName); //SetPrinterSettings(PrintDialog, PrintDialog.PrinterSettings.PrinterName); GetPrintSetting(computeName, printerType); } } } else { foreach (string item in System.Drawing.Printing.PrinterSettings.InstalledPrinters) { if (getdt.Columns.Contains("print_name") && getdt.Rows[0]["print_name"].ToString() == item) { isExisted = true; SetDefaultPrinter(item); printName = item; break; } } if (!isExisted || !IsAdoptPrinter(PrintDialog, printerType == 1)) { PrinterDialogResult = PrintDialog.ShowDialog(); if (PrinterDialogResult == DialogResult.OK) { SetDefaultPrinter(PrintDialog.PrinterSettings.PrinterName); if (IsAdoptPrinter(PrintDialog, printerType == 1)) { printName = UpdatePrinterSetting(computeName, PrintDialog.PrinterSettings.PrinterName, printerType, true); } else { MessageBox.Show(PromptMessageXmlHelper.Instance.GetPromptMessage("printlist", EnumPromptMessage.warning), "提示信息", MessageBoxButtons.OK, MessageBoxIcon.Warning); GetPrintSetting(computeName, printerType); } } } } SetDefaultPrinter(printName); }
public bool OnPrint(object args) { CheckDisposed(); if (m_printLayout == null || Clerk.CurrentObject == null) { return(false); } // Don't bother; this edit view does not specify a print layout, or there's nothing to print. var area = m_mediator.PropertyTable.GetStringProperty("areaChoice", null); string toolId; switch (area) { case "notebook": toolId = "notebookDocument"; break; case "lexicon": toolId = "lexiconDictionary"; break; default: return(false); } var docViewConfig = FindToolInXMLConfig(toolId); if (docViewConfig == null) { return(false); } var innerControlNode = GetToolInnerControlNodeWithRightLayout(docViewConfig); if (innerControlNode == null) { return(false); } using (var docView = CreateDocView(innerControlNode)) { if (docView == null) { return(false); } using (var pd = new PrintDocument()) using (var dlg = new PrintDialog()) { dlg.Document = pd; dlg.AllowSomePages = true; dlg.AllowSelection = false; dlg.PrinterSettings.FromPage = 1; dlg.PrinterSettings.ToPage = 1; if (dlg.ShowDialog() == DialogResult.OK) { // REVIEW: .NET does not appear to handle the collation setting correctly // so for now, we do not support non-collated printing. Forcing the setting // seems to work fine. dlg.Document.PrinterSettings.Collate = true; docView.PrintFromDetail(pd, Clerk.CurrentObject.Hvo); } } return(true); } }
public static void printBill(Invoice invoice) { //Window wd = new Window(); //FlowDocumentScrollViewer fdr = new FlowDocumentScrollViewer(); FlowDocument flowDocument = new FlowDocument(); Paragraph titleParagraph = new Paragraph(new Run("Boys World - Men's Wear")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontWeight = FontWeights.Bold; titleParagraph.FontSize = 11; titleParagraph.TextAlignment = TextAlignment.Center; titleParagraph.Margin = new Thickness(0.0); flowDocument.Blocks.Add(titleParagraph); titleParagraph = new Paragraph(new Run("53BI, First Floor, Ambai Road, Alangulam")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.TextAlignment = TextAlignment.Center; titleParagraph.Margin = new Thickness(0.0); flowDocument.Blocks.Add(titleParagraph); titleParagraph = new Paragraph(new Run("cell:7395831650")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.TextAlignment = TextAlignment.Center; titleParagraph.Margin = new Thickness(0.0); flowDocument.Blocks.Add(titleParagraph); titleParagraph = new Paragraph(new Run("Cash Bill")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.FontWeight = FontWeights.Bold; titleParagraph.TextAlignment = TextAlignment.Center; flowDocument.Blocks.Add(titleParagraph); Table table = new Table(); TableRowGroup titleRowGroup = new TableRowGroup(); table.RowGroups.Add(titleRowGroup); TableRow titleRow = new TableRow(); titleRowGroup.Rows.Add(titleRow); titleParagraph = new Paragraph(new Run("Bill No." + invoice.Number)); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; TableCell titleTableCell = new TableCell(titleParagraph); titleTableCell.Padding = new Thickness(2); titleTableCell.TextAlignment = TextAlignment.Left; titleRow.Cells.Add(titleTableCell); titleParagraph = new Paragraph(new Run("Date:" + invoice.Date)); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleTableCell = new TableCell(titleParagraph); titleTableCell.Padding = new Thickness(2); titleTableCell.TextAlignment = TextAlignment.Right; titleRow.Cells.Add(titleTableCell); flowDocument.Blocks.Add(table); table = new Table(); TableColumn column = new TableColumn(); column.Width = new GridLength(0.4, GridUnitType.Star); table.Columns.Add(column); column = new TableColumn(); column.Width = new GridLength(0.1, GridUnitType.Star); table.Columns.Add(column); column = new TableColumn(); column.Width = new GridLength(0.2, GridUnitType.Star); table.Columns.Add(column); column = new TableColumn(); column.Width = new GridLength(0.3, GridUnitType.Star); table.Columns.Add(column); TableRowGroup rowGroup = new TableRowGroup(); table.RowGroups.Add(rowGroup); TableRow row = new TableRow(); rowGroup.Rows.Add(row); Paragraph paragraph = new Paragraph(new Run("Product")); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; paragraph.FontWeight = FontWeights.Bold; TableCell tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Left; row.Cells.Add(tableCell); paragraph = new Paragraph(new Run("Qty.")); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; paragraph.FontWeight = FontWeights.Bold; tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Right; row.Cells.Add(tableCell); paragraph = new Paragraph(new Run("Price")); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; paragraph.FontWeight = FontWeights.Bold; tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Right; row.Cells.Add(tableCell); paragraph = new Paragraph(new Run("Total")); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; paragraph.FontWeight = FontWeights.Bold; tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Right; row.Cells.Add(tableCell); List <BillingProduct> products = JsonSerializer.Deserialize <List <BillingProduct> >(invoice.BillingProducts); foreach (BillingProduct product in products) { row = new TableRow(); rowGroup.Rows.Add(row); paragraph = new Paragraph(new Run(product.PrintName)); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Left; row.Cells.Add(tableCell); paragraph = new Paragraph(new Run(product.Quantity.ToString())); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; paragraph.FontSize = 11; tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Right; row.Cells.Add(tableCell); paragraph = new Paragraph(new Run(product.MRP.ToString())); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Right; row.Cells.Add(tableCell); paragraph = new Paragraph(new Run(product.Total.ToString())); paragraph.FontFamily = new FontFamily("Segoe UI"); paragraph.FontSize = 11; tableCell = new TableCell(paragraph); tableCell.Padding = new Thickness(2); tableCell.TextAlignment = TextAlignment.Right; row.Cells.Add(tableCell); } flowDocument.Blocks.Add(table); table = new Table(); TableRowGroup footerRowGroup = new TableRowGroup(); table.RowGroups.Add(footerRowGroup); TableRow footerRow = new TableRow(); footerRowGroup.Rows.Add(footerRow); int total = products.Sum(product => product.Quantity); titleParagraph = new Paragraph(new Run("Total Items:" + total.ToString())); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; TableCell footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Left; footerRow.Cells.Add(footerTableCell); if (invoice.Discount != null && invoice.Discount != "0") { footerRow = new TableRow(); footerRowGroup.Rows.Add(footerRow); titleParagraph = new Paragraph(new Run("Net Amt.")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.FontWeight = FontWeights.Bold; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Left; footerRow.Cells.Add(footerTableCell); titleParagraph = new Paragraph(new Run((int.Parse(invoice.Total) + int.Parse(invoice.Discount)).ToString())); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 13; titleParagraph.FontWeight = FontWeights.Bold; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Right; footerRow.Cells.Add(footerTableCell); footerRow = new TableRow(); footerRowGroup.Rows.Add(footerRow); titleParagraph = new Paragraph(new Run("Discount")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Left; footerRow.Cells.Add(footerTableCell); titleParagraph = new Paragraph(new Run(invoice.Discount)); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Right; footerRow.Cells.Add(footerTableCell); footerRow = new TableRow(); footerRowGroup.Rows.Add(footerRow); titleParagraph = new Paragraph(new Run("Gross Amt.")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.FontWeight = FontWeights.Bold; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Left; footerRow.Cells.Add(footerTableCell); titleParagraph = new Paragraph(new Run(invoice.Total)); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 13; titleParagraph.FontWeight = FontWeights.Bold; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Right; footerRow.Cells.Add(footerTableCell); } else { footerRow = new TableRow(); footerRowGroup.Rows.Add(footerRow); titleParagraph = new Paragraph(new Run("Net Amt.")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.FontWeight = FontWeights.Bold; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Left; footerRow.Cells.Add(footerTableCell); titleParagraph = new Paragraph(new Run(invoice.Total)); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 13; titleParagraph.FontWeight = FontWeights.Bold; footerTableCell = new TableCell(titleParagraph); footerTableCell.Padding = new Thickness(2); footerTableCell.TextAlignment = TextAlignment.Right; footerRow.Cells.Add(footerTableCell); } flowDocument.Blocks.Add(table); titleParagraph = new Paragraph(new Run("Thank you for shopping with us!!!")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.TextAlignment = TextAlignment.Center; titleParagraph.Margin = new Thickness(0.0); flowDocument.Blocks.Add(titleParagraph); titleParagraph = new Paragraph(new Run("*****@*****.**")); titleParagraph.FontFamily = new FontFamily("Segoe UI"); titleParagraph.FontSize = 11; titleParagraph.TextAlignment = TextAlignment.Center; titleParagraph.Margin = new Thickness(0.0); flowDocument.Blocks.Add(titleParagraph); flowDocument.MaxPageWidth = 270; //fdr.Document = flowDocument; //wd.Content = fdr; //wd.Show(); PrintDialog dialog = new PrintDialog(); bool result = (bool)dialog.ShowDialog(); if (result) { IDocumentPaginatorSource idpSource = flowDocument; dialog.PrintDocument(idpSource.DocumentPaginator, "Bill"); } }
/// <summary>Prints the FrameworkElement.</summary> /// <param name="fe">The FrameworkElement.</param> public static void Print(this FrameworkElement fe) { PrintDialog pd = new PrintDialog(); bool?result = pd.ShowDialog(); pd.PrintTicket.PageOrientation = PageOrientation.Portrait; if (!result.HasValue || !result.Value) { return; } System.Printing.PrintCapabilities capabilities = pd.PrintQueue.GetPrintCapabilities(pd.PrintTicket); try { fe.Dispatcher.Invoke(new Action(() => { //fe.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity)); //fe.Arrange(new Rect(fe.DesiredSize)); //fe.UpdateLayout(); // Change the layout of the UI Control to match the width of the printer page fe.Width = capabilities.PageImageableArea.ExtentWidth; fe.UpdateLayout(); fe.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Size size = new Size(capabilities.PageImageableArea.ExtentWidth, fe.DesiredSize.Height); fe.Measure(size); size = new Size(capabilities.PageImageableArea.ExtentWidth, fe.DesiredSize.Height); fe.Measure(size); fe.Arrange(new Rect(size)); }), System.Windows.Threading.DispatcherPriority.Render); int height = (int)pd.PrintTicket.PageMediaSize.Height; int width = (int)pd.PrintTicket.PageMediaSize.Width; int pages = (int)Math.Ceiling((fe.ActualHeight / height)); FixedDocument document = new FixedDocument(); for (int i = 0; i < pages; i++) { FixedPage page = new FixedPage(); page.Height = height; page.Width = width; page.PrintTicket = pd.PrintTicket; PageContent content = new PageContent(); content.Child = page; document.DocumentPaginator.PageSize = new Size(pd.PrintableAreaWidth + 50, pd.PrintableAreaHeight); document.Pages.Add(content); VisualBrush vb = new VisualBrush(fe); vb.AlignmentX = AlignmentX.Left; vb.AlignmentY = AlignmentY.Top; vb.Stretch = Stretch.None; vb.TileMode = TileMode.None; vb.Viewbox = new Rect(-11, i * height, width + 10, (i + 1) * height); vb.ViewboxUnits = BrushMappingMode.Absolute; RenderOptions.SetBitmapScalingMode(vb, BitmapScalingMode.Fant); Canvas canvas = new Canvas(); canvas.Background = vb; canvas.Height = height; canvas.Width = width; //FixedPage.SetLeft(canvas, 0); FixedPage.SetTop(canvas, 25); page.Children.Add(canvas); } pd.PrintDocument(document.DocumentPaginator, ((String.IsNullOrWhiteSpace(fe.Name) ? "Temp" : fe.Name) + " PRINT")); } finally { //// Scale UI control back to the original so we don't effect what is on the screen //fe.Width = double.NaN; //fe.UpdateLayout(); //fe.LayoutTransform = new ScaleTransform(1, 1); //Size size = new Size(capabilities.PageImageableArea.ExtentWidth, // capabilities.PageImageableArea.ExtentHeight); //fe.Measure(size); //fe.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, // capabilities.PageImageableArea.OriginHeight), size)); Mouse.OverrideCursor = null; } }
public void PrintPersonenLijst(string title, List <string> headerList, List <List <string> > cellList) { PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { FlowDocument fd = new FlowDocument(); Paragraph p = new Paragraph(new Run(title)); p.FontSize = 18; fd.Blocks.Add(p); Table table = new Table(); TableRowGroup tableRowGroup = new TableRowGroup(); TableRow r = new TableRow(); fd.PageWidth = printDialog.PrintableAreaWidth; fd.PageHeight = printDialog.PrintableAreaHeight; fd.BringIntoView(); fd.TextAlignment = TextAlignment.Center; fd.ColumnWidth = 500; table.CellSpacing = 1; for (int j = 0; j < headerList.Count; j++) { r.Cells.Add(new TableCell(new Paragraph(new Run(headerList[j])))); r.Cells[j].ColumnSpan = 9; //r.Cells[j].Padding = new Thickness(9); r.Cells[j].BorderBrush = Brushes.Black; r.Cells[j].FontWeight = FontWeights.Bold; r.Cells[j].Background = Brushes.LightGray; r.Cells[j].Foreground = Brushes.Black; r.Cells[j].BorderThickness = new Thickness(1, 1, 1, 1); } tableRowGroup.Rows.Add(r); table.RowGroups.Add(tableRowGroup); for (int i = 0; i < cellList.Count; i++) { TableRowGroup g = new TableRowGroup(); TableRow ro = new TableRow(); for (int j = 0; j < cellList[i].Count; j++) { ro.Cells.Add(new TableCell(new Paragraph(new Run(cellList[i][j])))); } for (int k = 0; k < cellList[0].Count; k++) { ro.Cells[k].ColumnSpan = 9; //ro.Cells[k].Padding = new Thickness(9); ro.Cells[k].BorderBrush = Brushes.Black; ro.Cells[k].FontWeight = FontWeights.Bold; ro.Cells[k].BorderThickness = new Thickness(1, 1, 1, 1); } g.Rows.Add(ro); table.RowGroups.Add(g); Debug.WriteLine(cellList[0].Count.ToString()); } fd.Blocks.Add(table); try { printDialog.PrintDocument(((IDocumentPaginatorSource)fd).DocumentPaginator, ""); } catch { MessageBox.Show("Probleem met afdrukken, herstart het programma en probeer het nog eens!", "Probleem met afdrukken"); } } }
public void Print(string name) { SourceCodePrintDocument printDocument = getPrintDocument(name); PrintDialog print = new PrintDialog() { Document = printDocument }; if (print.ShowDialog() == DialogResult.OK) { printDocument.Print(); } }
private void btn_imprimir_Click(object sender, EventArgs e) { string root = @"N:\PDF"; if (!Directory.Exists(root)) { Directory.CreateDirectory(root); } try { btn_imprimir.Enabled = false; int index = grd_Facturas.SelectedCells[0].RowIndex; objDocumentoCab = objListaDocumentoCab[index]; String codigoagenerar = "20300166611|01" + "|" + objDocumentoCab.DocumentoCabSerie + "|" + objDocumentoCab.DocumentoCabNro + "|" + objDocumentoCab.DocumentoCabIGV.ToString("C").Substring(3).Trim() + "|" + objDocumentoCab.DocumentoCabTotal.ToString("C").Substring(3).Trim() + "|" + objDocumentoCab.DocumentoCabFecha.ToString("dd-MM-yyyy") + "|" + "6|" + objDocumentoCab.DocumentoCabClienteDocumento + "|"; String nombreArchivo = objDocumentoCab.DocumentoCabSerie + "-" + objDocumentoCab.DocumentoCabNro; String qr = objProceso.genearQr(nombreArchivo, codigoagenerar); formatearFactura(qr); FacturaFecha cr = new FacturaFecha(); string rut = @"N:\PDF\20300166611-" + objDocumentoCab.DocumentoCabSerie + "-" + objDocumentoCab.DocumentoCabNro + ".pdf"; // System.Web.HttpResponse res = new System.Web.HttpResponse(); if (File.Exists(rut)) { File.Delete(rut); } cr.SetDataSource(objListFacturaReporte); cr.ExportToDisk(CrystalDecisions.Shared.ExportFormatType.PortableDocFormat, rut); using (PrintDialog Dialog = new PrintDialog()) { Dialog.ShowDialog(); ProcessStartInfo printProcessInfo = new ProcessStartInfo() { Verb = "print", CreateNoWindow = true, FileName = rut, WindowStyle = ProcessWindowStyle.Hidden }; Process printProcess = new Process(); printProcess.StartInfo = printProcessInfo; printProcess.Start(); printProcess.WaitForInputIdle(); Thread.Sleep(3000); if (false == printProcess.CloseMainWindow()) { printProcess.Kill(); } } btn_imprimir.Enabled = true; } catch (Exception ex) { MessageBox.Show("Error: " + ex.Message); btn_imprimir.Enabled = true; } }
public void Print() { List <string> files; if (Document is List <string> ) { files = (List <string>)Document; } else { files = new List <string>(); files.Add(Document.ToString()); } if (Settings is PrintDialog) { PrintDialog pDialog = (PrintDialog)Settings; OfficeHelper.ConvertWordToXPS(files); foreach (string file in files) { string xpsfile = file + ".xps"; XpsDocument document = new XpsDocument(xpsfile, FileAccess.Read); FixedDocumentSequence seq = document.GetFixedDocumentSequence(); FileInfo fileinfo = new FileInfo(file); pDialog.PrintDocument(seq.DocumentPaginator, fileinfo.Name); document.Close(); } } else { // one file only if (Printer == null) { Printer = printService.GetPrinter(); } if (Printer == null) { return; } string xpsfile = Document.ToString() + ".xps"; OfficeHelper.ConvertWordToXPS(files); PrintQueue pq = printService.GetPrintQueue(Printer.ToString()); PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = pq; // Display the dialog. This returns true if the user presses the Print button. Nullable <Boolean> print = pDialog.ShowDialog(); if (print == true) { XpsDocument document = new XpsDocument(xpsfile, FileAccess.Read); FixedDocumentSequence seq = document.GetFixedDocumentSequence(); FileInfo file = new FileInfo(Document.ToString()); pDialog.PrintDocument(seq.DocumentPaginator, file.Name); //dialog.ShowTaskDialog("Printing complete", "Printed to " + pDialog.PrintQueue.Name, "File printed: " + Document.ToString()); document.Close(); } } /* more crap that doesn't duplex * PrintQueue pq = Common.Services.PrintService.GetPrintQueue(Printer.ToString()); * if (pq == null) * { * dialog.ShowTaskDialog("Printer Problem", "Printer not set up or not available!", "Go to top menu -> Configuration -> My Details to set up your printer"); * return; * } * System.Printing.PrintTicket ticket = pq.DefaultPrintTicket; * PrintCapabilities capable = pq.GetPrintCapabilities(); * if (capable.DuplexingCapability.Contains(Duplexing.TwoSidedLongEdge)) * { * News.AddMessage("Printer can do duplex"); * ticket.Duplexing = Duplexing.TwoSidedLongEdge; * } * ticket.PageMediaSize = new PageMediaSize(PageMediaSizeName.ISOA4); * if (Settings != null) * { * if (Settings.ToString().Contains("landscape")) { ticket.PageOrientation = PageOrientation.Landscape; } * } * * XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq); * xpsdw.Write(seq, ticket); * document.Close(); */ /* * Word automation crap that doesn't duplex * try * { * Microsoft.Office.Interop.Word.Application app = new Microsoft.Office.Interop.Word.Application(); * app.Visible = false; * Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(Document); * * // print using word * object wb = app.WordBasic; * app.ActivePrinter = Printer.ToString(); * * if (Settings != null) * { * if (Settings.ToString().Contains("landscape")) { doc.PageSetup.Orientation = WdOrientation.wdOrientLandscape; } * } * * app.PrintOut(); * app.NormalTemplate.Saved = true; * app.Documents.Close(Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges); * app.Quit(); * } * catch (Exception ex) * { * News.AddError("DocxPrinter", ex.Message, ex); * return; * } */ }
private void 打印ToolStripMenuItem_Click(object sender, EventArgs e) { PrintDialog print = new PrintDialog(); print.ShowDialog(); }
private void toolStripPrintButton_Click(object sender, EventArgs e) { PrintDialog pd = new PrintDialog(); pd.ShowDialog(); }
private void bt_Print_Click(object sender, EventArgs e) { save_phone_addr(); if (tb_NO.Text.Trim().Length != 10) { MessageBox.Show("保单号长度错误,需10位"); return; } try { long.Parse(tb_NO.Text.Trim()); } catch { MessageBox.Show("保单号只能为数字"); return; } if (cb_Name.Text.Trim() == "") { MessageBox.Show("姓名不能为空"); return; } if (tb_CardNo.Text.Trim() == "") { MessageBox.Show("证件号码不能为空"); return; } this.tb_RandomNo.Text = System.DateTime.Now.Year.ToString().Remove(1, 1) + EagleAPI.GetRandom62(); if (!GlobalVar.b_OffLine) { if (cb_Name.Text != GlobalVar.HYXTESTPRINT) { HyxStructs hs = new HyxStructs(); hs.UserID = GlobalVar.loginName; hs.eNumber = tb_RandomNo.Text; hs.IssueNumber = tb_NO.Text; hs.NameIssued = cb_Name.Text; hs.CardType = "航班号" + tbFlightNo.Text + "乘机日" + tbFlightDate.Text; hs.CardNumber = tb_CardNo.Text; hs.Remark = "B01";//5"华安交通意外伤害保险";B01 hs.IssuePeriod = ""; hs.IssueBegin = dtp_Start.Value.ToShortDateString() + " 00:00:00"; hs.IssueEnd = dtp_End.Value.ToShortDateString() + " 00:00:00"; hs.SolutionDisputed = ""; hs.NameBeneficiary = tb_Benefit.Text; hs.Signature = this.tb_Signature.Text; hs.SignDate = dtp_Date.Value.ToShortDateString(); hs.InssuerName = ""; hs.Pnr = this.tb_PNR.Text; if (!hs.SubmitInfo()) { MessageBox.Show("数据提交失败!请检查保单号是否已被使用,或网络是否正常!"); return; } } } PrintDialog pd = new PrintDialog(); pd.Document = ptDoc; DialogResult dr = pd.ShowDialog(); if (dr == DialogResult.OK) { ptDoc.Print(); } }
private void reprint2() { if (lstItems.Items.Count < Convert.ToInt32(txtTotal.Text)) { MessageBox.Show(LabelPrintGlobal.ShowWarningMessage("NOT_FULL_QUANTITY_ERROR"), "ERROR", MessageBoxButtons.OK); return; } PrintDialog dlg = new PrintDialog(); if (dlg.ShowDialog() != DialogResult.OK) { return; } PrinterSettings setting = dlg.PrinterSettings; PrintLabelData data = new PrintLabelData(); data.PCode = txtCode.Text; data.DataCode = GetCodeDate(); data.Date = GetDate(); data.Total = Convert.ToInt32(txtTotal.Text); TPCResult <int> result = Database.GetModuleCount(m_Mode, txtCode.Text); if (result.State == RESULT_STATE.NG) { MessageBox.Show(result.Message); return; } data.Quantity = result.Value; string label_nameFrist = ""; string label_nameSecond = "fxzz_additional"; switch (m_Mode) { case PACK_MODE.Pack: label_nameFrist = "pack_fxzz"; break; case PACK_MODE.Carton: label_nameFrist = "carton_fxzz"; break; case PACK_MODE.Pallet: label_nameFrist = "pallet_fxzz"; break; } //打印第一页信息 TPCPrintLabel labelFrist = LabelPrintGlobal.g_LabelCreator.GetPrintLabel(label_nameFrist); List <string> parametersFrist = MakePrintParameters(m_Mode, data); //打印第二页信息 TPCPrintLabel labelSecond = LabelPrintGlobal.g_LabelCreator.GetPrintLabel(label_nameSecond); List <string> parametersSecond = MakePrintParameters(m_Mode, data); #region 修改打印参数 #region lotNo string lotNo = parametersSecond[14]; parametersSecond[14] = lotNo.Substring(0, lotNo.Length - 1); #endregion parametersSecond[5] = changeDateFormat(parametersSecond[14].Substring(3)); ///将时间格式9013改成2019-01-03 string changeDateFormat(string dateCode) { string outputTime = ""; string[] code = { dateCode.Substring(0, 1), dateCode.Substring(1, 2), dateCode.Substring(3, 1) }; #region 确定年月日 //确定年 string today = DateTime.Today.ToString("yyyy"); for (int i = 0; i < 10; i++) { if (today.Substring(3, 1).Equals(code[0])) { outputTime = today; } else { today = (Convert.ToInt16(today) - 1).ToString(); } } //确定月份和日 DateTime dtTemp = Convert.ToDateTime(outputTime + "-01-01"); GregorianCalendar gc = new GregorianCalendar(); for (int i = 0; i < 365; i++) { int weekOfYear = gc.GetWeekOfYear(dtTemp, CalendarWeekRule.FirstDay, DayOfWeek.Sunday); int dayOfWeek = (int)dtTemp.DayOfWeek + 1; if (weekOfYear == Convert.ToInt16(code[1]) && dayOfWeek == Convert.ToInt16(code[2])) { outputTime = dtTemp.ToString("yyyy-MM-dd"); break; } else { dtTemp = dtTemp.AddDays(1); } } #endregion return(outputTime); } #endregion switch (m_Mode) { case PACK_MODE.Pack: labelFrist.Print(setting, parametersFrist); dlg = new PrintDialog(); if (dlg.ShowDialog() != DialogResult.OK) { return; } setting = dlg.PrinterSettings; labelSecond.Print(setting, parametersSecond); break; case PACK_MODE.Carton: labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); dlg = new PrintDialog(); if (dlg.ShowDialog() != DialogResult.OK) { return; } setting = dlg.PrinterSettings; labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); break; case PACK_MODE.Pallet: labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); labelFrist.Print(setting, parametersFrist); dlg = new PrintDialog(); if (dlg.ShowDialog() != DialogResult.OK) { return; } setting = dlg.PrinterSettings; labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); labelSecond.Print(setting, parametersSecond); #region 富士康卡板A4纸张 //设置新纸张大小 dlg = new PrintDialog(); if (dlg.ShowDialog() != DialogResult.OK) { return; } setting = dlg.PrinterSettings; Print2 print2 = new Print2(txtCode.Text, parametersSecond[7], parametersSecond[5], parametersSecond[14]); DataTable dt = new DataTable(); dt.Columns.Add("No."); dt.Columns.Add("箱号"); dt.Columns.Add("料号"); dt.Columns.Add("数量"); int i = 0; //每行写上被包括的子标签数量等 TPCResult <List <List <string> > > items = null; bool queryInfo(string ID) { items = null; //m_Mode = PACK_MODE.Pack; items = Database.GetFXZZ_Data(ID); if (items.State == RESULT_STATE.NG) { MessageBox.Show(items.Message); return(false); } return(true); } foreach (ListViewItem var in lstItems.Items) { string id = var.SubItems[1].Text; if (!queryInfo(id)) { return; } if (items.Value.Count == 0) { continue; } DataRow dr = dt.NewRow(); dr["No."] = (++i).ToString(); dr["箱号"] = id; dr["料号"] = LabelPrintGlobal.g_Config.APN; dr["数量"] = items.Value[0][0].ToString(); dt.Rows.Add(dr); } print2.ImportDataTable(dt); if (print2.BtnPrint_Click(setting)) { print2.Dispose(); return; } print2.Dispose(); #endregion break; } //这里需要写入pnt_mng表 TPCResult <bool> ret = Database.SetManagerData(m_Mode, data.PCode, Program.LoginUser, Convert.ToInt32(data.Total), PACK_ACTION.Register, PACK_STATUS.Completed); if (ret.State == RESULT_STATE.NG) { MessageBox.Show(ret.Message); return; } }
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { switch (e.Button.Text) { case "打印": if (MDIParent.s_ObjCurrentPatient != null && MDIParent.s_ObjCurrentPatient.m_IntCharacter == 1) { bool blnIsCase = false; if (Static::clsEMR_StaticObject.s_ObjCurrentEmployee.m_strRoleNameArr != null) { int intRolesCount = Static::clsEMR_StaticObject.s_ObjCurrentEmployee.m_strRoleNameArr.Length; for (int i = 0; i < intRolesCount; i++) { if (Static::clsEMR_StaticObject.s_ObjCurrentEmployee.m_strRoleNameArr[i] == "病案室") { blnIsCase = true; break; } } } if (!blnIsCase) { clsPublicFunction.ShowInformationMessageBox("此病人病历为只读,不能打印!"); return; } } if (pd == null) { pd = new PrintDialog(); } if (string.IsNullOrEmpty(pd.PrinterSettings.PrinterName)) { pd.Document = printDocument1; pd.AllowPrintToFile = false; pd.ShowDialog(); } if (string.IsNullOrEmpty(pd.PrinterSettings.PrinterName)) //关闭打印设置后再次判断 { clsPublicFunction.ShowInformationMessageBox("请指定一台打印机!"); return; } m_blnControlPrint = true; printDocument1.Print(); m_blnControlPrint = false; break; case "打印机设置": if (pd == null) { pd = new PrintDialog(); } pd.Document = printDocument1; pd.ShowDialog(); break; case "续打": e.Button.Pushed = !e.Button.Pushed; m_blnContinuePrint = e.Button.Pushed; if (m_blnContinuePrint) { m_mniItem_Click(m_mniLine, EventArgs.Empty); } else { m_lblSpliter.Visible = false; m_mniClear_Click(null, null); } m_mthSyncFromPage(); m_blnIsContinuePrintPage = e.Button.Pushed; if (m_rdbSpecify.Checked) { m_nudFrom.Enabled = !m_blnContinuePrint; } break; case "关闭": this.Close(); break; } }
private void mitPrint_Click(object sender, RoutedEventArgs e) { int intCurrentRow = 0; int intCounter; int intColumns; int intNumberOfRecords; try { PrintDialog pdCancelledReport = new PrintDialog(); if (pdCancelledReport.ShowDialog().Value) { FlowDocument fdCancelledLines = new FlowDocument(); Thickness thickness = new Thickness(100, 50, 50, 50); fdCancelledLines.PagePadding = thickness; //Set Up Table Columns Table cancelledTable = new Table(); fdCancelledLines.Blocks.Add(cancelledTable); cancelledTable.CellSpacing = 0; intColumns = TheFindProjectsByDateRangeDataSet.FindProjectsByDateRange.Columns.Count; for (int intColumnCounter = 0; intColumnCounter < intColumns; intColumnCounter++) { cancelledTable.Columns.Add(new TableColumn()); } cancelledTable.RowGroups.Add(new TableRowGroup()); //Title row cancelledTable.RowGroups[0].Rows.Add(new TableRow()); TableRow newTableRow = cancelledTable.RowGroups[0].Rows[intCurrentRow]; newTableRow.Cells.Add(new TableCell(new Paragraph(new Run("Project Date Report")))); newTableRow.Cells[0].FontSize = 26; newTableRow.Cells[0].FontFamily = new FontFamily("Times New Roman"); newTableRow.Cells[0].ColumnSpan = intColumns; newTableRow.Cells[0].TextAlignment = TextAlignment.Center; newTableRow.Cells[0].Padding = new Thickness(0, 0, 0, 20); //Header Row cancelledTable.RowGroups[0].Rows.Add(new TableRow()); intCurrentRow++; newTableRow = cancelledTable.RowGroups[0].Rows[intCurrentRow]; newTableRow.Cells.Add(new TableCell(new Paragraph(new Run("Project ID")))); newTableRow.Cells.Add(new TableCell(new Paragraph(new Run("Assigned Project ID")))); newTableRow.Cells.Add(new TableCell(new Paragraph(new Run("Project Name")))); newTableRow.Cells.Add(new TableCell(new Paragraph(new Run("Entry Date")))); //Format Header Row for (intCounter = 0; intCounter < intColumns; intCounter++) { newTableRow.Cells[intCounter].FontSize = 11; newTableRow.Cells[intCounter].FontFamily = new FontFamily("Times New Roman"); newTableRow.Cells[intCounter].BorderBrush = Brushes.Black; newTableRow.Cells[intCounter].TextAlignment = TextAlignment.Center; newTableRow.Cells[intCounter].BorderThickness = new Thickness(); } intNumberOfRecords = TheFindProjectsByDateRangeDataSet.FindProjectsByDateRange.Rows.Count; //Data, Format Data for (int intReportRowCounter = 0; intReportRowCounter < intNumberOfRecords; intReportRowCounter++) { cancelledTable.RowGroups[0].Rows.Add(new TableRow()); intCurrentRow++; newTableRow = cancelledTable.RowGroups[0].Rows[intCurrentRow]; for (int intColumnCounter = 0; intColumnCounter < intColumns; intColumnCounter++) { newTableRow.Cells.Add(new TableCell(new Paragraph(new Run(TheFindProjectsByDateRangeDataSet.FindProjectsByDateRange[intReportRowCounter][intColumnCounter].ToString())))); newTableRow.Cells[intColumnCounter].FontSize = 12; newTableRow.Cells[0].FontFamily = new FontFamily("Times New Roman"); newTableRow.Cells[intColumnCounter].BorderBrush = Brushes.LightSteelBlue; newTableRow.Cells[intColumnCounter].BorderThickness = new Thickness(0, 0, 0, 1); newTableRow.Cells[intColumnCounter].TextAlignment = TextAlignment.Center; } } //Set up page and print fdCancelledLines.ColumnWidth = pdCancelledReport.PrintableAreaWidth; fdCancelledLines.PageHeight = pdCancelledReport.PrintableAreaHeight; fdCancelledLines.PageWidth = pdCancelledReport.PrintableAreaWidth; pdCancelledReport.PrintDocument(((IDocumentPaginatorSource)fdCancelledLines).DocumentPaginator, "Project Report"); intCurrentRow = 0; } } catch (Exception Ex) { TheMessagesClass.ErrorMessage(Ex.ToString()); TheEventLogClass.InsertEventLogEntry(DateTime.Now, "Blue Jay ERP \\ Project Date Search \\ Print Menu Item " + Ex.Message); } }
// call PrintDialog void PrintOnClick(object sender, RoutedEventArgs e) { PrintDialog dlg = new PrintDialog(); // init PrintQueue and PrintTicket if (prnqueue != null) { dlg.PrintQueue = prnqueue; } if (prntkt != null) { dlg.PrintTicket = prntkt; } if (dlg.ShowDialog().GetValueOrDefault()) { // save PrintQueue and PrintTicket prnqueue = dlg.PrintQueue; prntkt = dlg.PrintTicket; // create DrawingVisual DrawingVisual vis = new DrawingVisual(); DrawingContext dc = vis.RenderOpen(); Pen pn = new Pen(Brushes.Black, 1); // Rect for page minus margins Rect rectPage = new Rect( marginPage.Left, marginPage.Top, dlg.PrintableAreaWidth - (marginPage.Left + marginPage.Right), dlg.PrintableAreaHeight - (marginPage.Top + marginPage.Bottom)); // draw border rect dc.DrawRectangle(null, pn, rectPage); // create formatted text FormattedText formtxt = new FormattedText( String.Format("Hello, Printer! {0:F3} x {1:F3}", dlg.PrintableAreaWidth / 96, dlg.PrintableAreaHeight / 96), CultureInfo.CurrentCulture, FlowDirection.LeftToRight, new Typeface( new FontFamily("Times New Roman"), FontStyles.Italic, FontWeights.Normal, FontStretches.Normal), 48, Brushes.Black); // get physical size of this string Size sizeText = new Size(formtxt.Width, formtxt.Height); // center point Point ptText = new Point( rectPage.Left + (rectPage.Width - formtxt.Width) / 2, rectPage.Top + (rectPage.Height - formtxt.Height) / 2); // draw text and border dc.DrawText(formtxt, ptText); dc.DrawRectangle(null, pn, new Rect(ptText, sizeText)); // close drawing context dc.Close(); // print a page dlg.PrintVisual(vis, Title); } }
private void btnPrint_Click(object sender, EventArgs e) { PrintDialog PrintDialog1 = new PrintDialog(); PrintDialog1.ShowDialog(); }
//printing private void друкToolStripMenuItem_Click(object sender, EventArgs e) { PrintDialog printFile = new PrintDialog(); printFile.ShowDialog(); }
private void print_btn_Click(object sender, EventArgs e) { PrintDialog printDialog = new PrintDialog(); printDialog.ShowDialog(); }
private void toolBarMain_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e) { if (e.Button == toolBarBtnActPrint) { if (previewOptions.DisplayPrintDialog) { PrintDialog dlg = new PrintDialog(); dlg.AllowPrintToFile = false; dlg.AllowSomePages = true; dlg.Document = PreviewArea.Document; dlg.Document.PrinterSettings.MinimumPage = 1; dlg.Document.PrinterSettings.MaximumPage = 10000; dlg.Document.PrinterSettings.FromPage = 1; dlg.Document.PrinterSettings.ToPage = 100; if (dlg.ShowDialog(this) == DialogResult.OK) { PreviewArea.Document.Print(); } } else { PreviewArea.Document.Print(); } } if (e.Button == toolBarBtnActZoomAuto) { ZoomDisplay(0.0, MenuAuto); } if (e.Button == toolBarBtnOnePage) { PreviewArea.Columns = 1; PreviewArea.Rows = 1; } if (e.Button == toolBarBtnTwoPages) { PreviewArea.Columns = 2; PreviewArea.Rows = 1; } if (e.Button == toolBarBtnThreePages) { PreviewArea.Columns = 3; PreviewArea.Rows = 1; } if (e.Button == toolBarBtnFourPages) { PreviewArea.Columns = 2; PreviewArea.Rows = 2; } if (e.Button == toolBarBtnSixPages) { PreviewArea.Columns = 3; PreviewArea.Rows = 2; } if (e.Button == toolBarBtnFirstPage) { PreviewArea.StartPage = 0; PageRange.Text = (PreviewArea.StartPage + 1).ToString(); } if (e.Button == toolBarBtnPrevPage) { PreviewArea.StartPage -= 1; PageRange.Text = (PreviewArea.StartPage + 1).ToString(); } if (e.Button == toolBarBtnNextPage) { PreviewArea.StartPage += 1; PageRange.Text = (PreviewArea.StartPage + 1).ToString(); } if (e.Button == toolBarBtnLastPage) { PreviewArea.StartPage = int.MaxValue; PageRange.Text = (PreviewArea.StartPage + 1).ToString(); } if (e.Button == toolBarBtnScale) { toggleFitToPage(); } if (e.Button == toolBarBtnOrientation) { toggleOrientation(); } }
private void btnPrintBill_Click(object sender, EventArgs e) { PrintDialog dlg = new PrintDialog(); //Khởi tạo đối tượng PrintDialog dlg.ShowDialog(); //Hiển thị hộp thoại PrintDialog }
public void Print() { if (Settings is PrintDialog) { PrintDialog pDialog = (PrintDialog)Settings; string xpsfile = Document.ToString() + ".xps"; OfficeHelper.ConvertPPTXtoXPS(Document.ToString(), xpsfile); XpsDocument document = new XpsDocument(xpsfile, FileAccess.Read); FixedDocumentSequence seq = document.GetFixedDocumentSequence(); FileInfo file = new FileInfo(Document.ToString()); pDialog.PrintDocument(seq.DocumentPaginator, file.Name); document.Close(); } else { if (Printer == null) { Printer = printService.GetPrinter(); } if (Printer == null) { //dialog.ShowTaskDialog("Printer Problem", "Printer not set up or not available!", "Go to top menu -> Configuration -> My Details to set up your printer"); return; } string xpsfile = Document.ToString() + ".xps"; OfficeHelper.ConvertPPTXtoXPS(Document.ToString(), xpsfile); PrintQueue pq = printService.GetPrintQueue(Printer.ToString()); PrintDialog pDialog = new PrintDialog(); pDialog.PageRangeSelection = PageRangeSelection.AllPages; pDialog.UserPageRangeEnabled = true; pDialog.PrintQueue = pq; // Display the dialog. This returns true if the user presses the Print button. Nullable <Boolean> print = pDialog.ShowDialog(); if (print == true) { XpsDocument document = new XpsDocument(xpsfile, FileAccess.Read); FixedDocumentSequence seq = document.GetFixedDocumentSequence(); FileInfo file = new FileInfo(Document.ToString()); pDialog.PrintDocument(seq.DocumentPaginator, file.Name); document.Close(); } } /* * try * { * Microsoft.Office.Interop.PowerPoint.Application app; * try * { * app = new Microsoft.Office.Interop.PowerPoint.Application(); * } * catch (Exception ex) * { * News.AddError("PrintPPTX", "Problem with PowerPoint", ex); * return; * } * app.Visible = Microsoft.Office.Core.MsoTriState.msoTrue; * Microsoft.Office.Interop.PowerPoint.Presentation p = app.Presentations.Open(Document.ToString()); * p.PrintOptions.ActivePrinter = Printer.ToString(); * * if (Settings != null) * { * if (Settings.ToString().Contains("landscape")) { p.PageSetup.Orientation = WdOrientation.wdOrientLandscape; } * } * * p.PrintOut(); * p.Close(); * app.Quit(); * } * catch (Exception ex) * { * News.AddError("DocxPrinter", ex.Message, ex); * return; * } * dialog.ShowTaskDialog("Printing complete", "Printed to " + Printer.ToString(), "File printed: " + Document.ToString()); */ }
private void printPreviewToolStripMenuItem_Click(object sender, EventArgs e) { PrintDialog myPrintDialog = new PrintDialog(); myPrintDialog.currentTT = currentTT; myPrintDialog.ShowDialog(); }
private void GenerateLettersBtn_Click(object sender, EventArgs e) { PrintDocument document = new PrintDocument(); document.PrintPage += document_PrintPage; document.BeginPrint += document_BeginPrint; lettersTupleList = Bounced_Check_Manager_Data_Layer.LetterDAO.generateLetters(); if (lettersTupleList.Count == 0) { MessageBox.Show("No letters to print."); return; } // Choose printer PrintDialog printDialog1 = new PrintDialog(); printDialog1.Document = document; DialogResult result = printDialog1.ShowDialog(); if (result != DialogResult.OK) { return; } // Print the monster! document.Print(); foreach (var tuple in lettersTupleList) { Bounced_Check_Manager_Data_Layer.LetterDAO.create(tuple.Item1); } MessageBox.Show("Your letters are printing..."); }