static void Print(IWorkbook workbook) { Worksheet worksheet = workbook.Worksheets[0]; // Generate worksheet content - the simple multiplication table. CellRange columnHeadings = worksheet.Range.FromLTRB(1, 0, 40, 0); columnHeadings.Formula = "=COLUMN() - 1"; CellRange rowHeadings = worksheet.Range.FromLTRB(0, 1, 0, 40); rowHeadings.Formula = "=ROW() - 1"; CellRange tableRange = worksheet.Range.FromLTRB(1, 1, 40, 40); tableRange.Formula = "=(ROW()-1)*(COLUMN()-1)"; // Format headers of the multiplication table. Formatting rangeFormatting = columnHeadings.BeginUpdateFormatting(); rangeFormatting.Borders.BottomBorder.LineStyle = BorderLineStyle.Thin; rangeFormatting.Borders.BottomBorder.Color = Color.Black; columnHeadings.EndUpdateFormatting(rangeFormatting); rangeFormatting = rowHeadings.BeginUpdateFormatting(); rangeFormatting.Borders.RightBorder.LineStyle = BorderLineStyle.Thin; rangeFormatting.Borders.RightBorder.Color = Color.Black; rowHeadings.EndUpdateFormatting(rangeFormatting); rangeFormatting = tableRange.BeginUpdateFormatting(); rangeFormatting.Fill.BackgroundColor = Color.LightBlue; tableRange.EndUpdateFormatting(rangeFormatting); #region #WorksheetPrintOptions worksheet.ActiveView.Orientation = PageOrientation.Landscape; // Display row and column headings. worksheet.ActiveView.ShowHeadings = true; worksheet.ActiveView.PaperKind = System.Drawing.Printing.PaperKind.A4; // Access an object that contains print options. WorksheetPrintOptions printOptions = worksheet.PrintOptions; // Print in black and white. printOptions.BlackAndWhite = true; // Do not print gridlines. printOptions.PrintGridlines = false; // Scale the print area to fit to two pages wide. printOptions.FitToPage = true; printOptions.FitToWidth = 2; // Print a dash instead of a cell error message. printOptions.ErrorsPrintMode = ErrorsPrintMode.Dash; #endregion #WorksheetPrintOptions #region #PrintWorkbook // Invoke the Print Preview dialog for the workbook. using (LegacyPrintableComponentLink link = new LegacyPrintableComponentLink(workbook)) { link.CreateDocument(); link.ShowPrintPreviewDialog(App.Current.MainWindow); } #endregion #PrintWorkbook }
private void Button_Click(object sender, RoutedEventArgs e) { RichEditDocumentServer documentServer = new RichEditDocumentServer(); documentServer.Text = "RichEditDocumentServer Print Preview."; LegacyPrintableComponentLink link = new LegacyPrintableComponentLink(documentServer); DocumentPreviewWindow window = new DocumentPreviewWindow(); window.PreviewControl.DocumentSource = link; link.CreateDocument(false); window.ShowDialog(); }
protected internal void WordPrint(string text) { reds.RtfText = text; LegacyPrintableComponentLink link = new LegacyPrintableComponentLink(reds); dpc = new DocumentPreviewControl(); dpc.DocumentSource = link; link.CreateDocument(); dpc.PrintCommand.Execute(null); }
protected internal void PicturePrint(MemoryStream image) { reds.Document.Sections[0].Page.PaperKind = System.Drawing.Printing.PaperKind.A4; reds.Document.Unit = DevExpress.Office.DocumentUnit.Centimeter; reds.Document.Sections[0].Paragraphs[0].Alignment = ParagraphAlignment.Center; reds.Document.Shapes.InsertPicture(reds.Document.Sections[0].Paragraphs[0].Range.Start, DocumentImageSource.FromStream(new MemoryStream(image.ToArray()))); reds.Document.Shapes[0].LockAspectRatio = true; reds.Document.Shapes[0].HorizontalAlignment = ShapeHorizontalAlignment.Center; reds.Document.Shapes[0].VerticalAlignment = ShapeVerticalAlignment.Center; float X = (reds.Document.Sections[0].Page.Width - 2) / reds.Document.Shapes[0].Size.Width; float Y = (reds.Document.Sections[0].Page.Height - 2) / reds.Document.Shapes[0].Size.Height; reds.Document.Shapes[0].ScaleX = reds.Document.Shapes[0].ScaleY = X > Y ? Y : X; LegacyPrintableComponentLink link = new LegacyPrintableComponentLink(reds); dpc = new DocumentPreviewControl(); dpc.DocumentSource = link; link.CreateDocument(); dpc.PrintCommand.Execute(null); }
private void UsePrintingLibrary() { #region #PrintableComponentLink //Initialize a new server and printer PrintDialog printDialog = new PrintDialog(); RichEditDocumentServer docServer = new RichEditDocumentServer(); //Pass the document content to the server docServer.RtfText = richEdit.RtfText; //Change the document layout docServer.Document.Sections[0].Page.Landscape = true; docServer.Document.Sections[0].Page.PaperKind = PaperKind.A4; //Create a new component link LegacyPrintableComponentLink printableComponent = new LegacyPrintableComponentLink(docServer); //Create a document to print printableComponent.CreateDocument(false); //Silently print the document printableComponent.PrintDirect(); #endregion #PrintableComponentLink }