internal static void DoPreview(DocumentPaginator fd, Window owner, string title) { //FlowDocumentScrollViewer visual = (FlowDocumentScrollViewer)(_parent.FindName("fdsv1")); var ms = new MyMemoryStream(); using (var pkg = System.IO.Packaging.Package.Open(ms, FileMode.Create)) { using (XpsDocument doc = new XpsDocument(pkg)) { XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); writer.Write(fd); } } //ms.ToArray() ms.Position = 0; var pkg2 = System.IO.Packaging.Package.Open(ms); // Read the XPS document into a dynamically generated // preview Window var url = new Uri("memorystream://printstream"); PackageStore.AddPackage(url, pkg2); try { using (XpsDocument doc = new XpsDocument(pkg2, CompressionOption.SuperFast, url.AbsoluteUri)) { FixedDocumentSequence fds = doc.GetFixedDocumentSequence(); string s = _previewWindowXaml; s = s.Replace("@@TITLE", title.Replace("'", "'")); using (var reader = new System.Xml.XmlTextReader(new StringReader(s))) { Window preview = System.Windows.Markup.XamlReader.Load(reader) as Window; DocumentViewer dv1 = LogicalTreeHelper.FindLogicalNode(preview, "dv1") as DocumentViewer; dv1.Document = fds as IDocumentPaginatorSource; preview.Owner = owner; preview.ShowDialog(); } } } finally { PackageStore.RemovePackage(url); } }
/// <summary> /// Dispose the object. /// </summary> protected void Dispose() { if (!_disposed) { _disposed = true; // Cleanup all state associated with Paginator. if (_documentPaginator != null) { _documentPaginator.GetPageCompleted -= new GetPageCompletedEventHandler(HandleGetPageCompleted); _documentPaginator.PagesChanged -= new PagesChangedEventHandler(HandlePagesChanged); _documentPaginator.CancelAsync(this); DisposeCurrentPage(); DisposeAsyncPage(); } Invariant.Assert(_documentPage == null); Invariant.Assert(_documentPageAsync == null); _documentPaginator = null; _textView = null; } }
/// <summary>МЕТОД Быстрая Печать</summary> public void MyPrintNow() { PrintDialog _PrintDialog = new PrintDialog(); _PrintDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue(); _PrintDialog.UserPageRangeEnabled = true; //_PrintDialog.PrintTicket.PageOrientation = PageOrientation.Landscape; try { DocumentPaginator _Paginator = this.Document.DocumentPaginator; if (_PrintDialog.PageRangeSelection == PageRangeSelection.UserPages) { _Paginator = new UserPrint(this.Document.DocumentPaginator, _PrintDialog.PageRange); } _PrintDialog.PrintDocument(_Paginator, "BazisWPF"); } catch { MessageBox.Show("Ошибка Печати"); } }
/// <summary> /// Loads a document and saves all pages as images. /// </summary> /// <remarks> /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/save-document-as-image-net-csharp-vb.php /// </remarks> static void SaveToImage() { string filePath = @"..\..\example.docx"; DocumentCore dc = DocumentCore.Load(filePath); string folderPath = Path.GetFullPath(@"Result-files"); DocumentPaginator dp = dc.GetPaginator(); for (int i = 0; i < dp.Pages.Count; i++) { DocumentPage page = dp.Pages[i]; // For example, set DPI: 72, Background: White. Bitmap image = page.Rasterize(72, SautinSoft.Document.Color.White); Directory.CreateDirectory(folderPath); image.Save(folderPath + @"\Page - " + i.ToString() + ".png", ImageFormat.Png); } System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(folderPath) { UseShellExecute = true }); }
private void LoadedHandler(object sender, RoutedEventArgs e) { // We have to clone the FlowDocument before we use different pagination settings for the export. FlowDocument clone = ViewModel.Document.CloneContent(); clone.ColumnWidth = double.PositiveInfinity; var packageStream = new MemoryStream(); package = Package.Open(packageStream, FileMode.Create, FileAccess.ReadWrite); PackageStore.AddPackage(new Uri(PackagePath), package); xpsDocument = new XpsDocument(package, CompressionOption.SuperFast, PackagePath); using (var policy = new XpsPackagingPolicy(xpsDocument)) using (var serializer = new XpsSerializationManager(policy, false)) { DocumentPaginator paginator = ((IDocumentPaginatorSource)clone).DocumentPaginator; serializer.SaveAsXaml(paginator); } documentViewer.Document = xpsDocument.GetFixedDocumentSequence(); documentViewer.Focus(); }
public static int SaveAsXps(FlowDocument doc, string fileName, Size printableArea) { doc.ColumnWidth = printableArea.Width; using (Package container = Package.Open(fileName, FileMode.Create)) { using (XpsDocument xpsDoc = new XpsDocument(container, CompressionOption.Maximum)) { XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false); DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator; paginator.ComputePageCount(); DocumentPaginator newPaginator = new DocumentPaginatorWrapper( paginator, printableArea, new Size(8, 8)); rsm.SaveAsXaml(paginator); } } return(0); }
private Border GetPageUiElement(int i, DocumentPaginator paginator, double scale) { var source = paginator.GetPage(i); var border = new Border() { Background = Brushes.White }; border.Margin = new Thickness(10 * scale); border.BorderBrush = Brushes.DarkGray; border.BorderThickness = new Thickness(1); //var margin = PrintUtility.GetPageMargin(CurrentPrinterName); var margin = new Thickness(); var rectangle = new Rectangle(); rectangle.Width = ((source.Size.Width * 0.96 - (margin.Left + margin.Right)) * scale); rectangle.Height = ((source.Size.Height * 0.96 - (margin.Top + margin.Bottom)) * scale); rectangle.Margin = new Thickness(margin.Left * scale, margin.Top * scale, margin.Right * scale, margin.Bottom * scale); rectangle.Fill = Brushes.White; var vb = new VisualBrush(source.Visual); vb.Opacity = 1; vb.Stretch = Stretch.Uniform; rectangle.Fill = vb; border.Child = rectangle; return border; }
/* Written By Jordan Leibman * 12/5/17 * PrintRef_Executed is a refined Printing function that prevents the Editor from halting. * It functions by using the XPS class features and copying the printed document into a new document that is then printed * Reference for pseudocode was pulled from the MSDN forums. * TODO: Full Testing and integration with other features. */ private void PrintRef_Executed(object sender, ExecutedRoutedEventArgs e) { //makes a new text range copy TextRange source = new TextRange(rtbEditor.Document.ContentStart, rtbEditor.Document.ContentEnd); MemoryStream stream = new MemoryStream(); source.Save(stream, DataFormats.Xaml); //saves the copy into new FlowDocument FlowDocument print = new FlowDocument(); TextRange copy = new TextRange(print.ContentStart, print.ContentEnd); copy.Load(stream, DataFormats.Xaml); //Makes a new PrintDocument based on the selected printing size PrintDocumentImageableArea area = null; XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(ref area); if (writer != null && area != null) { DocumentPaginator paginator = ((IDocumentPaginatorSource)print).DocumentPaginator; paginator.PageSize = new Size(area.MediaSizeWidth, area.MediaSizeHeight); Thickness padding = print.PagePadding; //sets margins within the printed document print.PagePadding = new Thickness( Math.Max(area.OriginWidth, padding.Left), Math.Max(area.OriginHeight, padding.Top), Math.Max(area.MediaSizeWidth - (area.OriginWidth + area.ExtentWidth), padding.Right), Math.Max(area.MediaSizeWidth - (area.OriginHeight + area.ExtentHeight), padding.Bottom) ); //removes columns from the document print.ColumnWidth = double.PositiveInfinity; //XPS write writer.Write(paginator); } }
private void MI_Print_Click(object sender, RoutedEventArgs e) { // write the text file to storage FileManager.WriteTextFile(Smashers); // show the dialog PrintDialog printDialog = new PrintDialog(); if ((bool)printDialog.ShowDialog()) { try { // generate the data TextReader reader = new StreamReader(CharacterFileManager.TxtFilePath); string[] names = reader.ReadToEnd().Split('\n'); reader.Close(); // build the document FlowDocument doc = new FlowDocument(); int lineCount = 1; Paragraph paragraph = new Paragraph(); paragraph.Margin = new Thickness(50); paragraph.LineHeight = 15; foreach (string s in names) { string lineText = lineCount.ToString() + ") " + s + "\n"; lineCount++; if (!string.IsNullOrWhiteSpace(s)) { paragraph.Inlines.Add(new Run(lineText)); } } doc.Blocks.Add(paragraph); DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator; printDialog.PrintDocument(paginator, "Sm4sh Character List"); } catch (Exception ex) { MessageBox.Show("There was an error printing the file: " + ex.Message); } } }
public GoblinMarket() { // Access the document stored as an application resource. StreamResourceInfo info = Application.GetResourceStream( new Uri("pack://application:,,/GoblinMarket.xps")); // Open a package from the resources stream. Package pack = Package.Open(info.Stream, FileMode.Open, FileAccess.Read); // Add a URI to the package store. string strUri = "memorystream://GoblinMarket.xps"; Uri uriPackage = new Uri(strUri); PackageStore.AddPackage(uriPackage, pack); // Get the XPS file. XpsDocument xps = new XpsDocument(pack, CompressionOption.Normal, strUri); // Get a paginator for the fixed documents in the XPS file. FixedDocumentSequence seq = xps.GetFixedDocumentSequence(); DocumentPaginator paginator = seq.DocumentPaginator; // Plan is to get a Visual for each page in the document. Visual[] visuals = new Visual[paginator.PageCount]; for (int i = 0; i < paginator.PageCount; i++) { visuals[i] = paginator.GetPage(i).Visual; } // Close the file. xps.Close(); // Create BookViewport to display book. BookViewport viewer = new BookViewport(visuals); Content = viewer; }
private static void OnPrint(object sender, ExecutedRoutedEventArgs e) { RichTextEditor control = (RichTextEditor)sender; RichTextBox richTextBox = control.RichTextBox; // Serialize RichTextBox content into a stream in Xaml format. Note: XamlPackage format isn't supported in partial trust. TextRange sourceDocument = new TextRange(richTextBox.Document.ContentStart, richTextBox.Document.ContentEnd); MemoryStream stream = new MemoryStream(); sourceDocument.Save(stream, DataFormats.Xaml); // Clone the source document's content into a new FlowDocument. FlowDocument flowDocumentCopy = new FlowDocument(); TextRange copyDocumentRange = new TextRange(flowDocumentCopy.ContentStart, flowDocumentCopy.ContentEnd); copyDocumentRange.Load(stream, DataFormats.Xaml); // Creates a XpsDocumentWriter object, opens a Windows common print dialog and // returns a ref parameter that represents information about the dimensions of the media. PrintDocumentImageableArea ia = null; XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(ref ia); if (docWriter != null && ia != null) { DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocumentCopy).DocumentPaginator; // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device. paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight); Thickness pagePadding = flowDocumentCopy.PagePadding; flowDocumentCopy.PagePadding = new Thickness( Math.Max(ia.OriginWidth, pagePadding.Left), Math.Max(ia.OriginHeight, pagePadding.Top), Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), pagePadding.Right), Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), pagePadding.Bottom)); flowDocumentCopy.ColumnWidth = double.PositiveInfinity; // Send DocumentPaginator to the printer. docWriter.Write(paginator); } }
SerializeNextDocumentPage( NGCSerializerContext context ) { NGCDocumentPaginatorSerializerContext paginatorContext = context as NGCDocumentPaginatorSerializerContext; if (paginatorContext != null) { DocumentPaginator paginator = paginatorContext.Paginator; int index = paginatorContext.Index; if (!paginator.IsPageCountValid || (index < paginator.PageCount)) { index++; NGCDocumentPaginatorSerializerContext nextContext = new NGCDocumentPaginatorSerializerContext(this, paginator, index, SerializerAction.serializeNextDocumentPage); NgcSerializationManager.OperationStack.Push(nextContext); DocumentPage page = Toolbox.GetPage(paginator, index - 1); ReachSerializer serializer = SerializationManager.GetSerializer(page); if (serializer != null) { serializer.SerializeObject(page); } } } else { } }
public static FixedDocument ConvertFrom(FlowDocument doc, Size pageSize, Thickness pageMargin) { FixedDocument fixedDoc = new FixedDocument(); fixedDoc.DocumentPaginator.PageSize = InchesToDpi(pageSize); pageSize = InchesToDpi(GetCoreSize(pageSize, pageMargin)); pageMargin = InchesToDpi(pageMargin); DocumentPaginator paginator = (doc as IDocumentPaginatorSource).DocumentPaginator; paginator.PageSize = pageSize; if (!paginator.IsPageCountValid) { paginator.ComputePageCount(); } int pages = paginator.PageCount; for (int i = 0; i < pages; i++) { DocumentPage page = paginator.GetPage(i); FixedPage fp = new FixedPage(); fp.Children.Add(new Border() { Width = pageSize.Width, Height = pageSize.Height, Margin = pageMargin, Background = new VisualBrush(page.Visual) }); fixedDoc.Pages.Add(new PageContent() { Child = fp }); } return(fixedDoc); }
private void DoThePrint(FlowDocument document) { // Clone the source document's content into a new FlowDocument. // This is because the pagination for the printer needs to be // done differently than the pagination for the displayed page. // We print the copy, rather that the original FlowDocument. MemoryStream s = new MemoryStream(); TextRange source = new TextRange(document.ContentStart, document.ContentEnd); source.Save(s, DataFormats.Xaml); FlowDocument doc = GetPrintFlowDocument(); ForceRenderFlowDocument(doc); // get information about the dimensions of the seleted printer+media. System.Printing.PrintDocumentImageableArea ia = null; System.Windows.Xps.XpsDocumentWriter docWriter = System.Printing.PrintQueue.CreateXpsDocumentWriter(ref ia); if (docWriter != null && ia != null) { DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator; // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device. paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight); Thickness t = new Thickness(72); // copy.PagePadding; doc.PagePadding = new Thickness( Math.Max(ia.OriginWidth, t.Left), Math.Max(ia.OriginHeight, t.Top), Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), t.Right), Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), t.Bottom)); doc.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); } }
SerializeObject( Object serializedObject ) { NgcSerializationManager ngcManager = SerializationManager as NgcSerializationManager; DocumentPaginator paginator = (DocumentPaginator)serializedObject; // // For FlowDocument, the application might attach a PrintTicket DP on it. // DependencyObject dependencyObject = paginator != null ? paginator.Source as DependencyObject : null; if (dependencyObject != null) { if (!ngcManager.IsPrintTicketEventHandlerEnabled) { //ngcManager.FdPrintTicket = dependencyObject.GetValue(FixedDocument.PrintTicketProperty) as PrintTicket; } } ngcManager.StartDocument(paginator, true); if (paginator != null) { for (int i = 0; !paginator.IsPageCountValid || (i < paginator.PageCount); i++) { DocumentPage page = Toolbox.GetPage(paginator, i); ReachSerializer serializer = SerializationManager.GetSerializer(page); if (serializer != null) { serializer.SerializeObject(page); } } } ngcManager.EndDocument(); }
//int minimalOffset = 0; /// <summary> /// Helper method to create page header o footer from flow document template /// </summary> /// <param name="fd"></param> /// <param name="pageDef"></param> /// <returns></returns> public static XpsDocument CreateXpsDocument(FlowDocument fd, PageDefinition pageDef) { MemoryStream ms = new MemoryStream(); Package pkg = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite); string pack = "pack://" + fd.Name + System.Guid.NewGuid().ToString() + ".xps"; PackageStore.AddPackage(new Uri(pack), pkg); XpsDocument doc = new XpsDocument(pkg, CompressionOption.SuperFast, pack); XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false); DocumentPaginator paginator = ((IDocumentPaginatorSource)fd).DocumentPaginator; // Size size = new Size(800, 1024); // ReportPaginator rp = new ReportPaginator(paginator, PrintHelper.GetPageSize(), pageDef); // ReportPaginator rp = new ReportPaginator(paginator, size, pageDef); LabelPaginator rp = new LabelPaginator(paginator, LabelPrintHelper.GetPageSize(), pageDef); rsm.SaveAsXaml(rp); return(doc); }
public void SaveSingleFlowContentDocument( string containerName, bool async) { // Create flow content DocumentPaginator idp = _xpfContent.CreateFlowDocument().DocumentPaginator; // Create a saving XPSDocumentWriter // (temp file in current working directory). XpsDocumentWriter xdwSave = GetSaveXpsDocumentWriter(containerName); // Save content using helper function if (async) { SaveSingleFlowContentDocumentAsync(xdwSave, idp); } else { SaveSingleFlowContentDocument(xdwSave, idp); _xpsDocument.Close(); // Close the pakcage } }
/* Send it */ private void PrintPages(XpsDocumentWriter xpsdw, FixedDocument fixdoc, bool print_all, int from, int to, PrintTicket Ticket) { m_docWriter = xpsdw; xpsdw.WritingCompleted += new WritingCompletedEventHandler(AsyncCompleted); xpsdw.WritingProgressChanged += new WritingProgressChangedEventHandler(AsyncProgress); DocumentPaginator paginator = fixdoc.DocumentPaginator; try { if (print_all) { m_first_page = 1; m_num_pages = paginator.PageCount; xpsdw.Write(paginator, Ticket); } else { /* Create an override paginator to pick only the pages we want */ GSDocumentPaginator gspaginator = new GSDocumentPaginator(paginator, from, to); m_first_page = from; m_num_pages = paginator.PageCount; xpsdw.Write(gspaginator, Ticket); } } catch (Exception) { /* Something went wrong with this particular print driver * simply notify the user and clean up everything */ gsPrintEventArgs info = new gsPrintEventArgs(PrintStatus_t.PRINT_ERROR, false, 0, this.m_first_page, this.m_num_pages, this.m_filename); PrintUpdate(this, info); return; } }
}// end:PrintMultipleVisuals() // ------------------ PrintSingleFlowContentDocument ------------------ /// <summary> /// Prints the content of a single flow document.</summary> /// <param name="pq"> /// The print queue to print to.</param> /// <param name="async"> /// true to print asynchronously; false to print synchronously.</param> public void PrintSingleFlowContentDocument(PrintQueue pq, bool async) { // Create a paginated flow document. DocumentPaginator idp = _wpfContent.CreateFlowDocument().DocumentPaginator; // Create a document writer to print to. XpsDocumentWriter xdwPrint = GetPrintXpsDocumentWriter(pq); // Scale the paginated flow document to a visual for printing. Visual visual = _wpfContent.AdjustFlowDocumentToPage(idp, pq); // Print either asynchronously or synchronously. if (async) { PrintVisual(xdwPrint, visual); } else { PrintVisualAsync(xdwPrint, visual); } }// end:PrintSingleFlowContentDocument()
// Serializes a snapshot of the FlowDocument in view to XPS (output.container) private void XPSClick(object sender, RoutedEventArgs e) { Microsoft.Win32.SaveFileDialog sfd = new Microsoft.Win32.SaveFileDialog(); sfd.OverwritePrompt = true; sfd.Title = "Serialize to XPS Document"; sfd.DefaultExt = "xps"; sfd.Filter = "XPS Document(*.xps)|*.xps"; bool? success = sfd.ShowDialog(); if (success.HasValue == false || success == false) { return; } DocumentPaginator paginator = ((IDocumentPaginatorSource)currentFlowDocumentReader.Document).DocumentPaginator; Package pckg = Package.Open(sfd.FileName, FileMode.Create); XpsDocument xd = new XpsDocument(pckg); XpsDocumentWriter xdp = XpsDocument.CreateXpsDocumentWriter(xd); xdp.Write(paginator); xd.Close(); }
private static void CreateXps(FlowDocument tempFlow, string tempFile, PrintSettings settings) { //flowDocument, out exceptions, CheckGreyMark(mark, blackAndWhite), showNumber, face, blackAndWhite ? Brushes.Black : brush, useLeading, fontSize, from, till, useOldNumbering, blackAndWhite ? Brushes.Transparent : backBrush // var stream = new MemoryStream(); using (Package package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite)) { XpsDocument xpsDoc; using (xpsDoc = new XpsDocument(package, CompressionOption.Maximum)) { var rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false); DocumentPaginator paginator = ((IDocumentPaginatorSource)tempFlow).DocumentPaginator; paginator = new DocumentPaginatorWrapper(paginator) { ContentPageSize = new Size(paginator.PageSize.Width, paginator.PageSize.Height), ContentMargin = new Size(48, 48), Mark = settings.UseWatermark ? CheckGreyMark(settings.Watermark, settings.UseBlackAndWhite):null, FooterTypeface = new Typeface(settings.PageCountElement.FontFamily, FontStyles.Normal, FontWeights.Normal, FontStretches.Normal), ForegroundBrush = settings.UseBlackAndWhite ? Brushes.Black : settings.PageCountElement.ForgroundBrush, ShowNumbering = settings.ShowPageNumber, UseLeadingZero = settings.PageCountElement.UseLeadingZero, FooterFontSize = settings.PageCountElement.FontSize, FirstPritedPage = settings.From, LastPrintedPage = settings.Till, UseOldNumbering = settings.UseOldNumbering, BackgroundBrush = settings.UseBlackAndWhite ? Brushes.White : settings.BackgroundBrush }; ((DocumentPaginatorWrapper)paginator).ComputeValues(); rsm.SaveAsXaml(paginator); rsm.Commit(); } } stream.Position = 0; using (var fileStream = new FileStream(tempFile, FileMode.CreateNew, FileAccess.ReadWrite)) { stream.CopyTo(fileStream); } }
// <SampleCode1> /// <summary> /// Print all pages of an XPS document. /// Optionally, hide the print dialog window. /// </summary> /// <param name="xpsFilePath">Path to source XPS file</param> /// <param name="hidePrintDialog">Whether to hide the print dialog window (shown by default)</param> /// <returns>Whether the document printed</returns> public static bool PrintWholeDocument(string xpsFilePath, bool hidePrintDialog = false) { // Create the print dialog object and set options. PrintDialog printDialog = new(); if (!hidePrintDialog) { // Display the dialog. This returns true if the user presses the Print button. bool?isPrinted = printDialog.ShowDialog(); if (isPrinted != true) { return(false); } } // Print the whole document. try { // Open the selected document. XpsDocument xpsDocument = new(xpsFilePath, FileAccess.Read); // Get a fixed document sequence for the selected document. FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence(); // Create a paginator for all pages in the selected document. DocumentPaginator docPaginator = fixedDocSeq.DocumentPaginator; // Print to a new file. printDialog.PrintDocument(docPaginator, $"Printing {Path.GetFileName(xpsFilePath)}"); return(true); } catch (Exception e) { MessageBox.Show(e.Message); return(false); } }
SerializeNextDocumentPage( ReachSerializerContext context ) { DocumentPaginatorSerializerContext paginatorContext = context as DocumentPaginatorSerializerContext; if (paginatorContext != null) { DocumentPaginator paginator = paginatorContext.Paginator; int index = paginatorContext.Index; if (!paginator.IsPageCountValid || (index < paginator.PageCount)) { index++; DocumentPaginatorSerializerContext collectionContext = new DocumentPaginatorSerializerContext(this, paginatorContext.ObjectContext, paginator, index, SerializerAction.serializeNextDocumentPage); ((IXpsSerializationManagerAsync)SerializationManager).OperationStack.Push(collectionContext); DocumentPage page = Toolbox.GetPage(paginator, index - 1); ReachSerializer serializer = SerializationManager.GetSerializer(page); if (serializer != null) { serializer.SerializeObject(page); } } } else { } }
private void PrintPlaintext(string text, string docName, int copies) { // Clone the source document's content into a new FlowDocument. FlowDocument flowDocumentCopy = new FlowDocument(); flowDocumentCopy.Blocks.Add(new Paragraph(new Run(docName))); flowDocumentCopy.Blocks.Add(new Paragraph(new Run(text))); // Create a XpsDocumentWriter object, open a Windows common print dialog. // This methods returns a ref parameter that represents information about the dimensions of the printer media. PrintDocumentImageableArea ia = null; XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(ref ia); if (docWriter == null || ia == null) { throw new NullReferenceException(); } DocumentPaginator paginator = ((IDocumentPaginatorSource)flowDocumentCopy).DocumentPaginator; // Change the PageSize and PagePadding for the document to match the CanvasSize for the printer device. paginator.PageSize = new Size(ia.MediaSizeWidth, ia.MediaSizeHeight); Thickness pagePadding = flowDocumentCopy.PagePadding; flowDocumentCopy.PagePadding = new Thickness( Math.Max(ia.OriginWidth, pagePadding.Left), Math.Max(ia.OriginHeight, pagePadding.Top), Math.Max(ia.MediaSizeWidth - (ia.OriginWidth + ia.ExtentWidth), pagePadding.Right), Math.Max(ia.MediaSizeHeight - (ia.OriginHeight + ia.ExtentHeight), pagePadding.Bottom)); flowDocumentCopy.ColumnWidth = double.PositiveInfinity; PrintDialog dialog = new PrintDialog(); for (int i = 0; i < copies; i++) { dialog.PrintDocument(paginator, "asfd"); } }
/// <summary>МЕТОД Печать</summary> protected override void OnPrintCommand() { PrintDialog _PrintDialog = new PrintDialog(); _PrintDialog.PrintQueue = LocalPrintServer.GetDefaultPrintQueue(); _PrintDialog.UserPageRangeEnabled = true; if (_PrintDialog.ShowDialog() == true) { try { DocumentPaginator _Paginator = this.Document.DocumentPaginator; if (_PrintDialog.PageRangeSelection == PageRangeSelection.UserPages) { _Paginator = new UserPrint(this.Document.DocumentPaginator, _PrintDialog.PageRange); } _PrintDialog.PrintDocument(_Paginator, "BazisWPF"); } catch { MessageBox.Show("Ошибка!"); } } }
private void PrintButton_Click(object sender, RoutedEventArgs e) { try { //forPrint.PageHeight = InchToPoint(paperSizeA4.Height); // paperSizeA4.Height: integer value //forPrint.PageWidth = forPrint.ColumnWidth = InchToPoint(paperSizeA4.Width); // paperSizeA4.Width: integer value forPrint.PagePadding = new Thickness(40); DocumentPaginator docPaginator = ((IDocumentPaginatorSource)forPrint).DocumentPaginator; docPaginator.ComputePageCount(); this.IsEnabled = false; PrintDialog My_printDialog = new PrintDialog(); if (My_printDialog.ShowDialog() == true) { My_printDialog.PrintDocument(docPaginator, "My PDF print"); } } finally { this.IsEnabled = true; } }
public void PrintFlowDocument(FlowDocument documentProvider, PageOrientation pageOrientation = PageOrientation.Portrait, bool includeFooter = true) { PrintDialog dlg = new PrintDialog(); if ((bool)dlg.ShowDialog().GetValueOrDefault()) { using (new SpinnyCursor()) { var doc = documentProvider; DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator; if (includeFooter) { paginator = new FooteredDocumentPaginator(paginator, paginator.PageSize, new Size(0.0, 0.0), includeFooter); } dlg.PrintTicket.PageOrientation = pageOrientation; dlg.PrintDocument(paginator, "MSO Report"); } } }
/// <summary> /// Load a document and save all pages as separate PNG & Jpeg images. /// </summary> /// <remarks> /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/pagination-save-document-pages-as-png-jpg-jpeg-net-csharp-vb.php /// </remarks> static void SeparateDocumentToImagePages() { string filePath = @"..\..\example.docx"; DocumentCore dc = DocumentCore.Load(filePath); string folderPath = Path.GetFullPath(@"Result-files"); DocumentPaginator dp = dc.GetPaginator(); for (int i = 0; i < dp.Pages.Count; i++) { DocumentPage page = dp.Pages[i]; Directory.CreateDirectory(folderPath); // Save the each page as Bitmap. Bitmap bmp = page.Rasterize(300, SautinSoft.Document.Color.White); // Save the bitmap to PNG and JPEG. bmp.Save(folderPath + @"\Page (PNG) - " + (i + 1).ToString() + ".png"); bmp.Save(folderPath + @"\Page (Jpeg) - " + (i + 1).ToString() + ".jpg"); } System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(folderPath) { UseShellExecute = true }); }
public MainUpdateParameters(int textStorePosition, int lineNo, Point linePosition, TextFormatter textFormatter, double paragraphWidth, double pixelsPerDip, double emSize0, string faceName, ChannelWriter <UpdateInfo> channelWriter, FontWeight fontWeight, DocumentPaginator paginator, TextSourceInitializationParameters textSourceInitializationParameters, RoslynCodeBase.DebugDelegate debugFn = null, Size?pageSize = null, bool paginate = false) { TextStorePosition = textStorePosition; LineNo = lineNo; LinePosition = linePosition; TextFormatter = textFormatter; ParagraphWidth = paragraphWidth; PixelsPerDip = pixelsPerDip; FontSize = emSize0; FaceName = faceName; ChannelWriter = channelWriter; FontWeight = fontWeight; Paginator = paginator; TextSourceInitializationParameters = textSourceInitializationParameters; DebugFn = debugFn; PageSize = pageSize; Paginate = paginate; }
PersistObjectData( SerializableObjectContext serializableObjectContext ) { DocumentPaginator paginator = _syncSerializer.BeginPersistObjectData(serializableObjectContext); ReachSerializerContext context = new ReachSerializerContext(this, SerializerAction.endPersistObjectData); _xpsOMSerializationManagerAsync.OperationStack.Push(context); int index = 0; DocumentPaginatorSerializerContext collectionContext = new DocumentPaginatorSerializerContext(this, serializableObjectContext, paginator, index, SerializerAction.serializeNextDocumentPage); _xpsOMSerializationManagerAsync.OperationStack.Push(collectionContext); }
public override void WriteAsync(DocumentPaginator documentPaginator, PrintTicket printTicket, object userSuppliedState);
public override void WriteAsync(DocumentPaginator documentPaginator);
public override void WriteAsync(DocumentPaginator documentPaginator, PrintTicket printTicket);