public static FixedDocument CreateFixedDocument(double pageWidth, double pageHeight, UIElement content) { if (content == null) { throw new ArgumentNullException("content"); } if (pageWidth <= 0 || pageHeight <= 0) { throw new ArgumentOutOfRangeException(); } RenderTargetBitmap renderTarget = new RenderTargetBitmap(Convert.ToInt32(content.RenderSize.Width), Convert.ToInt32(content.RenderSize.Height), Constants.ScreenDPI, Constants.ScreenDPI, PixelFormats.Pbgra32); renderTarget.Render(content); FixedDocument doc = new FixedDocument(); Size pageSize = new Size(pageWidth, pageHeight); doc.DocumentPaginator.PageSize = pageSize; FixedPage fixedPage = new FixedPage(); fixedPage.Width = pageWidth; fixedPage.Height = pageHeight; Image image = new Image(); image.Height = pageHeight; image.Width = pageWidth; image.Stretch = Stretch.Uniform; image.StretchDirection = StretchDirection.Both; image.Source = renderTarget; fixedPage.Children.Add(image); PageContent pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(fixedPage); doc.Pages.Add(pageContent); return doc; }
/// <summary> /// Clones a PageContent based on its original /// </summary> /// <param name="OriginalPage">Original PageContent</param> /// <returns>Cloned PageContent</returns> public static PageContent ClonePage(PageContent OriginalPage) { PageContent pcReturn = new PageContent(); if (object.ReferenceEquals(OriginalPage, null) == false) { FixedPage fpTemplate = OriginalPage.GetPageRoot(true); pcReturn.Child = new FixedPage(); pcReturn.Child.Width = fpTemplate.Width; pcReturn.Child.Height = fpTemplate.Height; pcReturn.Child.MinHeight = fpTemplate.MinHeight; pcReturn.Child.MinWidth = fpTemplate.MinWidth; pcReturn.Child.MaxHeight = fpTemplate.MaxHeight; pcReturn.Child.MaxWidth = fpTemplate.MaxWidth; foreach (System.Windows.UIElement obj in fpTemplate.Children) { string s = System.Windows.Markup.XamlWriter.Save(obj); System.IO.StringReader stringReader = new System.IO.StringReader(s); System.Xml.XmlReader xmlReader = System.Xml.XmlTextReader.Create(stringReader, new System.Xml.XmlReaderSettings()); pcReturn.Child.Children.Add((System.Windows.UIElement)System.Windows.Markup.XamlReader.Load(xmlReader)); } } return pcReturn; }
static void AddPageToDocument(FixedDocument fixedDocument,FixedPage page) { PageContent pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(page); fixedDocument.Pages.Add(pageContent); }
public static bool SaveXPS(FixedPage page, bool isSaved) { FixedDocument fixedDoc = new FixedDocument();//创建一个文档 fixedDoc.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11); PageContent pageContent = new PageContent(); ((IAddChild)pageContent).AddChild(page); fixedDoc.Pages.Add(pageContent);//将对象加入到当前文档中 string containerName = GetXPSFromDialog(isSaved); if (containerName != null) { try { File.Delete(containerName); } catch (Exception e) { MessageBox.Show(e.Message); } XpsDocument _xpsDocument = new XpsDocument(containerName, FileAccess.Write); XpsDocumentWriter xpsdw = XpsDocument.CreateXpsDocumentWriter(_xpsDocument); xpsdw.Write(fixedDoc);//写入XPS文件 _xpsDocument.Close(); return true; } else return false; }
private static IDocumentPaginatorSource CreateDesignTimeDocument(Size pageSize) { var document = new FixedDocument(); document.DocumentPaginator.PageSize = pageSize; // ---- Page 1 var page1 = new FixedPage { Width = pageSize.Width, Height = pageSize.Height }; var page1Text = new TextBlock { FontSize = 16, Margin = new Thickness(96), Text = "Lorem ipsum dolor sit amet." }; page1.Children.Add(page1Text); var page1Content = new PageContent(); ((IAddChild)page1Content).AddChild(page1); document.Pages.Add(page1Content); // ---- Page 2 // ... return document; }
public PageBuilder(double width, double height, int marginsLeft, int marginsTop, int marginsRight, int marginsBottom, ContentControl frame) { _page = new PageContent(); _fixedPage = new FixedPage {Background = Brushes.White, Width = width, Height = height}; _repeater = new Repeater(); var repeatContainer = new Grid {Margin = new Thickness(marginsLeft, marginsTop, marginsRight, marginsBottom)}; repeatContainer.Children.Add(_repeater); frame.SetValue(FixedPage.LeftProperty, 0.00); frame.SetValue(FixedPage.TopProperty, 0.00); frame.SetValue(FrameworkElement.WidthProperty, _fixedPage.Width); frame.SetValue(FrameworkElement.HeightProperty, _fixedPage.Height); _fixedPage.Children.Add(frame); ((IAddChild)_page).AddChild(_fixedPage); frame.Content = repeatContainer; frame.Measure(new Size(width, height)); frame.Arrange(new Rect(0, 0, width, height)); _repeater.Width = repeatContainer.ActualWidth; _repeater.Height = repeatContainer.ActualHeight; }
private void print_btn_Click(object sender, RoutedEventArgs e) { try { report.report_cr_dr p = new BMS.report.report_cr_dr(); p.lst_balance.ItemsSource = dr; p.r_date.Content = DateTime.Now.Date.ToShortDateString(); p.r_name.Content = "Top Debitors"; PrintDialog pd = new PrintDialog(); FixedDocument document = new FixedDocument(); document.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11); FixedPage page1 = new FixedPage(); page1.Width = document.DocumentPaginator.PageSize.Width; page1.Height = document.DocumentPaginator.PageSize.Height; Canvas can = p.layout; page1.Children.Add(can); PageContent page1Content = new PageContent(); ((IAddChild)page1Content).AddChild(page1); document.Pages.Add(page1Content); pd.PrintDocument(document.DocumentPaginator, "My first document"); } catch (Exception ex) { MessageBox.Show("Sorry some system error has occour please try again"); } }
private PageContent CreatePawnTicketContent() { PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); UIElement visual = PawnTicketUIElement(); FixedPage.SetLeft(visual, 0); FixedPage.SetTop(visual, 0); double pageWidth = 96 * 8.5; double pageHeight = 96 * 11; fixedPage.Width = pageWidth; fixedPage.Height = pageHeight; fixedPage.Children.Add((UIElement)visual); Size sz = new Size(8.5 * 96, 11 * 96); fixedPage.Measure(sz); fixedPage.Arrange(new Rect(new Point(), sz)); fixedPage.UpdateLayout(); ((IAddChild)pageContent).AddChild(fixedPage); return pageContent; }
private void btnPrint_Click_1(object sender, RoutedEventArgs e) { var printControl = new SummaryControl(); printControl.DataContext = _reservation; printControl.Width = 8.27 * 96; printControl.Height = 11.69 * 96; //Create a fixed Document and Print the document FixedDocument fixedDoc = new FixedDocument(); PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); fixedPage.Height = 11.69 * 96; fixedPage.Width = 8.27 * 96; fixedPage.Children.Add(printControl); ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); fixedDoc.Pages.Add(pageContent); PrintDialog dialog = new PrintDialog(); if (dialog.ShowDialog() == true) { //dialog.PrintVisual(_PrintCanvas, "My Canvas"); dialog.PrintDocument(fixedDoc.DocumentPaginator, "Print label"); } }
public void printing_2(Grid grid_table_print) { DocumentViewer documentViewer1 = new DocumentViewer(); FixedDocument fixedDoc = new FixedDocument(); PageContent pgc = new PageContent(); FixedPage fxp = new FixedPage(); //A4 fxp.Width = 11.69 * 96; fxp.Height = 8.27 * 96; StackPanel panel = new StackPanel(); panel.Orientation = Orientation.Vertical; panel.HorizontalAlignment = System.Windows.HorizontalAlignment.Center; panel.Width = (11.69 * 96) * 0.9; panel.Orientation = Orientation.Vertical; Thickness margin = panel.Margin; margin.Bottom = 0; margin.Left = 50; margin.Top = 50; margin.Right = 25; panel.Margin = margin; BitmapImage bmp_ = new BitmapImage(); Label test_lb = new Label(); test_lb.Content = "\n\n\t\t\tРежим расчетов \n \tОцифровка в автоматическом режиме"; margin = test_lb.Margin; margin.Bottom = 50; margin.Left = 50; margin.Top = 50; margin.Right = 0; test_lb.BorderThickness = margin; panel.Children.Add(test_lb); ImageSource imageSource = new BitmapImage(new Uri(Directory.GetCurrentDirectory() + "\\file.jpg")); Image img = new Image(); img.Source = imageSource; panel.Children.Add(img); Grid grid_table_print_copy = new Grid();// { DataContext = grid_table_print.DataContext }; string gridXaml = XamlWriter.Save(grid_table_print); StringReader stringReader = new StringReader(gridXaml); XmlReader xmlReader = XmlReader.Create(stringReader); grid_table_print_copy = (Grid)XamlReader.Load(xmlReader); panel.Children.Add(grid_table_print_copy); fxp.Children.Add(panel); ((System.Windows.Markup.IAddChild)pgc).AddChild(fxp); fixedDoc.Pages.Add(pgc); documentViewer1.Document = fixedDoc; Window ShowWindow = new Window(); ShowWindow.Width = 850; ShowWindow.Height = 850; ShowWindow.Content = documentViewer1; ShowWindow.Show(); }
private void PrintSimpleTextButton_Click(object sender, RoutedEventArgs e) { // PrintDialog printDlg = new PrintDialog(); // // Create a FlowDocument dynamically. // FlowDocument doc = CreateFlowDocument(); // doc.Name = "FlowDoc"; // // Create IDocumentPaginatorSource from FlowDocument // IDocumentPaginatorSource idpSource = doc; // // Call PrintDocument method to send document to printer // printDlg.PrintDocument(idpSource.DocumentPaginator, "Hello WPF Printing."); PrintDialog pd = new PrintDialog(); if (pd.ShowDialog() != true) return; FixedDocument document = new FixedDocument(); document.DocumentPaginator.PageSize = new Size(8.5,11); FixedPage page1 = new FixedPage(); page1.Width = document.DocumentPaginator.PageSize.Width; page1.Height = document.DocumentPaginator.PageSize.Height; Canvas can = new Canvas(); TextBlock page1Text = new TextBlock(); page1Text.Text = "This is the first page"; page1Text.FontSize = 10; // 30pt text page1Text.Margin = new Thickness(5, 20, 30, 10); can.Children.Add(page1Text); // 1 inch margin //page1.Children.Add(page1Text); page1.Width = document.DocumentPaginator.PageSize.Width; page1.Height = document.DocumentPaginator.PageSize.Height; TextBlock page2Text = new TextBlock(); page2Text.Text = "This is the first page"; page2Text.FontSize = 40; // 30pt text page2Text.Margin = new Thickness(5, 20, 30, 10); // 1 inch margin can.Children.Add(page2Text); page1.Children.Add(can); PageContent page1Content = new PageContent(); ((IAddChild)page1Content).AddChild(page1); document.Pages.Add(page1Content); //FixedPage page2 = new FixedPage(); //page2.Width = document.DocumentPaginator.PageSize.Width; //page2.Height = document.DocumentPaginator.PageSize.Height; //TextBlock page2Text = new TextBlock(); //page2Text.Text = "This is NOT the first page"; //page2Text.FontSize = 40; //page2Text.Margin = new Thickness(96); //page2.Children.Add(page2Text); //PageContent page2Content = new PageContent(); //((IAddChild)page2Content).AddChild(page2); //document.Pages.Add(page2Content); pd.PrintDocument(document.DocumentPaginator, "My first document"); }
public static IDocumentPaginatorSource CreateXpsDocument(string ss, string ssname) { FixedPage fp = new FixedPage(); TextBox ll = new TextBox(); ll.Margin = new Thickness(20, 40, 20, 40); fp.Children.Add(ll); fp.UpdateLayout(); ll.TextWrapping = TextWrapping.WrapWithOverflow; ll.Text = ssname + Environment.NewLine + Environment.NewLine + ss; PageContent pc = new PageContent(); ((System.Windows.Markup.IAddChild)pc).AddChild(fp); FixedDocument fd = new FixedDocument(); fd.Pages.Add(pc); return fd; }
/// <summary> /// Render a UIElement such that the visual tree is generated, /// without actually displaying the UIElement /// anywhere /// </summary> public static void CreateVisualTree(this UIElement element) { var fixedDoc = new FixedDocument(); var pageContent = new PageContent(); var fixedPage = new FixedPage(); fixedPage.Children.Add(element); ((IAddChild)pageContent).AddChild(fixedPage); fixedDoc.Pages.Add(pageContent); var f = new XpsSerializerFactory(); using(var s = new MemoryStream()) { var w = f.CreateSerializerWriter(s); w.Write(fixedDoc); } }
public List<PageContent> PrintPage() { List<PageContent> Pages = new List<PageContent>(); PrintDialog printDialog = new PrintDialog(); foreach (ImageInfo imageInfo in OCRImages_ListBox.SelectedItems) { PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); bool rotate = false; double width = printDialog.PrintableAreaWidth; double height = printDialog.PrintableAreaHeight; if (imageInfo.imageSource.Width > imageInfo.imageSource.Height) { width = printDialog.PrintableAreaHeight; height = printDialog.PrintableAreaWidth; rotate = true; } PrintPreview printPreview = new PrintPreview(m_CaseObject, width, height); printPreview.SetImage(imageInfo.imageSource); fixedPage.Children.Add((UIElement)printPreview); if (rotate) { double pageWidth = printDialog.PrintableAreaWidth; double pageHeight = printDialog.PrintableAreaHeight; TranslateTransform tt = new TranslateTransform((pageWidth - pageHeight) / 2, (pageHeight - pageWidth) / 2); printPreview.RenderTransform = tt; RotateTransform rotateTransform = new RotateTransform(-90D, pageWidth / 2D, pageHeight / 2D); fixedPage.RenderTransform = rotateTransform; } ((IAddChild)pageContent).AddChild(fixedPage); Pages.Add(pageContent); } return Pages; }
public List<PageContent> PrintPage() { List<PageContent> Pages = new List<PageContent>(); PrintDialog printDialog = new PrintDialog(); PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); BitmapSource displayAreaSource = RenderVisaulToBitmap(m_FormHost, (int)m_FormHost.ActualWidth, (int)m_FormHost.ActualHeight); bool rotate = false; double width = printDialog.PrintableAreaWidth; double height = printDialog.PrintableAreaHeight; if (displayAreaSource.Width > displayAreaSource.Height) { width = printDialog.PrintableAreaHeight; height = printDialog.PrintableAreaWidth; rotate = true; } PrintPreview printPreview = new PrintPreview(m_CaseObject, width, height); printPreview.SetImage(displayAreaSource); fixedPage.Children.Add((UIElement)printPreview); if (rotate) { double pageWidth = printDialog.PrintableAreaWidth; double pageHeight = printDialog.PrintableAreaHeight; TranslateTransform tt = new TranslateTransform((pageWidth - pageHeight) / 2, (pageHeight - pageWidth) / 2); printPreview.RenderTransform = tt; RotateTransform rotateTransform = new RotateTransform(-90D, pageWidth / 2D, pageHeight / 2D); fixedPage.RenderTransform = rotateTransform; } ((IAddChild)pageContent).AddChild(fixedPage); Pages.Add(pageContent); return Pages; }
/// <summary>default constructor /// </summary> /// <param name="header">page header object</param> /// <param name="footer">page footer object</param> public ReportPage(HeaderFooterBase header, HeaderFooterBase footer) { PageContent = new PageContent(); FixedPage = new FixedPage() { Background = Brushes.White, Width = m_DisplayResolution * m_PageWidth, Height = m_DisplayResolution * m_PageHeight }; ((IAddChild)PageContent).AddChild(FixedPage); m_HeaderGrid = new Grid(); m_FooterGrid = new Grid(); BodyGrid = XPSHelper.GetGrid(0, 1); header.Write(m_HeaderGrid); footer.Write(m_FooterGrid); WriteItemToPage(m_HeaderGrid, m_PageTopMargin, m_PageTopMargin); WriteItemToPage(BodyGrid, m_PageLeftMargin, m_HeaderGrid.ActualHeight / m_DisplayResolution + m_HeaderToBodyGap); WriteItemToPage(m_FooterGrid, m_PageLeftMargin, double.MinValue, double.MinValue, m_PageBottomMargin); }
/// <summary> /// PrintDialogを使用した印刷を行います。 /// </summary> private void PrintDocument() { var dlg = new PrintDialog(); if (dlg.ShowDialog() == true) { var page = new FixedPage(); page.Children.Add(new SampleReport()); var cont = new PageContent(); cont.Child = page; var doc = new FixedDocument(); doc.Pages.Add(cont); dlg.PrintDocument(doc.DocumentPaginator, "Print1"); } }
private void UserControl_Loaded(object sender, RoutedEventArgs e) { //CompanyDomain domain = new CompanyDomain(1, Common.Enums.LanguagesEnum.Arabic); //cmbo_Company.ItemsSource = domain.FindNotFull(); CompanyReportChart soldgersPrintData = new CompanyReportChart(); soldgersPrintData.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; soldgersPrintData.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; soldgersPrintData.Margin = new Thickness(0, 20, 0, 0); FixedDocument fixedDoc = new FixedDocument(); PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); fixedPage.Width = 850; fixedPage.Height = 1220; fixedPage.Children.Add(soldgersPrintData); ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); fixedDoc.Pages.Add(pageContent); dcViewer.Document = fixedDoc; }
internal void NavigationService_LoadCompleted(object sender, NavigationEventArgs e) { _menus = e.ExtraData as ObservableCollection<MenuEntry>; _fixedDocument = new FixedDocument(); var pageContent1 = new PageContent(); _fixedDocument.Pages.Add(pageContent1); var page1 = new FixedPage(); pageContent1.Child = page1; page1.Children.Add(GetHeaderContent()); page1.Children.Add(GetLogoContent()); page1.Children.Add(GetDateContent()); page1.Children.Add(GetMenuContent()); viewer.Document = _fixedDocument; NavigationService.LoadCompleted -= NavigationService_LoadCompleted; }
static public void Display() { FixedPage fpage = App.LoadComponent(new Uri("Views/LostFormsMemo.xaml", UriKind.Relative)) as FixedPage; PageContent pagewrapper = new PageContent(); (pagewrapper as IAddChild).AddChild(fpage); FixedDocument doc = new FixedDocument(); doc.Pages.Add(pagewrapper); DocumentViewer docviewer = new DocumentViewer(); docviewer.Document = doc; docviewer.Zoom = 75; Window win = new Window(); win.Content = docviewer; win.Owner = App.Current.MainWindow; win.Width = (fpage.ActualWidth + 50) * 0.75;// docviewer.ExtentWidth + 50; //win.Height = fpage.ActualHeight; win.Show(); }
public void Generar(Object data, List<UserControl> bodyPages) { foreach (UserControl Pagina in bodyPages) { FixedPage page = new FixedPage(); PageContent pageContent = new PageContent(); page.Children.Add(Pagina); ((IAddChild)pageContent).AddChild(page); document.Pages.Add(pageContent); } if (printDialog.ShowDialog() != true) return; printDialog.PrintDocument(document.DocumentPaginator, "DOCUMENT"); }
private void Xps_Click(object sender, RoutedEventArgs e) { FixedPage page = new FixedPage() { Background = Brushes.White, Width = Dpi * PaperWidth, Height = Dpi * PaperHeight }; TextBlock tbTitle = new TextBlock { Text = "My InkCanvas Sketch", FontSize = 24, FontFamily = new FontFamily("Arial") }; FixedPage.SetLeft(tbTitle, Dpi * 0.75); FixedPage.SetTop(tbTitle, Dpi * 0.75); page.Children.Add((UIElement)tbTitle); var toPrint = myInkCanvasBorder; myGrid.Children.Remove(myInkCanvasBorder); FixedPage.SetLeft(toPrint, Dpi * 2); FixedPage.SetTop(toPrint, Dpi * 2); page.Children.Add(toPrint); Size sz = new Size(Dpi * PaperWidth, Dpi * PaperHeight); page.Measure(sz); page.Arrange(new Rect(new Point(), sz)); page.UpdateLayout(); var filepath = System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "PrintingTest"); if (!File.Exists(filepath)) Directory.CreateDirectory(filepath); var filename = System.IO.Path.Combine(filepath, "myXpsFile.xps"); FixedDocument doc = new FixedDocument(); PageContent pageContent = new PageContent(); ((System.Windows.Markup.IAddChild)pageContent).AddChild(page); doc.Pages.Add(pageContent); XpsDocument xpsd = new XpsDocument(filename, FileAccess.Write); XpsDocument.CreateXpsDocumentWriter(xpsd).Write(doc); //requires System.Printing namespace xpsd.Close(); PrintDialog printDialog = new PrintDialog(); if (printDialog.ShowDialog() == true) printDialog.PrintQueue.AddJob("MyInkCanvas print job", filename, true); page.Children.Remove(toPrint); myGrid.Children.Add(toPrint); }
private void cmbo_Year_SelectionChanged(object sender, SelectionChangedEventArgs e) { //if (cmbo_Company.SelectedItem!=null) //{ //CompanyDetailReport soldgersPrintData = new CompanyDetailReport(((Company)(cmbo_Company.SelectedItem)).ID); CompanyReportChart soldgersPrintData = new CompanyReportChart(); soldgersPrintData.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Center; soldgersPrintData.VerticalContentAlignment = System.Windows.VerticalAlignment.Center; soldgersPrintData.Margin = new Thickness(0, 20, 0, 0); FixedDocument fixedDoc = new FixedDocument(); PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); fixedPage.Width = 850; fixedPage.Height = 1220; fixedPage.Children.Add(soldgersPrintData); ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); fixedDoc.Pages.Add(pageContent); dcViewer.Document = fixedDoc; //} }
///<summary>Adds a page to the document and returns a canvas to put all the page UIElements into. The returned canvas is the size and position of the bounds passed in. If no bounds are passed in, it gives a standard margin of 50. Includes automatically adding the required PageContent and FixedPage without the user having to be bothered with it. Also adds a master canvas onto which the child canvas is placed to handle margins.</summary> public static Canvas GetCanvas(FixedDocument document,Rect bounds){ FixedPage page=new FixedPage(); page.Width=document.DocumentPaginator.PageSize.Width; page.Height=document.DocumentPaginator.PageSize.Height; Canvas canvas=new Canvas(); canvas.Width=bounds.Width; canvas.Height=bounds.Height; Canvas canvasMain=new Canvas(); canvasMain.Width=page.Width; canvasMain.Height=page.Height; canvasMain.Children.Add(canvas); Canvas.SetLeft(canvas,bounds.Left); Canvas.SetTop(canvas,bounds.Top); page.Children.Add(canvasMain); PageContent pageContent = new PageContent(); pageContent.MaxWidth=1600; ((IAddChild)pageContent).AddChild(page); document.Pages.Add(pageContent); return canvas; }
public static void Print(MainWindowViewModel viewModel) { //Set up the WPF Control to be printed var fixedDoc = new FixedDocument(); var objReportToPrint = new ReportSample(); var ReportToPrint = objReportToPrint as UserControl; ReportToPrint.DataContext = viewModel; var pageContent = new PageContent(); var fixedPage = new FixedPage(); //Create first page of document fixedPage.Children.Add(ReportToPrint); ((IAddChild)pageContent).AddChild(fixedPage); fixedDoc.Pages.Add(pageContent); SendFixedDocumentToPrinter(fixedDoc); }
public static void AskToPrint( ContentPresenter content , string printJobDesc = "Tab Content Visual") { var dlg = new PrintDialog(); if (dlg.ShowDialog() != true) return; //dlg.PrintVisual(contentPresenter, "Tab Content Visual"); var doc = new FixedDocument(); doc.DocumentPaginator.PageSize = new Size(dlg.PrintableAreaWidth, dlg.PrintableAreaHeight); var page = new FixedPage(); page.Width = doc.DocumentPaginator.PageSize.Width; page.Height = doc.DocumentPaginator.PageSize.Height; page.Children.Add(content); // <--- error here var pgContnt = new PageContent(); ((IAddChild)pgContnt).AddChild(page); doc.Pages.Add(pgContnt); dlg.PrintDocument(doc.DocumentPaginator, printJobDesc); }
//Creates a FixedDocument with lots of pages. public FixedDocument CreateMultiPageFixedDocument() { FixedDocument fixedDocument = new FixedDocument(); fixedDocument.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11); //Create a large number of pages so we can see the progress //bar and cancel button in action. for (int i = 0; i < 2; i++) { PageContent pageContent = new PageContent(); fixedDocument.Pages.Add(pageContent); FixedPage fixedPage = new FixedPage(); //Add a canvas with a TextBlock and a Rectangle as children. Canvas canvas = new Canvas(); fixedPage.Children.Add(canvas); TextBlock textBlock = new TextBlock(); textBlock.Text = string.Format("Page {0} / {1}\n\nThis Is Page {0}.", i + 1, 1000); textBlock.FontSize = 24; canvas.Children.Add(textBlock); Rectangle rect = new Rectangle(); rect.Width = 200; rect.Height = 200; rect.Fill = new SolidColorBrush(Color.FromArgb(200, 20, 50, 200)); canvas.Children.Add(rect); ((IAddChild)pageContent).AddChild(fixedPage); } return fixedDocument; }
public IFELabel() { PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); StackPanel rowPanel = new StackPanel(); rowPanel.Orientation = Orientation.Horizontal; rowPanel.Margin = new Thickness(5); IFELabelPanel panel1 = new IFELabelPanel(); IFELabelPanel panel2 = new IFELabelPanel(); IFELabelPanel panel3 = new IFELabelPanel(); IFELabelPanel panel4 = new IFELabelPanel(); rowPanel.Children.Add(panel1); rowPanel.Children.Add(panel2); rowPanel.Children.Add(panel3); rowPanel.Children.Add(panel4); fixedPage.Children.Add(rowPanel); ((System.Windows.Markup.IAddChild)pageContent).AddChild(fixedPage); this.Pages.Add(pageContent); }
private void PrintFixedDocument() { PrintDialog dialog; if (LoadPrintDialog(out dialog)) { var document = new FixedDocument(); var page = new FixedPage(); var t = new TextBlock { FontFamily = font, FontSize = kFontSize, Text = Data.ToString() }; page.Children.Add(t); t.Measure(new Size(document.DocumentPaginator.PageSize.Width, document.DocumentPaginator.PageSize.Width)); page.Height = t.DesiredSize.Height; page.Width = t.DesiredSize.Width; var p = new PageContent { Child = page }; document.Pages.Add(p); Print(document, dialog); } }
public List<PageContent> PrintPage() { List<PageContent> Pages = new List<PageContent>(); InitializePages(); PageContent pageContent = new PageContent(); FixedPage fixedPage = new FixedPage(); PrintDialog printDlg = new PrintDialog(); PrintPreview printPreview = new PrintPreview(m_CaseObject); printPreview.Width = printDlg.PrintableAreaWidth; printPreview.Height = printDlg.PrintableAreaHeight; fixedPage.Children.Add((UIElement)printPreview); ((IAddChild)pageContent).AddChild(fixedPage); Pages.Add(pageContent); return Pages; }
static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { PageContent p = (PageContent)d; p._pageRef = null; }