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;
        }
        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");
            }
        }
예제 #3
0
        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;
        }
예제 #4
0
        static void AddPageToDocument(FixedDocument fixedDocument,FixedPage page)
        {
            PageContent pageContent = new PageContent();
            ((IAddChild)pageContent).AddChild(page);

            fixedDocument.Pages.Add(pageContent);
        }
예제 #5
0
        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;
        }
예제 #6
0
		static FixedDocument CreateFixedDocument(ReportSettings reportSettings)
		{
			var document = new FixedDocument();
			document.DocumentPaginator.PageSize = new System.Windows.Size(reportSettings.PageSize.Width,
			                                                              reportSettings.PageSize.Height);
		return document;
		}
예제 #7
0
        public object Convert (object value, Type targetType, object parameter, CultureInfo culture)
        {
            var document = value as Document;
            if (document == null)
                return null;

            FrameworkContentElement content;
            DocumentRenderTargetBase target;
            if (DocumentType == PresentationDocumentType.FixedDocument) {
                var fixedDocument = new FixedDocument();
                target = new FixedDocumentRenderTarget(fixedDocument);
                content = fixedDocument;
            }
            else {
                var flowDocument = new FlowDocument();
                target = new FlowDocumentRenderTarget(flowDocument);
                content = flowDocument;
            }

            target.Background = Background;
            target.FontFamily = FontFamily;
            target.FontSize = FontSize;
            target.FontStretch = FontStretch;
            target.FontStyle = FontStyle;
            target.FontWeight = FontWeight;

            ConsoleRenderer.RenderDocument(document, target, new Rect(new Size(ConsoleWidth, Size.Infinity)));

            return content;
        }
예제 #8
0
        public static void SaveFixedDocumentAsTiff(FixedDocument document, string outputFileName)
        {
            int pages = document.DocumentPaginator.PageCount;

            TiffBitmapEncoder encoder = new TiffBitmapEncoder();
            encoder.Compression = TiffCompressOption.Ccitt4;

            for (int pageNum = 0; pageNum < pages; pageNum++)
            {
                DocumentPage docPage = document.DocumentPaginator.GetPage(pageNum);

                RenderTargetBitmap renderTarget =
                    new RenderTargetBitmap((int)(docPage.Size.Width * 300 / 96),
                                            (int)(docPage.Size.Height * 300 / 96),
                                            300d, // WPF (Avalon) units are 96dpi based
                                            300d,
                                            System.Windows.Media.PixelFormats.Default);

                renderTarget.Render(docPage.Visual);
                encoder.Frames.Add(BitmapFrame.Create(renderTarget));
            }

            FileStream outputFileStream = new FileStream(outputFileName, FileMode.Create);
            encoder.Save(outputFileStream);
            outputFileStream.Close();
        }
예제 #9
0
        void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.container = ((System.Windows.Controls.DocumentViewer)(target));
                return;

            case 2:
                this.doc = ((System.Windows.Documents.FixedDocument)(target));
                return;

            case 3:

            #line 35 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.saveClick);

            #line default
            #line hidden
                return;

            case 4:

            #line 36 "..\..\MainWindow.xaml"
                ((System.Windows.Controls.Button)(target)).Click += new System.Windows.RoutedEventHandler(this.loadClick);

            #line default
            #line hidden
                return;
            }
            this._contentLoaded = true;
        }
예제 #10
0
파일: home.xaml.cs 프로젝트: sumit10/BMS
 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");
     }
 }
예제 #11
0
        public static FixedDocument FixedDocumentFromImageStream(Stream[] ImagesStream)
        {
            FixedDocument fdReturn = new FixedDocument();

            foreach (Stream streamImage in ImagesStream)
            {
                FixedPage fpFromImage = new FixedPage();

                var bitImage = new BitmapImage();
                bitImage.BeginInit();
                bitImage.StreamSource = streamImage;
                bitImage.DecodePixelWidth = 250;
                bitImage.CacheOption = BitmapCacheOption.OnLoad;
                bitImage.CreateOptions = BitmapCreateOptions.IgnoreColorProfile;
                bitImage.EndInit();
                bitImage.StreamSource.Seek(0, System.IO.SeekOrigin.Begin);
                bitImage.Freeze();

                var tempImage = new System.Windows.Controls.Image { Source = bitImage };
                //var imageObject = new ImageObject(tempImage, fileName);

                fpFromImage.Children.Add(tempImage);
                fdReturn.Pages.Add(new PageContent() { Child = fpFromImage });

                bitImage.StreamSource.Dispose();
            }

            return fdReturn;
        }
예제 #12
0
 /// <summary>
 /// Builds FixedDocument from string.
 /// </summary>
 /// <param name="text">Text to use.</param>
 /// <returns>FixedDocument of text.</returns>
 public static FixedDocument GenerateFixedDocumentFromText(string text)
 {
     FixedDocument document = new FixedDocument();
     PageContent content = GeneratePageFromText(text);
     document.Pages.Add(content);
     return document;
 }
예제 #13
0
		public override void Start()
		{
			base.Start();
			document = new FixedDocument();
			

			// point 	 595x842
			
			// 827/1169

//			A4 paper is 210mm x 297mm
			//8.2 inch x 11.6 inch
			//1240 px x 1754 px
			/*
		iTextSharp uses a default of 72 pixels per inch.
			792 would be 11", or the height of a standard Letter size paper." +
			595 would be 8.264",
		which is the standard width of A4 size paper.
			Using 595 x 792 as the page size would be a cheap and dirty way
			to ensure that you could print on either A4 or Letter
			without anything getting cut off. –
			 */
			
			docCreator.PageSize = new System.Windows.Size(reportSettings.PageSize.Width,reportSettings.PageSize.Height);
			document.DocumentPaginator.PageSize = docCreator.PageSize;
		}
예제 #14
0
        /// <summary>
        ///     Displays the <see cref="FixedDocument" /> in a <see cref="DocumentViewer" />
        /// </summary>
        /// <param name="fixedDocument">The fixed document to display.</param>
        /// <param name="title">Title of the preview window</param>
        /// <param name="windowProvider">An implementation for creating a customized window. If null, default implementation is used.</param>
        public static void ShowFixedDocument(FixedDocument fixedDocument, string title, IWindowProvider windowProvider = null)
        {
            var tempFileName = Path.GetTempFileName();

            WriteXps(fixedDocument, tempFileName);
            ShowXps(tempFileName, title, windowProvider);
        }
예제 #15
0
        private void PrintPreview_Click(object sender, RoutedEventArgs e)
        {
            var printdialog = new PrintDialog();
            if (printdialog.ShowDialog() != true) { return; }
            var doc = new FixedDocument();
            doc.DocumentPaginator.PageSize = new Size(printdialog.PrintableAreaWidth, printdialog.PrintableAreaHeight);
            var queue = printdialog.PrintQueue;
            var caps = queue.GetPrintCapabilities();
            var area = caps.PageImageableArea;
            var marginwidth = (printdialog.PrintableAreaWidth - caps.PageImageableArea.ExtentWidth) / 2.0;
            var marginheight = (printdialog.PrintableAreaHeight - caps.PageImageableArea.ExtentHeight) / 2.0;

            double gutter;
            if (!Double.TryParse(GutterWidthTextbox.Text, out gutter)) { gutter = 0.25; }
            // Translate inches to device independent pixels
            gutter *= 96.0;

            var opts = new PrintOptions
            {
                PrintableWidth = area.ExtentWidth,
                PrintableHeight = area.ExtentHeight,
                MarginWidth = marginwidth,
                MarginHeight = marginheight,
                Gutter = gutter
            };

            var category = (CardCategory)DataContext;
            category.AddPagesToDocument(doc, opts, category.SelectedCards);

            var preview = new PrintPreview();
            preview.Document = doc;
            preview.ShowDialog();
        }
예제 #16
0
파일: print.cs 프로젝트: K0lyuchiy/Tass
        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();
        }
예제 #17
0
		public override void Run () {
			Document = new FixedDocument();
			foreach (var page in Pages) {
				IAcceptor acceptor = page as IAcceptor;
				if (acceptor != null) {
					visitor.Visit(page);
				}
				AddPageToDocument(Document,visitor.FixedPage);
			}
		}
예제 #18
0
        public void OnLoaded(object sender, RoutedEventArgs args)
        {
            XpsDocument document = new XpsDocument(Window1.CombineFileInCurrentDirectory("CSharp 3.0 Specification.xps"), System.IO.FileAccess.Read);

            FixedDocument doc = new FixedDocument();
            FixedDocumentSequence fixedDoc = document.GetFixedDocumentSequence();

            viewer.Document = fixedDoc;
            viewer.FitToHeight();
        }
 protected FixedDocument GenerateReport(Func<int, object> frameDataContext, Size paperSize, Margins margins, IEnumerable records)
 {
     var document = new FixedDocument();
       document.DocumentPaginator.PageSize = new Size(DPI * paperSize.Width, DPI * paperSize.Height);
       foreach (var page in CreatePages(frameDataContext, paperSize, margins, records))
       {
     document.Pages.Add(page);
       }
       return document;
 }
예제 #20
0
        /// <summary>
        /// Builds FixedDocument from file.
        /// </summary>
        /// <param name="filename">Path of file to use.</param>
        /// <param name="err">Error container.</param>
        /// <returns>FixedDocument of file.</returns>
        public static FixedDocument GenerateFixedDocumentFromFile(string filename, out string err)
        {
            FixedDocument doc = new FixedDocument();
            string text = null;

            // KFreon: Set error if necessary
            if ((err = UsefulThings.General.ReadTextFromFile(filename, out text)) == null)
                doc = GenerateFixedDocumentFromText(text);

            return doc;
        }
예제 #21
0
 private void PrivateCreatePagesFromFixedDocument(FixedDocument fixedDocument)
 {
     foreach (var pageContent in fixedDocument.Pages)
     {
         Pages.Add(((IUriContext) pageContent).BaseUri != null
             ? new RollUpFixedPage(pageContent.Source, ((IUriContext) pageContent).BaseUri)
             : new RollUpFixedPage(pageContent.Child));
     }
     Source = null;
     BaseUri = null;
 }
예제 #22
0
        private static int CreatePages(DefinitionsForPrintWithXAMLControls XAMLDefinitionsForOnePage,
            FixedDocument PageDocumentToPrint, double MaxOHeight,
            List<Object> printCollection, ObservableCollection<object> PageCollection, 
            String HeadLineText, int NumberOfPages = 0)
            {
            int CountedNumberOfPages = 0;
            double RemainingHeight = 0;
            List<CommonPageFooter> CreatetedFooterPages = new List<CommonPageFooter>();

            PageCollection.Add(new CommonPageHeader() { HeadLineText = HeadLineText });
            foreach (object ControlToPrint in printCollection)
                {
                PageCollection.Add(ControlToPrint);
                XAMLDefinitionsForOnePage.Measure(new Size(PAPER_SIZE_WIDTH, PAPER_SIZE_HEIGHT));
                XAMLDefinitionsForOnePage.Arrange(new Rect(new Point(), new Size(PAPER_SIZE_WIDTH, PAPER_SIZE_HEIGHT)));
                XAMLDefinitionsForOnePage.UpdateLayout();
                double width = XAMLDefinitionsForOnePage.DesiredSize.Width;
                double height = XAMLDefinitionsForOnePage.DesiredSize.Height;

                RemainingHeight = MaxOHeight - height;
                if (height > MaxOHeight)
                    {
                    PageCollection.Remove(ControlToPrint);
                    CreatetedFooterPages.Add(new CommonPageFooter());
                    PageCollection.Add(CreatetedFooterPages.Last());
                    XAMLDefinitionsForOnePage = GenerateNewContent(PageDocumentToPrint);
                    PageCollection = XAMLDefinitionsForOnePage.GlobalContainer.ItemsSource as ObservableCollection<object>;
                    PageCollection.Add(new CommonPageHeader() { HeadLineText = HeadLineText});
                    PageCollection.Add(ControlToPrint);
                    XAMLDefinitionsForOnePage.Measure(new Size(PAPER_SIZE_WIDTH, PAPER_SIZE_HEIGHT));
                    XAMLDefinitionsForOnePage.Arrange(new Rect(new Point(), new Size(PAPER_SIZE_WIDTH, PAPER_SIZE_HEIGHT)));
                    XAMLDefinitionsForOnePage.UpdateLayout();
                    CountedNumberOfPages++;
                    }
                }
            CreatetedFooterPages.Add(new CommonPageFooter() { DistanceToLastLineValue = RemainingHeight - 20});
            PageCollection.Add(CreatetedFooterPages.Last());
            CountedNumberOfPages++;

            int WorkingPageNumber = 0;
            foreach (CommonPageFooter Footer in CreatetedFooterPages)
                {
                Footer.NumberOfPages = CountedNumberOfPages;
                Footer.PageNumber = ++WorkingPageNumber;
                }

            foreach (PageContent Page in PageDocumentToPrint.Pages)
                {
                Page.Measure(new Size(PAPER_SIZE_WIDTH, PAPER_SIZE_HEIGHT));
                Page.Arrange(new Rect(new Point(), new Size(PAPER_SIZE_WIDTH, PAPER_SIZE_HEIGHT)));
                Page.UpdateLayout();
                }
            return CountedNumberOfPages;
            }
예제 #23
0
        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");
        }
예제 #24
0
		public PreviewViewModel(ReportSettings reportSettings, Collection<ExportPage> pages)
		{
			if (pages == null)
				throw new ArgumentNullException("pages");
			if (reportSettings == null)
				throw new ArgumentNullException("reportSettings");
			
			Document = CreateFixedDocument(reportSettings);
			
			var wpfExporter = new WpfExporter(pages);
			wpfExporter.Run();
			this.document = wpfExporter.Document;
		}
예제 #25
0
        /// <summary>constructor
        /// </summary>
        /// <param name="reportFirstPageHeader"></param>
        /// <param name="reportFooter">page header for first page</param>
        /// <param name="reportNextPageHeader">page header for second and next pages, if null then page header for first page is used</param>
        public ReportDocument(HeaderFooterBase reportFirstPageHeader, HeaderFooterBase reportFooter, HeaderFooterBase reportNextPageHeader = null)
        {
            m_ReportFirstPageHeader = reportFirstPageHeader;
            m_ReportNextPageHeader = (reportNextPageHeader ?? m_ReportFirstPageHeader);
            m_ReportFooter = reportFooter;
            m_FixedDocument = new FixedDocument();

            m_FixedDocument.DocumentPaginator.PageSize = new Size(ReportPage.DisplayResolution * ReportPage.PageWidth, ReportPage.DisplayResolution * ReportPage.PageHeight);
            m_CurrentReportPage = new ReportPage(m_ReportFirstPageHeader, m_ReportFooter);
            m_FixedDocument.Pages.Add(m_CurrentReportPage.PageContent);

            m_CurrentReportPage.UpdatePageLayout();
        }
예제 #26
0
        public MultiPageDocument(HeaderFooterBase reportFirstPageHeader, HeaderFooterBase reportNextPageHeader = null)
        {
            this.m_ReportFirstPageHeader = reportFirstPageHeader;
            this.m_ReportNextPageHeader = (reportNextPageHeader ?? m_ReportFirstPageHeader);
            this.m_FixedDocument = new FixedDocument();

            this.m_FixedDocument.DocumentPaginator.PageSize = new Size(ReportPage.DisplayResolution * ReportPage.PageWidth, ReportPage.DisplayResolution * ReportPage.PageHeight);
            PageNumberFooter pageNumberFooter = new PageNumberFooter(1);
            this.m_CurrentReportPage = new ReportPage(m_ReportFirstPageHeader, pageNumberFooter);
            this.m_FixedDocument.Pages.Add(m_CurrentReportPage.PageContent);

            this.m_CurrentReportPage.UpdatePageLayout();
        }
예제 #27
0
        public void Create()
        {
            var uri    = new Uri("pack://application:,,,/ypi_client_order.xps");
            var stream = System.Windows.Application.GetResourceStream(uri).Stream;

            System.IO.Packaging.Package package1 = System.IO.Packaging.Package.Open(stream);
            System.IO.Packaging.PackageStore.AddPackage(uri, package1);
            var xpsDoc = new XpsDocument(package1, System.IO.Packaging.CompressionOption.Maximum, uri.AbsoluteUri);
            var fixedDocumentSequenceO = xpsDoc.GetFixedDocumentSequence();

            MemoryStream xpsStream       = new MemoryStream();
            Package      package2        = Package.Open(xpsStream, FileMode.Create);
            string       memoryStreamUri = "memorystream://printstream";
            Uri          packageUri      = new Uri(memoryStreamUri);

            PackageStore.AddPackage(packageUri, package2);
            XpsDocument       doc    = new XpsDocument(package2, CompressionOption.Fast, memoryStreamUri);
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(doc);

            System.Windows.Documents.Serialization.SerializerWriterCollator vxpsd = writer.CreateVisualsCollator();
            int pageno = 1;

            foreach (System.Windows.Documents.DocumentReference r in fixedDocumentSequenceO.References)
            {
                System.Windows.Documents.FixedDocument d = r.GetDocument(false);
                foreach (System.Windows.Documents.PageContent pc in d.Pages)
                {
                    System.Windows.Documents.FixedPage fixedPage = pc.GetPageRoot(false);
                    double width           = fixedPage.Width;
                    double height          = fixedPage.Height;
                    System.Windows.Size sz = new System.Windows.Size(width, height);
                    fixedPage.Measure(sz);
                    fixedPage.Arrange(new System.Windows.Rect(new System.Windows.Point(), sz));
                    fixedPage.UpdateLayout();
                    ContainerVisual newpage = new ContainerVisual();
                    newpage.Children.Add(fixedPage);
                    newpage.Children.Add(CreateWatermark(400, 400, "hello world"));
                    pageno++;
                    vxpsd.Write(newpage);

                    //PackageStore.RemovePackage(packageUri);
                    //doc.Close();
                }
            }

            doc.Close();
            xpsStream.Position = 0;
            Package     finalPackage          = Package.Open(xpsStream, FileMode.Open);
            XpsDocument finalDoc              = new XpsDocument(finalPackage, CompressionOption.Fast, memoryStreamUri);
            var         fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
        }
예제 #28
0
		public PreviewViewModel(ReportSettings reportSettings, Collection<IPage> pages)
		{
			if (pages == null)
				throw new ArgumentNullException("pages");
			if (reportSettings == null)
				throw new ArgumentNullException("reportSettings");
			Document = new FixedDocument();
			var s = Document.DocumentPaginator.PageSize;
			Document.DocumentPaginator.PageSize = new System.Windows.Size(reportSettings.PageSize.Width,reportSettings.PageSize.Height);
			var wpfExporter = new WpfExporter(reportSettings,pages);
			wpfExporter.Run();
			var fixedPage = wpfExporter.FixedPage;
			AddPageToDocument(Document,fixedPage);
		}
예제 #29
0
        private static void SendFixedDocumentToPrinter(FixedDocument fixedDocument)
        {
            XpsDocumentWriter xpsdw;

            PrintDocumentImageableArea imgArea = null;
            //こちらのオーバーロードだと、プリンタ選択ダイアログが出る。
            xpsdw = PrintQueue.CreateXpsDocumentWriter(ref imgArea);

            //var ps = new LocalPrintServer();
            //var pq = ps.DefaultPrintQueue;
            //こちらのオーバーロードだと、プリンタ選択ダイアログを飛ばして既定のプリンタにスプールされる
            //xpsdw = PrintQueue.CreateXpsDocumentWriter(pq);
            xpsdw.Write(fixedDocument);
        }
예제 #30
0
        /// <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);
            }
        }
예제 #31
0
파일: XpsDoc.cs 프로젝트: dingxinbei/OLdBck
        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;
        }
예제 #32
0
        /// <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");
            }
        }
예제 #33
0
        public static void DoItTTT()
        {
            string filename    = "c:\\tmp\\goof.xps";
            string newFilename = "c:\\tmp\\new_goof.xps";

            XpsDocument xpsOld = new XpsDocument(filename, System.IO.FileAccess.Read);

            System.Windows.Documents.FixedDocumentSequence seqOld = xpsOld.GetFixedDocumentSequence();
            System.IO.Packaging.Package container = System.IO.Packaging.Package.Open(newFilename, System.IO.FileMode.Create);
            XpsDocumentWriter           writer    = XpsDocument.CreateXpsDocumentWriter(new XpsDocument(container));

            System.Windows.Documents.Serialization.SerializerWriterCollator vxpsd = writer.CreateVisualsCollator();
            int pageno = 1;

            foreach (System.Windows.Documents.DocumentReference r in seqOld.References)
            {
                System.Windows.Documents.FixedDocument d = r.GetDocument(false);
                foreach (System.Windows.Documents.PageContent pc in d.Pages)
                {
                    System.Windows.Documents.FixedPage fixedPage = pc.GetPageRoot(false);
                    double width           = fixedPage.Width;
                    double height          = fixedPage.Height;
                    System.Windows.Size sz = new System.Windows.Size(width, height);
                    fixedPage.Measure(sz);
                    fixedPage.Arrange(new System.Windows.Rect(new System.Windows.Point(), sz));
                    fixedPage.UpdateLayout();
                    ContainerVisual newpage = new ContainerVisual();
                    newpage.Children.Add(fixedPage);
                    newpage.Children.Add(CreateWatermark(400, 400, "hello world"));
                    pageno++;
                    vxpsd.Write(newpage);
                }
            }
            vxpsd.EndBatchWrite();
            container.Close();
            xpsOld.Close();
        }
 /// <summary>
 /// Attach a document to this DocumentReference
 /// You can only attach a document if it is not attached before or it is not created from URI before.
 /// </summary>
 /// <param name="doc"></param>
 public void SetDocument(FixedDocument doc)
 {
     VerifyAccess();
     _docIdentity = null;
     _doc         = doc;
 }
예제 #35
0
        //--------------------------------------------------------------------
        //
        // Constructors
        //
        //---------------------------------------------------------------------

        #region Constructors

        /// <summary>
        ///     HighlightVisual construction
        /// </summary>
        /// <param name="panel">FixedDocument where selection is taking place</param>
        /// <param name="page">FixedPage that is being highlighted</param>
        internal HighlightVisual(FixedDocument panel, FixedPage page) : base(page)
        {
            _panel = panel;
            _page  = page;
        }
        //Searches for the specified pattern and updates start *or* end pointers depending on search direction
        //At the end of the operation, start or end should be pointing to the beginning/end of the page
        //of occurance of pattern respectively
        internal static TextRange Find(ITextPointer start,
                                       ITextPointer end,
                                       string findPattern,
                                       CultureInfo cultureInfo,
                                       bool matchCase,
                                       bool matchWholeWord,
                                       bool matchLast,
                                       bool matchDiacritics,
                                       bool matchKashida,
                                       bool matchAlefHamza)
        {
            Debug.Assert(start != null);
            Debug.Assert(end != null);
            Debug.Assert(((start is DocumentSequenceTextPointer) && (end is DocumentSequenceTextPointer)) ||
                         ((start is FixedTextPointer) && (end is FixedTextPointer)));
            Debug.Assert(findPattern != null);

            if (findPattern.Length == 0)
            {
                return(null);
            }

            IDocumentPaginatorSource paginatorSource = start.TextContainer.Parent as IDocumentPaginatorSource;
            DynamicDocumentPaginator paginator       = paginatorSource.DocumentPaginator as DynamicDocumentPaginator;

            Debug.Assert(paginator != null);

            int pageNumber    = -1;
            int endPageNumber = -1;

            if (matchLast)
            {
                endPageNumber = paginator.GetPageNumber((ContentPosition)start);
                pageNumber    = paginator.GetPageNumber((ContentPosition)end);
            }
            else
            {
                endPageNumber = paginator.GetPageNumber((ContentPosition)end);
                pageNumber    = paginator.GetPageNumber((ContentPosition)start);
            }

            TextRange result = null;

            CompareInfo    compareInfo = cultureInfo.CompareInfo;
            bool           replaceAlefWithAlefHamza = false;
            CompareOptions compareOptions           = _InitializeSearch(cultureInfo, matchCase, matchAlefHamza, matchDiacritics, ref findPattern, out replaceAlefWithAlefHamza);

            //Translate the page number
            int translatedPageNumber = pageNumber;
            //If this is a DocumentSequence, we need to pass translated page number to the below call
            FixedDocumentSequence    documentSequence = paginatorSource as FixedDocumentSequence;
            DynamicDocumentPaginator childPaginator   = null;

            if (documentSequence != null)
            {
                documentSequence.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber);
            }

            if (pageNumber - endPageNumber != 0)
            {
                ITextPointer firstSearchPageStart = null;
                ITextPointer firstSearchPageEnd   = null;

                _GetFirstPageSearchPointers(start, end, translatedPageNumber, matchLast, out firstSearchPageStart, out firstSearchPageEnd);

                Debug.Assert(firstSearchPageStart != null);
                Debug.Assert(firstSearchPageEnd != null);

                //Need to search the first page using TextFindEngine to start exactly from the requested search location to avoid false positives
                result = TextFindEngine.InternalFind(firstSearchPageStart,
                                                     firstSearchPageEnd,
                                                     findPattern,
                                                     cultureInfo,
                                                     matchCase,
                                                     matchWholeWord,
                                                     matchLast,
                                                     matchDiacritics,
                                                     matchKashida,
                                                     matchAlefHamza);
                if (result == null)
                {
                    //Start from the next page and check all pages until the end
                    pageNumber = matchLast ? pageNumber - 1 : pageNumber + 1;
                    int increment = matchLast ? -1 : 1;
                    for (; matchLast?pageNumber >= endPageNumber : pageNumber <= endPageNumber; pageNumber += increment)
                    {
                        FixedDocument fixedDoc = null;

                        translatedPageNumber = pageNumber;
                        childPaginator       = null;
                        if (documentSequence != null)
                        {
                            documentSequence.TranslatePageNumber(pageNumber, out childPaginator, out translatedPageNumber);
                            fixedDoc = (FixedDocument)childPaginator.Source;
                        }
                        else
                        {
                            fixedDoc = paginatorSource as FixedDocument;
                        }

                        Debug.Assert(fixedDoc != null);

                        String pageString = _GetPageString(fixedDoc, translatedPageNumber, replaceAlefWithAlefHamza);

                        if (pageString == null)
                        {
                            //This is not a page-per-stream
                            //Default back to slow search
                            return(TextFindEngine.InternalFind(start,
                                                               end,
                                                               findPattern,
                                                               cultureInfo,
                                                               matchCase,
                                                               matchWholeWord,
                                                               matchLast,
                                                               matchDiacritics,
                                                               matchKashida,
                                                               matchAlefHamza));
                        }

                        if (_FoundOnPage(pageString, findPattern, cultureInfo, compareOptions))
                        {
                            //Update end or start pointer depending on search direction
                            if (documentSequence != null)
                            {
                                ChildDocumentBlock childBlock = documentSequence.TextContainer.FindChildBlock(fixedDoc.DocumentReference);
                                if (matchLast)
                                {
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(translatedPageNumber)));
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(translatedPageNumber)));
                                }
                                else
                                {
                                    start = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Forward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageStartFlowPosition(translatedPageNumber)));
                                    end   = new DocumentSequenceTextPointer(childBlock, new FixedTextPointer(false, LogicalDirection.Backward, fixedDoc.FixedContainer.FixedTextBuilder.GetPageEndFlowPosition(translatedPageNumber)));
                                }
                            }
                            else
                            {
                                //We are working on a FixedDocument
                                FixedTextBuilder textBuilder = ((FixedDocument)(paginatorSource)).FixedContainer.FixedTextBuilder;
                                if (matchLast)
                                {
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, textBuilder.GetPageEndFlowPosition(pageNumber));
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, textBuilder.GetPageStartFlowPosition(pageNumber));
                                }
                                else
                                {
                                    start = new FixedTextPointer(false, LogicalDirection.Forward, textBuilder.GetPageStartFlowPosition(pageNumber));
                                    end   = new FixedTextPointer(false, LogicalDirection.Backward, textBuilder.GetPageEndFlowPosition(pageNumber));
                                }
                            }
                            result = TextFindEngine.InternalFind(start,
                                                                 end,
                                                                 findPattern,
                                                                 cultureInfo,
                                                                 matchCase,
                                                                 matchWholeWord,
                                                                 matchLast,
                                                                 matchDiacritics,
                                                                 matchKashida,
                                                                 matchAlefHamza);

                            //If the result is null, this means we had a false positive
                            if (result != null)
                            {
                                return(result);
                            }
                        }
                    }
                }
            }

            else
            {
                //Make sure fast search result and slow search result are consistent
                FixedDocument fixedDoc   = childPaginator != null ? childPaginator.Source as FixedDocument : paginatorSource as FixedDocument;
                String        pageString = _GetPageString(fixedDoc, translatedPageNumber, replaceAlefWithAlefHamza);
                if (pageString == null ||
                    _FoundOnPage(pageString, findPattern, cultureInfo, compareOptions))
                {
                    //The search is only limited to the current page
                    result = TextFindEngine.InternalFind(start,
                                                         end,
                                                         findPattern,
                                                         cultureInfo,
                                                         matchCase,
                                                         matchWholeWord,
                                                         matchLast,
                                                         matchDiacritics,
                                                         matchKashida,
                                                         matchAlefHamza);
                }
            }

            return(result);
        }
예제 #37
0
 /// <summary>Attaches a <see cref="T:System.Windows.Documents.FixedDocument" /> to the <see cref="T:System.Windows.Documents.DocumentReference" />.</summary>
 /// <param name="doc">The document that is attached.</param>
 // Token: 0x06002B57 RID: 11095 RVA: 0x000C607A File Offset: 0x000C427A
 public void SetDocument(FixedDocument doc)
 {
     base.VerifyAccess();
     this._docIdentity = null;
     this._doc         = doc;
 }
예제 #38
0
 // Token: 0x06002CE4 RID: 11492 RVA: 0x000CA9D1 File Offset: 0x000C8BD1
 internal FixedDocumentPage(FixedDocument panel, FixedPage page, Size fixedSize, int index) : base(page, fixedSize, new Rect(fixedSize), new Rect(fixedSize))
 {
     this._panel = panel;
     this._page  = page;
     this._index = index;
 }
예제 #39
0
 // Token: 0x06003267 RID: 12903 RVA: 0x000DCC63 File Offset: 0x000DAE63
 internal PageContentCollection(FixedDocument logicalParent)
 {
     this._logicalParent = logicalParent;
     this._internalList  = new List <PageContent>();
 }