Esempio n. 1
0
        /// <summary>
        /// Take a list of <see cref="UIElement"/> and return a <see cref="FixedDocument"/> where each page contains the given <see cref="UIElement"/>.
        /// </summary>
        /// <param name="uiElements"><see cref="UIElement"/> derived classes to place each in a <see cref="FixedPage"/>.</param>
        /// <param name="pageSize">Desired page size of each <see cref="FixedPage"/>. If <see cref="Paginator"/> was used to paginate, this should be the same value given to the Paginate method.</param>
        /// <returns></returns>
        public FixedDocument GetFixedDocumentFromPages(List <UIElement> uiElements, Size pageSize)
        {
            var document = new FixedDocument();

            document.DocumentPaginator.PageSize = pageSize;

            foreach (var page in uiElements)
            {
                var fixedPage = new FixedPage
                {
                    Width  = document.DocumentPaginator.PageSize.Width,
                    Height = document.DocumentPaginator.PageSize.Height
                };

                FixedPage.SetLeft(page, 0);
                FixedPage.SetTop(page, 0);

                fixedPage.Children.Add(page);

                var pageContent = new PageContent();
                ((IAddChild)pageContent).AddChild(fixedPage);

                fixedPage.Measure(pageSize);
                fixedPage.Arrange(new Rect(new Point(), pageSize));
                fixedPage.UpdateLayout();

                document.Pages.Add(pageContent);
            }

            return(document);
        }
Esempio n. 2
0
        /// <summary>
        /// PageからFixedPageを作成し、PageContentに追加
        /// </summary>
        /// <param name="sender">Page</param>
        /// <param name="size">縦横サイズ</param>
        /// <returns>PageContent</returns>
        private PageContent CreatePageContent(object sender, Size size)
        {
            var pageContent = new PageContent();
            var fixedPage   = new FixedPage();

            if (sender is Page page)
            {
                var frame = new Frame {
                    Content = page
                };

                FixedPage.SetLeft(frame, 0d);
                FixedPage.SetTop(frame, 0d);

                fixedPage.Children.Add(frame);
                fixedPage.Width  = size.Width;
                fixedPage.Height = size.Height;
                fixedPage.Measure(size);
                fixedPage.Arrange(new Rect(new Point(), size));
                fixedPage.UpdateLayout();

                pageContent.Child = fixedPage;
            }

            return(pageContent);
        }
        private static void PositionizeUiElement(PageContent pageContent, UIElement frameworkElement, Point positioningPoint)
        {
            FixedPage.SetTop(frameworkElement, positioningPoint.Y);
            FixedPage.SetLeft(frameworkElement, positioningPoint.X);

            pageContent.Child.Children.Add(frameworkElement);
        }
Esempio n. 4
0
        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);
        }
Esempio n. 5
0
        /// <summary>
        /// Fügt einen Text hinzu mit der Möglichkeit eines Rahmnens
        /// </summary>
        /// <param name="Page"></param>
        /// <param name="Text"></param>
        /// <param name="Top"></param>
        /// <param name="Left"></param>
        /// <param name="FontSize"></param>
        /// <param name="Width"></param>
        /// <param name="alignment"></param>
        /// <param name="Weight"></param>
        /// <param name="Border"></param>
        protected void AddText(FixedPage Page, string Text, double Top, double Left, int FontSize, double Width, double Height, TextAlignment alignment, FontWeight Weight, int Border)
        {
            TextBlock text = new TextBlock();

            text.Text          = Text;
            text.FontSize      = FontSize;
            text.FontFamily    = new FontFamily("Arial");
            text.TextAlignment = alignment;
            text.FontWeight    = Weight;
            text.Width         = Width * 96 / 2.54;
            text.Height        = Height * 96 / 2.54;
            var width    = text.ActualWidth;
            var boxwidth = Width * 96 / 2.54;
            var diff     = (boxwidth - width) / 2;

            if (Border > 0)
            {
                text.Padding = new Thickness(4, 2, 2, 2);
            }

            Border b = new Border();

            b.BorderThickness = new Thickness(Border);
            b.BorderBrush     = Brushes.Black;
            b.Child           = text;
            FixedPage.SetLeft(b, 96 * Left / 2.54); // left margin
            FixedPage.SetTop(b, 96 / 2.54 * Top);   // top margin
            width = text.ActualWidth;
            Page.Children.Add((UIElement)b);
        }
Esempio n. 6
0
        public static void Print(FrameworkElement objectToPrint, string print_job_name)
        {
            double original_width  = objectToPrint.ActualWidth;
            double original_height = objectToPrint.ActualHeight;

            PrintDialog printDialog = new PrintDialog();

            if ((bool)printDialog.ShowDialog().GetValueOrDefault())
            {
                PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);

                // Convert the UI control into a bitmap
                double             DPI      = 200;
                double             dpiScale = DPI / 96.0;
                RenderTargetBitmap bmp      = new RenderTargetBitmap(
                    Convert.ToInt32(objectToPrint.ActualWidth * dpiScale),
                    Convert.ToInt32(objectToPrint.ActualHeight * dpiScale),
                    DPI, DPI, PixelFormats.Pbgra32
                    );
                bmp.Render(objectToPrint);
                bmp.Freeze();


                // Create the document
                FixedDocument document = new FixedDocument();
                document.DocumentPaginator.PageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);


                // Break the bitmap down into pages
                int pageWidth  = Convert.ToInt32(capabilities.PageImageableArea.ExtentWidth * dpiScale);
                int pageHeight = Convert.ToInt32(capabilities.PageImageableArea.ExtentHeight * dpiScale);
                {
                    FixedPage printDocumentPage = new FixedPage();
                    printDocumentPage.Width  = pageWidth;
                    printDocumentPage.Height = pageHeight;

                    // Create a new bitmap for the contents of this page
                    Image pageImage = new Image();
                    pageImage.Source              = bmp;
                    pageImage.VerticalAlignment   = VerticalAlignment.Center;
                    pageImage.HorizontalAlignment = HorizontalAlignment.Center;

                    // Place the bitmap on the page
                    printDocumentPage.Children.Add(pageImage);

                    PageContent pageContent = new PageContent();
                    ((IAddChild)pageContent).AddChild(printDocumentPage);

                    pageImage.Width  = capabilities.PageImageableArea.ExtentWidth;
                    pageImage.Height = capabilities.PageImageableArea.ExtentHeight;

                    FixedPage.SetLeft(pageImage, capabilities.PageImageableArea.OriginWidth);
                    FixedPage.SetTop(pageImage, capabilities.PageImageableArea.OriginHeight);

                    document.Pages.Add(pageContent);
                }

                printDialog.PrintDocument(document.DocumentPaginator, print_job_name);
            }
        }
Esempio n. 7
0
        //<SnippetXpsSaveCreateFixedPage1>
        // ----------------------- CreateFirstFixedPage -----------------------
        /// <summary>
        ///   Creates the FixedPage for the first page.</summary>
        /// <returns>
        ///   The FixedPage for the first page.</returns>
        private FixedPage CreateFirstFixedPage()
        {
            FixedPage fixedPage = new FixedPage();

            fixedPage.Background = Brushes.LightYellow;
            UIElement visual = CreateFirstVisual(false);

            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();

            return(fixedPage);
        }// end:CreateFirstFixedPage()
Esempio n. 8
0
        }// end:CreateFourthPageContent()

        //<SnippetXpsSaveCreateFixedPage5>
        // --------------------- CreateFifthPageContent -----------------------
        /// <summary>
        ///   Creates the content for the fifth fixed page.</summary>
        /// <returns>
        ///   The page content for the fifth fixed page.</returns>
        private PageContent CreateFifthPageContent()
        {
            PageContent pageContent = new PageContent();
            FixedPage   fixedPage   = new FixedPage();
            UIElement   visual      = CreateThirdVisual(false);

            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);
        }// end:CreateFifthPageContent()
Esempio n. 9
0
        private PageContent CreatePageContent(SautinSoft.Document.DocumentPage page)
        {
            PageContent pageContent = new PageContent();
            FixedPage   fixedPage   = new FixedPage();

            UIElement visual = page.GetContent();

            FixedPage.SetLeft(visual, 0);
            FixedPage.SetTop(visual, 0);

            double pageWidth  = page.Width;
            double pageHeight = page.Height;

            fixedPage.Width  = pageWidth;
            fixedPage.Height = pageHeight;

            fixedPage.Children.Add((UIElement)visual);

            //Size sz = new Size(pageWidth, pageHeight);
            //fixedPage.Measure(sz);
            //fixedPage.Arrange(new Rect(new Point(), sz));
            //fixedPage.UpdateLayout();

            ((IAddChild)pageContent).AddChild(fixedPage);
            return(pageContent);
        }
        private void AddPageNumbers(int from = 0, int to = int.MaxValue)
        {
            var currentPageCount = 0;

            foreach (var pageContent in FixedDocument.Pages.Skip(from).Take(to))
            {
                currentPageCount++;
                if (!_printProcessor.PrintDefinition.IsToPrint(PrintAppendixes.PageNumbers, currentPageCount, false))
                {
                    continue;
                }

                Trace.TraceInformation($"Print Page Numbers on page #{currentPageCount}");
                var textBlock = new TextBlock {
                    Text = $"{currentPageCount} | {FixedDocument.Pages.Count - from}", TextAlignment = TextAlignment.Center, Width = _printProcessor.PrintDimension.PrintablePageSize.Width
                };

                if (_printProcessor.ColorPrintPartsForDebug)
                {
                    textBlock.Background = Brushes.Red;
                }

                textBlock.Height = _printProcessor.PrintDimension.GetPageNumberHeight(currentPageCount);

                FixedPage.SetTop(textBlock, _printProcessor.PrintDimension.GetRange(PrintAppendixes.PageNumbers, currentPageCount, false).From);
                FixedPage.SetLeft(textBlock, _printProcessor.PrintDimension.Margin.Left);
                pageContent.Child.Children.Add(textBlock);
            }
        }
Esempio n. 11
0
        private PageContent generatePageContent(System.Drawing.Bitmap bmp, int top, int bottom, double pageWidth, double PageHeight, System.Printing.PrintCapabilities capabilities)
        {
            FixedPage printDocumentPage = new FixedPage();

            printDocumentPage.Width  = pageWidth;
            printDocumentPage.Height = PageHeight;
            int newImageHeight = bottom - top;

            System.Drawing.Bitmap bmpPage = bmp.Clone(new System.Drawing.Rectangle(0, top, bmp.Width, newImageHeight), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            // Create a new bitmap for the contents of this page
            Image        pageImage = new Image();
            BitmapSource bmpSource =
                System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    bmpPage.GetHbitmap(),
                    IntPtr.Zero,
                    System.Windows.Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight(bmp.Width, newImageHeight));

            pageImage.Source            = bmpSource;
            pageImage.VerticalAlignment = VerticalAlignment.Top;
            // Place the bitmap on the page
            printDocumentPage.Children.Add(pageImage);
            PageContent pageContent = new PageContent();

            ((System.Windows.Markup.IAddChild)pageContent).AddChild(printDocumentPage);
            FixedPage.SetLeft(pageImage, capabilities.PageImageableArea.OriginWidth);
            FixedPage.SetTop(pageImage, capabilities.PageImageableArea.OriginHeight);
            pageImage.Width  = capabilities.PageImageableArea.ExtentWidth;
            pageImage.Height = capabilities.PageImageableArea.ExtentHeight;
            return(pageContent);
        }
Esempio n. 12
0
        public static FixedDocument GetFixedDocument(FrameworkElement toPrint, PrintDialog printDialog)
        {
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Starting {0}", MethodBase.GetCurrentMethod().ToString());
            }
            if (toPrint == null)
            {
                return(null);
            }
            if (printDialog == null)
            {
                return(null);
            }
            System.Printing.PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);

            Size          pageSize    = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
            Size          visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
            FixedDocument fixedDoc    = new FixedDocument();

            //If the toPrint visual is not displayed on screen we neeed to measure and arrange it
            toPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            toPrint.Arrange(new Rect(new Point(0, 0), toPrint.DesiredSize));
            //
            Size size = toPrint.DesiredSize;
            //Will assume for simplicity the control fits horizontally on the page
            double yOffset = 0;

            while (yOffset < size.Height)
            {
                VisualBrush vb = new VisualBrush(toPrint);
                vb.Stretch      = Stretch.None;
                vb.AlignmentX   = AlignmentX.Left;
                vb.AlignmentY   = AlignmentY.Top;
                vb.ViewboxUnits = BrushMappingMode.Absolute;
                vb.TileMode     = TileMode.None;
                vb.Viewbox      = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height);
                PageContent pageContent = new PageContent();
                FixedPage   page        = new FixedPage();
                ((IAddChild)pageContent).AddChild(page);
                fixedDoc.Pages.Add(pageContent);
                page.Width  = pageSize.Width;
                page.Height = pageSize.Height;
                Canvas canvas = new Canvas();
                FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
                FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
                canvas.Width      = visibleSize.Width;
                canvas.Height     = visibleSize.Height;
                canvas.Background = vb;
                page.Children.Add(canvas);
                yOffset += visibleSize.Height;
            }
            if (_log.IsDebugEnabled)
            {
                _log.DebugFormat("Ending {0}", MethodBase.GetCurrentMethod().ToString());
            }
            return(fixedDoc);
        }
        public FixedDocument CreateFixedDocument(IEnumerable <string> diagrams,
                                                 Size areaExtent,
                                                 Size areaOrigin,
                                                 bool fixedStrokeThickness,
                                                 DiagramTable table)
        {
            var origin = new Point(areaOrigin.Width, areaOrigin.Height);
            var area   = new Rect(origin, areaExtent);
            var scale  = Math.Min(areaExtent.Width / PageWidth, areaExtent.Height / PageHeight);

            var fixedDocument = new FixedDocument()
            {
                Name = "diagrams"
            };

            //fixedDocument.DocumentPaginator.PageSize = new Size(areaExtent.Width, areaExtent.Height);

            SetElementResources(fixedDocument.Resources, fixedStrokeThickness);

            foreach (var diagram in diagrams)
            {
                var pageContent = new PageContent();
                var fixedPage   = new FixedPage();

                //pageContent.Child = fixedPage;
                ((IAddChild)pageContent).AddChild(fixedPage);

                fixedDocument.Pages.Add(pageContent);

                fixedPage.Width  = areaExtent.Width;
                fixedPage.Height = areaExtent.Height;

                var element = CreateDiagramElement(diagram,
                                                   areaExtent,
                                                   origin,
                                                   area,
                                                   fixedStrokeThickness,
                                                   fixedDocument.Resources,
                                                   table);

                // transform and scale for print
                element.LayoutTransform = new ScaleTransform(scale, scale);

                // set element position
                FixedPage.SetLeft(element, areaOrigin.Width);
                FixedPage.SetTop(element, areaOrigin.Height);

                // add element to page
                fixedPage.Children.Add(element);

                // update fixed page layout
                //fixedPage.Measure(areaExtent);
                //fixedPage.Arrange(area);
            }

            return(fixedDocument);
        }
Esempio n. 14
0
        /// <summary>
        /// Sizes the given bitmap to the page size and returns it as part
        /// of a printable page.
        /// </summary>
        /// <param name="bmp">
        /// The bitmap to search through for a breakpoint.
        /// </param>
        /// <param name="top">
        /// The top row to print with.
        /// </param>
        /// <param name="bottom">
        /// The bottom row to print with.
        /// </param>
        /// <param name="pageWidth">
        /// The available width of the page to print.
        /// </param>
        /// <param name="PageHeight">
        /// The available height of the page to print.
        /// </param>
        /// <param name="capabilities">
        /// The possible printing features.
        /// </param>
        private static PageContent GeneratePageContent(
            System.Drawing.Bitmap bmp,
            int top,
            int bottom,
            double pageWidth,
            double PageHeight,
            System.Printing.PrintCapabilities capabilities)
        {
            Image        pageImage;
            BitmapSource bmpSource;

            //Creates a page with a specific width/height.
            FixedPage printPage = new FixedPage();

            printPage.Width  = pageWidth;
            printPage.Height = PageHeight;

            //Cuts the given image at a reasonable boundary.
            int newImageHeight = bottom - top;

            //Creates a clone of the image.
            using (System.Drawing.Bitmap bmpCut =
                       bmp.Clone(new System.Drawing.Rectangle(0, top, bmp.Width, newImageHeight),
                                 bmp.PixelFormat))
            {
                //Prepares the bitmap source.
                pageImage = new Image();
                bmpSource =
                    System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                        bmpCut.GetHbitmap(),
                        IntPtr.Zero,
                        Int32Rect.Empty,
                        BitmapSizeOptions.FromWidthAndHeight(bmpCut.Width, bmpCut.Height));
            }

            //Adds the bitmap to the page.
            pageImage.Source            = bmpSource;
            pageImage.VerticalAlignment = VerticalAlignment.Top;
            printPage.Children.Add(pageImage);

            PageContent pageContent = new PageContent();

            ((System.Windows.Markup.IAddChild)pageContent).AddChild(printPage);

            //Adds a margin.
            printPage.Margin = new Thickness(
                horzBorder, vertBorder,
                horzBorder, vertBorder);

            FixedPage.SetLeft(pageImage, capabilities.PageImageableArea.OriginWidth);
            FixedPage.SetTop(pageImage, capabilities.PageImageableArea.OriginHeight);

            //Adjusts for the margins and to fit the page.
            pageImage.Width  = capabilities.PageImageableArea.ExtentWidth - horzBorder * 2;
            pageImage.Height = capabilities.PageImageableArea.ExtentHeight - vertBorder * 2;
            return(pageContent);
        }
Esempio n. 15
0
        private static void eventualiStampigli(FixedPage page1, LavoroDiStampaFoto lavoroDiStampa)
        {
            SolidColorBrush coloreFg = new SolidColorBrush(Colors.Black);
            SolidColorBrush coloreBg = new SolidColorBrush(Colors.White);

            int stampigliMarginBotton = Configurazione.UserConfigLumen.stampigliMarginBottom;
            int stampigliMarginTop    = Configurazione.UserConfigLumen.stampigliMarginBottom;
            int stampigliMarginRight  = Configurazione.UserConfigLumen.stampigliMarginRight;
            int stampigliMarginLeft   = Configurazione.UserConfigLumen.stampigliMarginRight;


            // Prima era 30 poi 16 poi l'ho reso esterno
            int fontSize = Configurazione.UserConfigLumen.fontSizeStampaFoto;

            if (fontSize <= 0)
            {
                fontSize = 14;                 // Default
            }
            // Numero della foto
            if (lavoroDiStampa.param.stampigli.numFoto)
            {
                TextBlock textNumero = new TextBlock();
                textNumero.Text       = lavoroDiStampa.fotografia.etichetta;
                textNumero.FontSize   = fontSize;               // 30pt text
                textNumero.Foreground = coloreFg;
                textNumero.Background = coloreBg;
                FixedPage.SetBottom(textNumero, stampigliMarginBotton);
                FixedPage.SetRight(textNumero, stampigliMarginRight);
                page1.Children.Add(textNumero);
            }

            // Giornata
            if (lavoroDiStampa.param.stampigli.giornata)
            {
                TextBlock textGiorno = new TextBlock();
                textGiorno.Text       = lavoroDiStampa.fotografia.giornata.ToString("d");
                textGiorno.FontSize   = fontSize;               // 30pt text
                textGiorno.Foreground = coloreFg;
                textGiorno.Background = coloreBg;
                FixedPage.SetBottom(textGiorno, stampigliMarginBotton);
                FixedPage.SetLeft(textGiorno, stampigliMarginLeft);
                page1.Children.Add(textGiorno);
            }

            // Operatore
            if (lavoroDiStampa.param.stampigli.operatore)
            {
                TextBlock textOperatore = new TextBlock();
                textOperatore.Text       = lavoroDiStampa.fotografia.fotografo.iniziali;
                textOperatore.FontSize   = fontSize;               // 30pt text
                textOperatore.Foreground = coloreFg;
                textOperatore.Background = coloreBg;
                FixedPage.SetTop(textOperatore, stampigliMarginTop);
                FixedPage.SetRight(textOperatore, stampigliMarginRight);
                page1.Children.Add(textOperatore);
            }
        }
Esempio n. 16
0
 /// <summary>
 /// Vertikale Linie
 /// </summary>
 /// <param name="Page"></param>
 /// <param name="Top"></param>
 /// <param name="Left"></param>
 /// <param name="Height"></param>
 protected void AddVerticalLine(FixedPage Page, double Top, double Left, double Height)
 {
     System.Windows.Controls.Border b = new Border();
     b.BorderThickness = new Thickness(1);
     b.BorderBrush     = Brushes.Black;
     b.Height          = Height * 96 / 2.54;
     b.Width           = 1;
     FixedPage.SetLeft(b, 96 * Left / 2.54); // left margin
     FixedPage.SetTop(b, 96 / 2.54 * Top);   // top margin
     Page.Children.Add((UIElement)b);
 }
Esempio n. 17
0
        private static Rectangle CreateContentRectangle(Brush vb, Rect rect)
        {
            var rc = new Rectangle {
                Width = rect.Width, Height = rect.Height, Fill = vb
            };

            FixedPage.SetLeft(rc, rect.X);
            FixedPage.SetTop(rc, rect.Y);
            FixedPage.SetRight(rc, rect.Width);
            FixedPage.SetBottom(rc, rect.Height);
            return(rc);
        }
Esempio n. 18
0
        public FixedDocument CreateFixedDocument(IEnumerable <IRenderable> renderables)
        {
            Size pageSize    = new Size(pageConfig.PageWidth, pageConfig.PageHeight);
            Size visibleSize = new Size(pageConfig.ExtentWidth, pageConfig.ExtentHeight);

            Document document = new Document();

            document.PageSize = visibleSize;

            var pageCanvas = document.CreatePage().PageCanvas;

            foreach (var item in renderables)
            {
                if (!pageCanvas.AddItem(item))
                {
                    pageCanvas = document.CreatePage().PageCanvas;
                    if (!pageCanvas.AddItem(item))
                    {
                        break;
                    }
                }
            }

            for (int i = 0; i < document.PageCount; i++)
            {
                document.GetPage(i).PageCanvas.InvalidateVisual();
            }

            FixedDocument fixedDoc = new FixedDocument();

            for (int i = 0; i < document.PageCount; i++)
            {
                var pp     = document.GetPage(i);
                var canvas = pp.PageCanvas;

                PageContent pageContent = new PageContent();
                FixedPage   page        = new FixedPage();
                ((IAddChild)pageContent).AddChild(page);
                fixedDoc.Pages.Add(pageContent);
                page.Width  = pageSize.Width;
                page.Height = pageSize.Height;

                FixedPage.SetLeft(canvas, pageConfig.OriginWidth);
                FixedPage.SetTop(canvas, pageConfig.OriginHeight);

                canvas.Width  = visibleSize.Width;
                canvas.Height = visibleSize.Height;

                page.Children.Add(canvas);
            }

            return(fixedDoc);
        }
Esempio n. 19
0
        private UIElement GetHeaderContent()
        {
            var text1 = new TextBlock();

            text1.FontFamily          = new FontFamily("Mangal");
            text1.FontSize            = 34;
            text1.HorizontalAlignment = HorizontalAlignment.Center;
            text1.Inlines.Add(new Bold(new Run("cn|elements")));
            FixedPage.SetLeft(text1, 170);
            FixedPage.SetTop(text1, 40);
            return(text1);
        }
 void CreatePageInternal(FixedPage page, ExporterCollection items)
 {
     foreach (var element in items)
     {
         var item = ItemFactory(element);
         if (item != null)
         {
             FixedPage.SetLeft(item, element.StyleDecorator.Location.X);
             FixedPage.SetTop(item, element.StyleDecorator.Location.Y);
             page.Children.Add(item);
         }
     }
 }
Esempio n. 21
0
        private UIElement GetLogoContent()
        {
            var ellipse = new Ellipse
            {
                Width  = 90,
                Height = 40,
                Fill   = new RadialGradientBrush(Colors.Yellow, Colors.DarkRed)
            };

            FixedPage.SetLeft(ellipse, 600);
            FixedPage.SetTop(ellipse, 50);
            return(ellipse);
        }
Esempio n. 22
0
        /// <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);
        }
Esempio n. 23
0
        internal void SetPagePanelToDocument(StackPanel panel)
        {
            var newPage = GetNewPage(document.DocumentPaginator.PageSize);

            //Wenn die aktuelle Höhe + die neue Höhe > seiten-Höhe
            FixedPage.SetTop(panel, PixelConverter.CmToPx(1));
            FixedPage.SetLeft(panel, PixelConverter.CmToPx(0.7));
            newPage.Children.Add(panel);

            PageContent content = new PageContent();

            ((IAddChild)content).AddChild(newPage);
            document.Pages.Add(content);
        }
Esempio n. 24
0
        private static UIElement GetHeaderContent()
        {
            var text1 = new TextBlock
            {
                FontFamily          = new FontFamily("Segoe UI"),
                FontSize            = 34,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            text1.Inlines.Add(new Bold(new Run("cn|elements")));
            FixedPage.SetLeft(text1, 170);
            FixedPage.SetTop(text1, 40);
            return(text1);
        }
Esempio n. 25
0
        private UIElement GetMenuContent()
        {
            var grid1 = new Grid {
                ShowGridLines = true
            };

            grid1.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(50)
            });
            grid1.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(520)
            });
            grid1.ColumnDefinitions.Add(new ColumnDefinition {
                Width = new GridLength(50)
            });

            for (int i = 0; i < menus.Count; i++)
            {
                grid1.RowDefinitions.Add(new RowDefinition {
                    Height = new GridLength(40)
                });

                var t1 = new TextBlock(
                    new Run(String.Format("{0:ddd}", menus[i].Day)));
                t1.VerticalAlignment = VerticalAlignment.Center;
                t1.Margin            = new Thickness(5, 2, 5, 2);
                Grid.SetColumn(t1, 0);
                Grid.SetRow(t1, i);
                grid1.Children.Add(t1);

                var t2 = new TextBlock(new Run(menus[i].Menu));
                t2.VerticalAlignment = VerticalAlignment.Center;
                t2.Margin            = new Thickness(5, 2, 5, 2);
                Grid.SetColumn(t2, 1);
                Grid.SetRow(t2, i);
                grid1.Children.Add(t2);

                var t3 = new TextBlock(new Run(menus[i].Price.ToString()));
                t3.VerticalAlignment = VerticalAlignment.Center;
                t3.Margin            = new Thickness(5, 2, 5, 2);
                Grid.SetColumn(t3, 2);
                Grid.SetRow(t3, i);
                grid1.Children.Add(t3);
            }

            FixedPage.SetLeft(grid1, 100);
            FixedPage.SetTop(grid1, 140);
            return(grid1);
        }
Esempio n. 26
0
        private UIElement GetDateContent()
        {
            var dateString = $"{_menus[0].Day:d} to {_menus[_menus.Count - 1].Day:d}";
            var text1      = new TextBlock
            {
                FontSize            = 24,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            text1.Inlines.Add(new Bold(new Run(dateString)));
            FixedPage.SetLeft(text1, 130);
            FixedPage.SetTop(text1, 90);

            return(text1);
        }
Esempio n. 27
0
        private UIElement GetDateContent()
        {
            string dateString = String.Format("{0:d} to {1:d}",
                                              menus[0].Day, menus[menus.Count - 1].Day);
            var text1 = new TextBlock
            {
                FontSize            = 24,
                HorizontalAlignment = HorizontalAlignment.Center
            };

            text1.Inlines.Add(new Bold(new Run(dateString)));
            FixedPage.SetLeft(text1, 130);
            FixedPage.SetTop(text1, 90);
            return(text1);
        }
Esempio n. 28
0
        private static PageContent GeneratePageContent(System.Drawing.Bitmap bmp, int top, int bottom, double pageWidth, double PageHeight, Size pageSize, double left)
        {
            FixedPage printDocumentPage = new FixedPage();

            printDocumentPage.Width = pageWidth;

            printDocumentPage.Height = PageHeight;

            int newImageHeight = bottom - top;

            System.Drawing.Bitmap bmpPage = bmp.Clone(new System.Drawing.Rectangle(0, top, bmp.Width, newImageHeight), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            // Create a new bitmap for the contents of this page

            Image        pageImage = new Image();
            var          ptr       = bmpPage.GetHbitmap();
            BitmapSource bmpSource =
                System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
                    ptr,
                    IntPtr.Zero,
                    System.Windows.Int32Rect.Empty,
                    BitmapSizeOptions.FromWidthAndHeight(bmp.Width, newImageHeight));

            bmpSource.Freeze();
            bool res = PrintHelper.DeleteObject(ptr);

            pageImage.Source = bmpSource;

            pageImage.Width = pageSize.Width;

            pageImage.Height              = pageSize.Height;
            pageImage.VerticalAlignment   = VerticalAlignment.Top;
            pageImage.HorizontalAlignment = HorizontalAlignment.Center;

            // Place the bitmap on the page

            FixedPage.SetLeft(pageImage, left);

            FixedPage.SetTop(pageImage, 35);

            printDocumentPage.Children.Add(pageImage);
            PageContent pageContent = new PageContent();

            ((System.Windows.Markup.IAddChild)pageContent).AddChild(printDocumentPage);



            return(pageContent);
        }
Esempio n. 29
0
        public static FixedDocument GetFixedDocument(FrameworkElement toPrint, PrintDialog printDialog, Thickness margin)
        {
            PrintCapabilities capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);

            printDialog.PrintTicket.PageOrientation = PageOrientation.Landscape;
            Size pageSize = new Size(printDialog.PrintableAreaWidth, printDialog.PrintableAreaHeight);
            //Size pageSize = new Size(toPrint.ActualWidth, toPrint.ActualHeight);
            //Size visibleSize = new Size(capabilities.PageImageableArea.ExtentWidth - margin.Left - margin.Right, capabilities.PageImageableArea.ExtentHeight - margin.Top - margin.Bottom);
            Size          visibleSize = new Size(toPrint.ActualWidth, toPrint.ActualHeight);
            FixedDocument fixedDoc    = new FixedDocument();

            //If the toPrint visual is not displayed on screen we neeed to measure and arrange it
            toPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            toPrint.Arrange(new Rect(new Point(0, 0), toPrint.DesiredSize));
            //
            Size size = toPrint.DesiredSize;
            //Will assume for simplicity the control fits horizontally on the page
            double yOffset = 0;

            while (yOffset < size.Height)
            {
                VisualBrush vb = new VisualBrush(toPrint);
                vb.Stretch      = Stretch.None;
                vb.AlignmentX   = AlignmentX.Left;
                vb.AlignmentY   = AlignmentY.Top;
                vb.ViewboxUnits = BrushMappingMode.Absolute;
                vb.TileMode     = TileMode.None;
                vb.Viewbox      = new Rect(0, yOffset, visibleSize.Width, visibleSize.Height);

                PageContent pageContent = new PageContent();
                FixedPage   page        = new FixedPage();
                ((IAddChild)pageContent).AddChild(page);
                fixedDoc.Pages.Add(pageContent);
                page.Width  = pageSize.Width;
                page.Height = pageSize.Height;
                Canvas canvas = new Canvas();
                FixedPage.SetLeft(canvas, capabilities.PageImageableArea.OriginWidth);
                FixedPage.SetTop(canvas, capabilities.PageImageableArea.OriginHeight);
                canvas.Width      = visibleSize.Width;
                canvas.Height     = visibleSize.Height;
                canvas.Background = vb;
                canvas.Margin     = margin;

                page.Children.Add(canvas);
                yOffset += visibleSize.Height;
            }
            return(fixedDoc);
        }
Esempio n. 30
0
        /// <summary>
        /// This will create a valid Xps FixedPage.
        /// </summary>
        /// <param name="canvas">The Canvas to include in the page.</param>
        /// <param name="name">The name of the page.</param>
        /// <returns>A valid Xps FixedPage.</returns>
        private static FixedPage CreateFixedPage(Canvas canvas, string name)
        {
            FixedPage page = new FixedPage();

            FixedPage.SetLeft(canvas, 0);
            FixedPage.SetTop(canvas, 0);

            page.Width  = canvas.Width;
            page.Height = canvas.Height;

            page.Name = name;

            page.Children.Add(canvas);

            return(page);
        }