/// <summary> /// Prints the document. /// </summary> public void Print() { PrintDocumentImageableArea area = null; XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(ref area); if (xpsdw != null) { xpsdw.Write(this.CreateFixedDocument(new Size(area.ExtentWidth, area.ExtentHeight))); } }
private void DoThePrint(System.Windows.Documents.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 copy = new FlowDocument(); TextRange dest = new TextRange(copy.ContentStart, copy.ContentEnd); dest.Load(s, DataFormats.Xaml); string[] address = Address.Split(','); Paragraph price = new Paragraph(new Run("Total Price: " + m_Order.TotalPrice + "€")); price.TextAlignment = TextAlignment.Right; price.Margin = new Thickness(0, 30, 0, 0); Paragraph customerInfo = new Paragraph(new Run(String.Format("{0} {1}\n{2}\n{3}", FirstName, LastName, address[0].Trim(), address[1].Trim()))); customerInfo.Margin = new Thickness(0, 0, 0, 50); copy.Blocks.Add(price); copy.Blocks.InsertBefore(copy.Blocks.FirstBlock, customerInfo); // Create a XpsDocumentWriter object, implicitly opening a Windows common print dialog, // and allowing the user to select a printer. // get information about the dimensions of the seleted printer+media. PrintDocumentImageableArea ia = null; XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(ref ia); if (docWriter != null && ia != null) { DocumentPaginator paginator = ((IDocumentPaginatorSource)copy).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; copy.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)); copy.ColumnWidth = double.PositiveInfinity; // Send content to the printer. docWriter.Write(paginator); } }
/// <summary> /// Saves the document. /// </summary> /// <param name="filename">The filename.</param> /// <param name="width">The width.</param> /// <param name="height">The height.</param> public virtual void Save(string filename, double width = 816, double height = 1056) { using (var package = Package.Open(filename, FileMode.Create, FileAccess.ReadWrite)) { using (var xpsdoc = new XpsDocument(package)) { XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsdoc); writer.Write(this.CreateFixedDocument(new Size(width, height))); } } }
//Prints a FlowDocument public void PrintFlowDocument(PrintQueue printQueue) { FlowDocument flowDocument = GetFlowDocument(); DocumentPaginator documentPaginator = ((IDocumentPaginatorSource)flowDocument).DocumentPaginator; XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(printQueue); writer.Write(documentPaginator); }
public static void PrintFlowDoc(FlowDocument doc, string fileName) { DocumentPaginator paginator = (doc as IDocumentPaginatorSource).DocumentPaginator; //paginator.PageSize = new Size(96 * 8.27, 96 * 11.7); // A4 paginator.PageSize = new Size(96 * 11.7, 96 * 16.5); // A3 using (XpsDocument xps = new XpsDocument(fileName, System.IO.FileAccess.Write)) { XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xps); writer.Write(paginator); } }
public void PrintPreview(IDocument document) { DocumentPaginator documentPaginator = new XpsPrintingDocumentPaginator(document); using (var xpsWrapper = new InProcXpsDocumentWrapper()) { XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsWrapper.Document); xpsWriter.Write(documentPaginator); ShowXpsPreview(xpsWrapper.Document); } }
/// <summary> /// Used the XpsDocumentWriter to write a FixedDocumentSequence which contains the UIElements as single pages /// </summary> /// <param name="xpsWriter"></param> /// <param name="uiElements"></param> private void PrintUIElements(XpsDocumentWriter xpsWriter, List <UIElement> uiElements) { FixedDocumentSequence fixedDocSeq = new FixedDocumentSequence(); foreach (UIElement element in uiElements) { (fixedDocSeq as IAddChild).AddChild(toDocumentReference(element)); } // write the FixedDocumentSequence as an XPS Document xpsWriter.Write(fixedDocSeq); }
private void PrintStart(object sender, RoutedEventArgs e) { PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { PrintQueue printQueue = printDialog.PrintQueue; XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue); IDocumentPaginatorSource document = new StartPrintFlowDocument(viewModel.ExpiringProducts, viewModel.ProductsShortInStock); xpsDocumentWriter.Write(document.DocumentPaginator); } }
void OnClick_Print(object sender, RoutedEventArgs args) { PrintDialog dlg = new PrintDialog(); if ((bool)dlg.ShowDialog().GetValueOrDefault()) { FixedDocument doc = OutputXPS.CreateFixedDocument(GetCurrentStep()); XpsDocumentWriter writer = PrintQueue.CreateXpsDocumentWriter(dlg.PrintQueue); writer.Write(doc); } }
/// <summary> /// Creates a PDF file from the XPS Document by printing it to the PdfCreator printer and saving it with the specified name /// </summary> /// <param name="xpsDocument">Xps Document</param> /// <param name="destPdfFilePath">The destination path and filename of the generated PDF file.</param> /// <param name="blocking">When true, will wait until the file is fully processed and written, when false will return as soon as the conversion job is running.</param> /// <returns>True if the job is finished and successfull. (When not blocking true if the job started)</returns> public bool CreatePdf(XpsDocument xpsDocument, string destPdfFilePath, bool blocking = true) { return(CreatePdf(destPdfFilePath, blocking, new Action <PrintQueue>(pq => { XpsDocumentWriter printWriter = PrintQueue.CreateXpsDocumentWriter(pq); PrintTicket pt = new PrintTicket(); AppyPrintTicketSettings(pt); FixedDocumentSequence fds = xpsDocument.GetFixedDocumentSequence(); printWriter.Write(fds, pt); // Do the actual printing pq.Commit(); }))); }
private void CreateDocument(CustomDataGridDocumentPaginator paginator) { string tempFileName = Path.GetTempFileName(); File.Delete(tempFileName); using (XpsDocument xpsDocument = new XpsDocument(tempFileName, FileAccess.ReadWrite)) { XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument); writer.Write(paginator); PrintDocument = xpsDocument.GetFixedDocumentSequence(); } }
}// end:OnClose() // -------------------------- PrintDocument --------------------------- /// <summary> /// Prints the DocumentViewer's content and annotations.</summary> public void PrintDocument() { if (docViewer == null) { return; // DocumentViewer has not been initialized yet. } // If Annotations are disabled, use normal DocuementViewer.Print() if ((menuViewAnnotations.IsChecked == false) || (_annotHelper == null)) { docViewer.Print(); } // If Annotations are enabled, print showing the annotations. else // if (menuViewAnnotations.IsChecked && (_annotHelper != null)) { //<SnippetDocViewAnnXpsPrint> PrintDialog prntDialog = new PrintDialog(); if ((bool)prntDialog.ShowDialog()) { // XpsDocumentWriter.Write() may change the current // directory to "My Documents" or another user selected // directory for storing the print document. Save the // current directory and restore it after calling Write(). string docDir = Directory.GetCurrentDirectory(); // Create and XpsDocumentWriter for the selected printer. XpsDocumentWriter xdw = PrintQueue.CreateXpsDocumentWriter( prntDialog.PrintQueue); // Print the document with annotations. try { xdw.Write(_annotHelper.GetAnnotationDocumentPaginator( _xpsDocument.GetFixedDocumentSequence())); } catch (PrintingCanceledException) { // If in the PrintDialog the user chooses a file-based // output, such as the "MS Office Document Image Writer", // the user confirms or specifies the actual output // filename when the xdw.write operation executes. // If the user clicks "Cancel" in the filename // dialog a PrintingCanceledException is thrown // which we catch here and ignore. // MessageBox.Show("Print output cancelled"); } // Restore the original document directory to "current". Directory.SetCurrentDirectory(docDir); } //</SnippetDocViewAnnXpsPrint> } }// end:PrintDocument()
public void Write(FixedDocumentSequence document) { // create a XpsDocument object XpsDocument xpsDoc = new XpsDocument(_path, FileAccess.Write); // get the XpsDocumentWriter for the XpsDocument object XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDoc); // write the FixedDocumentSequence object writer.Write(document); // close the XpsDocument xpsDoc.Close(); }
/// <summary> /// Actually print an Xps Document with previously setup params /// </summary> /// <param name="paginator">Document to print</param> /// <param name="description">Description</param> public void PrintDocument(DocumentPaginator paginator, string description) { if (paginator == null) { throw new ArgumentNullException("paginator", "No DocumentPaginator to print"); } VerifyPrintSettings(); //Handle XPS ourself, as their document writer hates our thread if (mPrintQueue.FullName.Contains("XPS")) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Xps Document (*.xps) | *.xps"; if (sfd.ShowDialog() == true) { XpsDocument document = new XpsDocument(sfd.FileName, System.IO.FileAccess.Write); XpsPackagingPolicy packagePolicy = new XpsPackagingPolicy(document); XpsSerializationManager serializationMgr = new XpsSerializationManager(packagePolicy, false); serializationMgr.SaveAsXaml(paginator); document.Close(); } return; } XpsDocumentWriter writer = null; new PrintingPermission(PrintingPermissionLevel.DefaultPrinting).Assert(); try { mPrintQueue.CurrentJobSettings.Description = description; writer = PrintQueue.CreateXpsDocumentWriter(mPrintQueue); TicketEventHandler handler = new TicketEventHandler(mPrintTicket); writer.WritingPrintTicketRequired += new WritingPrintTicketRequiredEventHandler(handler.SetPrintTicket); } finally { CodeAccessPermission.RevertAssert(); } writer.Write(paginator); //Reset mPrintableWidth = 0.0; mPrintableHeight = 0.0; mWidthUpdated = false; mHeightUpdated = false; }
public void Save() { if (Uri == null) { throw new ArgumentException("Uri has not been specified"); } XpsDocument xpsDocument = new XpsDocument(Uri.OriginalString, System.IO.FileAccess.ReadWrite); XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument); xpsDocumentWriter.Write(FixedDocumentSequence); xpsDocument.Close(); }
public static void SaveFixedDocument(FixedDocument fixedDoc) { string xpsPath = "C://Program Files (x86)//이주데이타//가로주택정비//" + "testFile.xps"; using (XpsDocument currentXpsDoc = new XpsDocument(xpsPath, FileAccess.ReadWrite)) { XpsDocumentWriter xw = XpsDocument.CreateXpsDocumentWriter(currentXpsDoc); xw.Write(fixedDoc); } return; }
/* 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; } }
private void Button_saveClick(object sender, RoutedEventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "XPS Files (*.xps)|*.xps"; if (sfd.ShowDialog() == true) { XpsDocument doc = new XpsDocument(sfd.FileName, FileAccess.Write); XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); writer.Write(documentViewer.Document as FixedDocument); doc.Close(); } }
/// <summary> /// Renders the current visual as a FixedPage and save it as XPS file. /// </summary> public void SaveXps() { var zipFile = Package.Open(Path.Combine(OutputDirectory, Name + ".xps"), FileMode.Create); XpsDocument xpsDocument = new XpsDocument(zipFile); PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); fixedPage.Width = WidthInPU; fixedPage.Height = HeightInPU; fixedPage.Background = Brushes.Transparent; // Visuals needs a UIElement as drawing container VisualPresenter presenter = new VisualPresenter(); presenter.AddVisual(this.visual); FixedPage.SetLeft(presenter, 0); FixedPage.SetTop(presenter, 0); fixedPage.Children.Add(presenter); // Perform layout Size size = new Size(WidthInPU, HeightInPU); fixedPage.Measure(size); fixedPage.Arrange(new Rect(new Point(), size)); fixedPage.UpdateLayout(); ((IAddChild)pageContent).AddChild(fixedPage); FixedDocument fixedDocument = new FixedDocument(); fixedDocument.DocumentPaginator.PageSize = size; fixedDocument.Pages.Add(pageContent); // Save as XPS file XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument); xpsWriter.Write(fixedDocument); xpsDocument.Close(); zipFile.Close(); // Must call at least two times GC.Collect this to get access to the xps file even I write synchronously. This is a bug in WPF. // Vista 64 .NET 3.5 SP1 installed xpsDocument = null; xpsWriter = null; GC.Collect(10, GCCollectionMode.Forced); GC.Collect(10, GCCollectionMode.Forced); //GC.Collect(10, GCCollectionMode.Forced); //GC.Collect(10, GCCollectionMode.Forced); }
private void CreateASimpleDocument() { var fSeq = new FixedDocumentSequence(); var fDoc = new FixedDocument(); // Add DocumentReference with FixedDoc to FixedDocSeq var docRef = new DocumentReference(); docRef.SetDocument(fDoc); fSeq.References.Add(docRef); // Create Fixed Page var fPage = new FixedPage { Width = 816, Height = 1056 }; var txt = new TextBlock { Text = "Hello XPS" }; fPage.Children.Add(txt); // Add FixedPage to PageContent var pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(fPage); // Add PageContent to FixedDoc fDoc.Pages.Add(pageContent); // Save as XPS if (File.Exists(_fileName)) { File.Delete(_fileName); } XpsDocument doc = new XpsDocument(_fileName, FileAccess.Write); try { XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); writer.Write(fSeq); } finally { doc.Close(); } }
private Nullable <bool> ShowPrintPreview(XpsDocument xps, DocumentPaginator paginator) { XpsDocumentWriter xpw = XpsDocument.CreateXpsDocumentWriter(xps); xpw.Write(paginator); PrintPreview previewWindow = new PrintPreview(xps); Nullable <bool> PreviewDialogState = previewWindow.ShowDialog(); xps.Close(); return(PreviewDialogState); }
public static void ExportVisualAsPdf(MainWindowViewModel usefulDataVM) { //Set up the WPF Control to be printed UserControl1 controlToPrint; controlToPrint = new UserControl1(); controlToPrint.DataContext = usefulDataVM; PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); fixedPage.Children.Add(controlToPrint); ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); SaveFileDialog sfd = new SaveFileDialog { DefaultExt = ".pdf", Filter = "PDF Documents (.pdf)|*.pdf" }; bool?result = sfd.ShowDialog(); if (result != true) { return; } MemoryStream memoryStream = new MemoryStream(); System.IO.Packaging.Package package = System.IO.Packaging.Package.Open(memoryStream, FileMode.Create); XpsDocument xpsDocument = new XpsDocument(package); XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument); xpsDocumentWriter.Write(fixedPage); xpsDocument.Close(); package.Close(); var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(memoryStream); //public static void Convert(Stream xpsInStream, Stream pdfOutStream, bool closePdfStream); XpsConverter.Convert(pdfXpsDoc, sfd.FileName, 0); Process.Start(sfd.FileName); }
/// <summary> /// Print the document. /// </summary> private void PrintDoc() { PrintTicket printTicket = _printDlg.PrintTicket; FlowDocument flowDocForPrinting = GetFlowDocumentForPrinting(printTicket); // In case the user has changed some settings (e.g., orientation or page size) // by going to the printer preferences dialog from the print dialog itself, // set the printer queue's User ticket to the one attached to the print dialog. _printDlg.PrintQueue.UserPrintTicket = printTicket; // Print the FlowDocument _printDlg.PrintQueue.CurrentJobSettings.Description = (String.IsNullOrEmpty(_documentName) ? Guid.NewGuid().ToString() : _documentName); XpsDocumentWriter docWriter = PrintQueue.CreateXpsDocumentWriter(_printDlg.PrintQueue); // Use our IDocumentPaginator implementation so we can insert headers and footers, // if present. // PrintableAreaHeight and Width are passed to the paginator to establish the // true printable area for the document. HeaderFooterDocumentPaginator paginator = new HeaderFooterDocumentPaginator( ((IDocumentPaginatorSource)flowDocForPrinting).DocumentPaginator, null, null, _printDlg.PrintableAreaHeight, _printDlg.PrintableAreaWidth); if (_asyncPrintFlag == false) { try { docWriter.Write(paginator, printTicket); } catch (PrintingCanceledException) { } } else { // Changes for Async printing start here: Application.Current.MainWindow.Opacity = 0.7; PrintProgressWindow dlg = new PrintProgressWindow(docWriter); dlg.PageNumber = 0; docWriter.WritingProgressChanged += new WritingProgressChangedEventHandler(dlg.OnWritingProgressChanged); docWriter.WritingCompleted += new WritingCompletedEventHandler(dlg.OnWritingCompleted); docWriter.WriteAsync(paginator, printTicket); dlg.ShowDialog(); // Reset the flag here for next printing invocation. _asyncPrintFlag = false; } }
static void Main(string[] args) { try { // create XPS file based on a WPF Visual, and store it in a memorystream MemoryStream lMemoryStream = new MemoryStream(); Package package = Package.Open(lMemoryStream, FileMode.Create); XpsDocument doc = new XpsDocument(package); XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc); writer.Write(WPF2PDF.CreateVisual()); // now open this XPS stream in the NiXPS SDK, and export it as pdf //NOPackage lPackage = NOPackage.readPackageFromBuffer("file.xps", lMemoryStream.GetBuffer(), (uint)lMemoryStream.Length); //NOProgressReporter lReporter = new NOProgressReporter(); //lPackage.getDocument(0).exportToPDF("file.pdf", lReporter); //NOPackage.destroyPackage(ref lPackage); //Create URI for Xps Package //Any Uri will actually be fine here. It acts as a place holder for the //Uri of the package inside of the PackageStore string inMemoryPackageName = string.Format("memorystream://{0}.xps", Guid.NewGuid()); Uri packageUri = new Uri(inMemoryPackageName); //Add package to PackageStore PackageStore.AddPackage(packageUri, package); XpsDocument xpsDoc = new XpsDocument(package, CompressionOption.Maximum, inMemoryPackageName); FixedDocumentSequence fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence(); PrintDialog dlg = new PrintDialog(); dlg.PrintDocument(fixedDocumentSequence.DocumentPaginator, "Document title"); PackageStore.RemovePackage(packageUri); xpsDoc.Close(); doc.Close(); package.Close(); } catch (Exception e) { System.Console.Out.WriteLine("EXCEPTION: 0x" + string.Format("{0:X}", e.Message)); } Console.WriteLine("Conversion to WPF done!"); Console.ReadKey(); }
private void btnPrint_Click(object sender, RoutedEventArgs e) { SetPrintTicket(printTicket); XpsDocumentWriter documentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue); documentWriter.Write(CreateMultiPageFixedDocument(), printTicket); MessageBox.Show("Document printed.", "Recipe 07 05", MessageBoxButton.OK, MessageBoxImage.Information); }
/// <summary> /// Synchronously, add the XPS document together with a print ticket to the print queue. /// </summary> /// <param name="xpsFilePath">Path to source XPS file.</param> /// <param name="printQueue">The print queue to print to.</param> /// <param name="printTicket">The print ticket for the selected print queue.</param> public static void PrintXpsDocument(string xpsFilePath, PrintQueue printQueue, PrintTicket printTicket) { // Create an XpsDocumentWriter object for the print queue. XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue); // Open the selected document. XpsDocument xpsDocument = new(xpsFilePath, FileAccess.Read); // Get a fixed document sequence for the selected document. FixedDocumentSequence fixedDocSeq = xpsDocument.GetFixedDocumentSequence(); // Synchronously, add the XPS document together with a print ticket to the print queue. xpsDocumentWriter.Write(fixedDocSeq, printTicket); }
private void PrintDailyAccounting(object sender, RoutedEventArgs e) { PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) { PrintQueue printQueue = printDialog.PrintQueue; XpsDocumentWriter xpsDocumentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue); IDocumentPaginatorSource document = new SalePrintFlowDocument(viewModel.SaleToday.SaleProducts); xpsDocumentWriter.Write(document.DocumentPaginator); } InvokersListBox.Focus(); }
internal XpsDocument WriteXps(FixedDocument doc) { string tempPath = Path.GetTempPath() + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xps"; XpsDocument output = new XpsDocument(tempPath, FileAccess.ReadWrite); XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(output); writer.Write(doc); output.Close(); return(output); }
public void PrintUsingXps(bool showProgressDialog) { if (showProgressDialog) { controller.ShowProgressDialog(true); } try { // Set up and position everything. SetupPrinting(); PrintQueue printQueue = GetPrintQueue(pageSettings.PrinterSettings.PrinterName); do { PrintTicket printTicket = GetPrintTicket(printQueue, pageSettings); Margins margins = pageSettings.Margins; BeginPrint(this, new PrintEventArgs()); printQueue.CurrentJobSettings.Description = documentTitle; XpsDocumentWriter documentWriter = PrintQueue.CreateXpsDocumentWriter(printQueue); Paginator paginator = new Paginator(this, currentPage, new SizeF(pageSettings.PaperSize.Width, pageSettings.PaperSize.Height), margins, GetDPI(printTicket), showProgressDialog); documentWriter.Write(paginator, printTicket); currentPage += paginator.PageCount; EndPrint(this, new PrintEventArgs()); // If we didn't print all the pages, then we must have been doing a pause // between pages. if (currentPage < totalPages) { string pauseMessage; bool pause = PausePrintingAfterPage(currentPage - 1, out pauseMessage); Debug.Assert(pause); if (!controller.OkCancelMessage(pauseMessage, true)) { break; } } } while (currentPage < totalPages); } finally { if (showProgressDialog) { controller.EndProgressDialog(); } } }
private void Button_Click(object sender, RoutedEventArgs e) { LocalPrintServer ps = new LocalPrintServer(); PrintQueue pq = ps.DefaultPrintQueue; XpsDocumentWriter xpsdw = PrintQueue.CreateXpsDocumentWriter(pq); PrintTicket pt = pq.UserPrintTicket; if (xpsdw != null) { pt.PageOrientation = PageOrientation.Portrait; PageMediaSize pageMediaSize = new PageMediaSize(this.ActualWidth, this.ActualHeight); pt.PageMediaSize = pageMediaSize; xpsdw.Write(MyContent); } }