Beispiel #1
0
        private void PrintPanel(Panel panelToPrint, string description, PrintDialog printDialog, double customScale)
        {
            double scale;
            Rect   printableArea;

            System.Printing.PrintCapabilities capabilities;
            List <UIElement> uiElementsToPrint;

            FixedDocument myDocument;
            PageContent   pageContent;
            StackPanel    pageStackPanel;

            UIElement oneChild = null;
            double    childHeight;

            double currentPageContentHeight;
            int    pageNumber;



            capabilities = printDialog.PrintQueue.GetPrintCapabilities(printDialog.PrintTicket);

            printableArea = new Rect(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight,
                                     capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);


            if (panelToPrint.DesiredSize.Width > printableArea.Width)
            {
                scale = printableArea.Width / panelToPrint.DesiredSize.Width;
            }
            else
            {
                scale = 1.0;
            }

            if (customScale > 0 && customScale < scale)
            {
                scale = customScale;
            }

            // This does not work, because child elements that do not fit on the page are moved to the next page - this make the total height bigger than panelToPrint.DesiredSize.Height
            //if (fitToPagesCount > 0)
            //{
            //    double scale2;

            //    if (panelToPrint.DesiredSize.Height > printableArea.Height * fitToPagesCount)
            //    {
            //        scale2 = (printableArea.Height * fitToPagesCount) / panelToPrint.DesiredSize.Height;

            //        if (scale2 < scale)
            //            scale = scale2;
            //    }
            //}



            if (panelToPrint.DesiredSize.IsEmpty)
            {
                // If not measured and arranged yet, do it now
                panelToPrint.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
                panelToPrint.Arrange(new Rect(new Point(0, 0), panelToPrint.DesiredSize));
            }



            // First disconnect the elements to print and collect them in uiElementsToPrint (in reverse order)
            uiElementsToPrint = new List <UIElement>();

            for (int i = panelToPrint.Children.Count - 1; i >= 0; i--)
            {
                oneChild = panelToPrint.Children[i];

                panelToPrint.Children.Remove(oneChild);
                uiElementsToPrint.Add(oneChild);
            }


            // Initialize
            currentPageContentHeight = 0;
            pageNumber = 0;

            myDocument     = new FixedDocument();
            pageContent    = null;
            pageStackPanel = null;

            childHeight = 0;

            FixedPage page = null;

            oneChild = null;                                                                                    // So it will not be added

            for (int i = uiElementsToPrint.Count - 1; i >= 0 || (pageContent == null && oneChild != null); i--) // !!! if (pageContent == null && oneChild != null) than we need to add new page and oneChild to it
            {
                if (pageContent == null)
                {
                    // Create new page
                    pageStackPanel             = new StackPanel();
                    pageStackPanel.Orientation = Orientation.Vertical;
                    pageStackPanel.Margin      = new Thickness(printableArea.X + 5, printableArea.Y + 5, printableArea.X + 5, printableArea.Y + 5);

                    page        = new FixedPage();
                    page.Width  = printDialog.PrintableAreaWidth;
                    page.Height = printDialog.PrintableAreaHeight;

                    page.Children.Add(pageStackPanel); // pageStackPanel will hold the controls to print

                    pageContent = new PageContent();
                    ((System.Windows.Markup.IAddChild)pageContent).AddChild(page); // Child must be FixedPage

                    // Check if we need to scale to show the whole width
                    if (scale != 1.0)
                    {
                        pageStackPanel.LayoutTransform = new ScaleTransform(scale, scale);
                    }

                    currentPageContentHeight = 0;
                    pageNumber++;


                    if (oneChild != null)
                    {
                        // Add the child from previous loop pass

                        // Check if the child is too bit to go to one page - in this case scale the child to fit onto the page
                        if (childHeight > printableArea.Height)
                        {
                            double childScale;

                            childScale = printableArea.Height / childHeight;
                            oneChild.RenderTransform = new ScaleTransform(childScale, childScale);

                            childHeight *= childScale;
                        }

                        pageStackPanel.Children.Add(oneChild);
                        currentPageContentHeight += childHeight;
                    }
                }

                if (i < 0) // handle the case where we continued the loop to add the last element to the new page -> the new page with the last element is now created so we can break the loop
                {
                    break;
                }

                // Get the element
                oneChild = uiElementsToPrint[i];

                childHeight = oneChild.DesiredSize.Height * scale;


                if (currentPageContentHeight + childHeight > printableArea.Height)
                {
                    // The height with the oneChild would exceed the printable height
                    // So add the current page to the document, create a new page and add oneChild to the new page
                    myDocument.Pages.Add(pageContent);

                    pageContent = null; // this will create a new page
                }
                else
                {
                    // There is still room for oneChild

                    // And add it to new parent
                    pageStackPanel.Children.Add(oneChild);

                    currentPageContentHeight += childHeight;
                }
            }


            // Add last page (if it was not already added)
            if (pageContent != null)
            {
                myDocument.Pages.Add(pageContent);
            }

            printDialog.PrintDocument(myDocument.DocumentPaginator, description);



            for (int i = uiElementsToPrint.Count - 1; i >= 0; i--)
            {
                oneChild = uiElementsToPrint[i];

                StackPanel parent = VisualTreeHelper.GetParent(oneChild) as StackPanel;

                if (parent != null)
                {
                    parent.Children.Remove(oneChild);
                }

                panelToPrint.Children.Add(oneChild);
            }
        }
Beispiel #2
0
        private static void LayoutPage(ref List <ScrabbleSolution> .Enumerator it, FixedPage page, double?fontSize)
        {
            double marginX = 48;
            double marginY = 48;
            var    sz      = new Size(8.5 * 96 - 2 * marginX, 11 * 96 - 2 * marginY);

            // This is how we know we are done.
            // No more pages to layout if there
            // aren't any more solutions to show
            if (it.Current == null)
            {
                return;
            }

            //Do Page Header
            var headerTextBlock = new TextBlock
            {
                Text     = "Scrabble Generator Solutions",
                FontSize = 25
            };

            headerTextBlock.Measure(sz);

            FixedPage.SetLeft(headerTextBlock, sz.Width / 2 - headerTextBlock.DesiredSize.Width / 2); // Center the Header
            FixedPage.SetTop(headerTextBlock, 48);                                                    // Put it at 1/2 inch down

            page.Children.Add(headerTextBlock);

            var separator = new Separator
            {
                Width  = sz.Width,
                Height = 5
            };

            separator.Measure(sz);

            FixedPage.SetLeft(separator, marginX);
            FixedPage.SetTop(separator, marginY + headerTextBlock.DesiredSize.Height);

            page.Children.Add(separator);

            double x        = marginX;
            double y        = marginY + headerTextBlock.DesiredSize.Height + separator.DesiredSize.Height;
            double largestY = 0;

            do
            {
                var ctl = new ScrabbleSolutionControl
                {
                    ScrabbleSolution = it.Current,
                    Margin           = new Thickness(10),
                };

                if (fontSize.HasValue)
                {
                    ctl.FontSize = fontSize.Value;
                }

                ctl.Measure(sz);

                // Page starts with two controls (Heading & separator.. Count==2).
                // If we haven't placed a Scrabble Solution (i.e Count==2), and the current
                // solution is too damn big to fit, lets keep shrinking the fontsize
                // by one until the solution fits!  Yes, it will be one solution per page,
                // but the good news is that we will manage to print every solution for
                // the user, as close to as big as they wanted as possible.
                if (page.Children.Count == 2)
                {
                    var newFontSize = ctl.FontSize;

                    while (ctl.DesiredSize.Width > sz.Width - 2 * marginX || ctl.DesiredSize.Height > sz.Height - marginY)
                    {
                        ctl.FontSize = newFontSize--;

                        ctl.Measure(sz);
                    }
                }

                // When we run out of X space, we move down and start over in the x direction
                if (x + ctl.DesiredSize.Width > page.Width - 2 * marginX)
                {
                    x        = marginX;
                    y       += largestY;
                    largestY = 0;
                }

                // When we run out of Y space, the page is full.
                if (y + ctl.DesiredSize.Height > page.Height - marginY)
                {
                    break;
                }

                FixedPage.SetLeft(ctl, x);
                FixedPage.SetTop(ctl, y);
                page.Children.Add(ctl);

                x += ctl.DesiredSize.Width;

                largestY = Math.Max(largestY, ctl.DesiredSize.Height);
            }while(it.MoveNext() == true);
        }
 /// <summary>
 /// Write a single FixedPage and close package
 /// </summary>
 public override void Write(FixedPage fixedPage)
 {
     Write(fixedPage, null);
 }
 /// <summary>
 /// Asynchronous Write a single FixedPage and close package
 /// </summary>
 public override void WriteAsync(FixedPage fixedPage)
 {
     throw new NotSupportedException();
 }
        public override FixedDocument CreateFixedDocument()
        {
            FixedDocument fd = new FixedDocument();

            ReportProgressUpdate updateFunc = GetProgressUpdateFunc();
            ReportStatusUpdate   doneFunc   = GetProgressDoneFunc();

            fd.DocumentPaginator.PageSize = PageSize;

            if (doneFunc != null)
            {
                doneFunc(false, false);
            }

            Parameter.SetFieldValue("DOCUMENT_TYPE", ((int)CashDocumentType.CashDocExport).ToString());
            ArrayList arr = OnixWebServiceAPI.GetCashDocList(Parameter);

            if (arr == null)
            {
                return(fd);
            }

            int         cnt  = arr.Count;
            UReportPage area = null;

            createRowTemplates();
            int i = 0;

            Size areaSize = GetAreaSize();

            AvailableSpace = areaSize.Height;

            CReportDataProcessingProperty property = null;

            while (i < arr.Count)
            {
                CTable o = (CTable)arr[i];

                if ((i == 0) || (property.IsNewPageRequired))
                {
                    AvailableSpace = areaSize.Height;

                    CurrentPage++;

                    FixedPage fp = new FixedPage();
                    fp.Margin = Margin;

                    PageContent pageContent = new PageContent();
                    ((System.Windows.Markup.IAddChild)pageContent).AddChild(fp);

                    fd.Pages.Add(pageContent);
                    area = initNewArea(areaSize);

                    pages.Add(area);
                    fp.Children.Add(area);
                }

                property = DataToProcessingProperty(o, arr, i);
                if (property.IsNewPageRequired)
                {
                    //Do not create row if that row caused new page flow
                    //But create it in the next page instead
                    i--;
                }
                else
                {
                    ConstructUIRows(area, property);
                }

                if (updateFunc != null)
                {
                    updateFunc(i, cnt);
                }

                i++;
            }

            if (doneFunc != null)
            {
                doneFunc(true, false);
            }

            keepFixedDoc = fd;
            return(fd);
        }
Beispiel #6
0
        internal static FixedPage GetPageRoot(object page)
        {
            FixedPage fixedPage = ((PageContent)page).GetPageRoot(false) as FixedPage;

            return(fixedPage);
        }
        /// <summary>
        /// Parses a FixedPage element.
        /// </summary>
        FixedPage ParseFixedPage()
        {
            Debug.Assert(this.reader.Name == "FixedPage");
            FixedPage fpage = new FixedPage();

            try
            {
                bool isEmptyElement = this.reader.IsEmptyElement;
                Debug.Assert(this.fpage == null);
                this.fpage = fpage;
                while (this.reader.MoveToNextAttribute())
                {
                    switch (this.reader.Name)
                    {
                    case "Name":
                        fpage.Name = this.reader.Value;
                        break;

                    case "Width":
                        fpage.Width = ParseDouble(this.reader.Value);
                        break;

                    case "Height":
                        fpage.Height = ParseDouble(this.reader.Value);
                        break;

                    case "ContentBox":
                        fpage.ContentBox = Rect.Parse(this.reader.Value);
                        break;

                    case "BleedBox":
                        fpage.BleedBox = Rect.Parse(this.reader.Value);
                        break;

                    case "xmlns":
                        break;

                    case "xmlns:xps":
                        break;

                    case "xmlns:false":
                        break;

                    case "xmlns:mc":
                        break;

                    case "xmlns:x":
                        break;

                    case "xmlns:xml":
                        break;

                    case "xmlns:xsi":
                        break;

                    case "xmlns:v2":
                        break;

                    case "xml:lang":
                        fpage.Lang = this.reader.Value;
                        break;

                    case "xml:space":
                        break;

                    case "xsi:schemaLocation":
                        break;

                    case "mc:MustUnderstand":
                        break;

                    default:
                        UnexpectedAttribute(this.reader.Name);
                        break;
                    }
                }
                if (!isEmptyElement)
                {
                    MoveToNextElement();
                    while (this.reader.IsStartElement())
                    {
                        XpsElement element = null;
                        switch (reader.Name)
                        {
                        case "Path":
                            element = ParsePath();
                            fpage.Content.Add(element);
                            element.Parent = fpage;
                            break;

                        case "Canvas":
                            element = ParseCanvas();
                            fpage.Content.Add(element);
                            element.Parent = fpage;
                            break;

                        case "Glyphs":
                            element = ParseGlyphs();
                            fpage.Content.Add(element);
                            element.Parent = fpage;
                            break;

                        case "MatrixTransform":
                            Debugger.Break();
                            ParseMatrixTransform();
                            //fpage.
                            //element = ParseGlyphs();
                            //fpage.Content.Add(element);
                            break;

                        case "FixedPage.Resources":
                            MoveToNextElement();
                            ResourceDictionary rd = new ResourceDictionary();
                            fpage.Resources   = rd;
                            rd.Parent         = fpage;
                            rd.ResourceParent = ResourceDictionaryStack.Current;
                            ResourceDictionaryStack.Push(rd);
                            ParseResourceDictionary(rd);
                            MoveToNextElement();
                            break;

                        case "mc:AlternateContent":
                            MoveToNextElement();
                            break;

                        case "mc:Choice":
                            MoveToNextElement();
                            break;

                        case "v2:Circle":
                            MoveToNextElement();
                            break;

                        case "v2:Watermark":
                            MoveToNextElement();
                            break;

                        case "v2:Blink":
                            MoveToNextElement();
                            break;

                        default:
                            Debugger.Break();
                            break;
                        }
                    }
                }
                MoveToNextElement();
            }
            finally
            {
                // If the current ResourceDictionary is from this FixedPage, pop it.
                if (fpage != null && fpage.Resources != null)
                {
                    if (Object.ReferenceEquals(fpage.Resources, ResourceDictionaryStack.Current))
                    {
                        ResourceDictionaryStack.Pop();
                    }
                }
            }
            return(fpage);
        }
Beispiel #8
0
 public override void WriteAsync(FixedPage fixedPage);
 /// <summary>
 /// Write a single FixedPage and close package
 /// </summary>
 public override void Write(FixedPage fixedPage, PrintTicket printTicket)
 {
     SerializeVisualTree(fixedPage);
     _writer.Close();
 }
Beispiel #10
0
        }// end:CreateSecondPageContent()

        // --------------------- CreateThirdPageContent -----------------------
        /// <summary>
        ///   Creates the content for the third fixed page.</summary>
        /// <returns>
        ///   The page content for the third fixed page.</returns>
        public PageContent CreateThirdPageContent()
        {
            PageContent pageContent = new PageContent();
            FixedPage   fixedPage   = new FixedPage();

            fixedPage.Background = Brushes.White;
            Canvas canvas1 = new Canvas();

            canvas1.Width  = 8.5 * 96;
            canvas1.Height = 11 * 96;

            // Top-Left
            TextBlock label = new TextBlock();

            label.Foreground = Brushes.Black;
            label.FontFamily = new System.Windows.Media.FontFamily("Arial");
            label.FontSize   = 14.0;
            label.Text       = String1;
            Canvas.SetTop(label, 0);
            Canvas.SetLeft(label, 0);
            canvas1.Children.Add(label);

            label            = new TextBlock();
            label.Foreground = Brushes.Black;
            label.FontFamily = new System.Windows.Media.FontFamily("Arial");
            label.FontSize   = 14.0;
            label.Text       = String2;
            Canvas.SetTop(label, 20);
            Canvas.SetLeft(label, 0);
            canvas1.Children.Add(label);

            label            = new TextBlock();
            label.Foreground = Brushes.Black;
            label.FontFamily = new System.Windows.Media.FontFamily("Arial");
            label.FontSize   = 14.0;
            label.Text       = String3;
            Canvas.SetTop(label, 40);
            Canvas.SetLeft(label, 0);
            canvas1.Children.Add(label);

            label            = new TextBlock();
            label.Foreground = Brushes.Black;
            label.FontFamily = new System.Windows.Media.FontFamily("Arial");
            label.FontSize   = 14.0;
            label.Text       = String4;
            Canvas.SetTop(label, 60);
            Canvas.SetLeft(label, 0);
            canvas1.Children.Add(label);

            label            = new TextBlock();
            label.Foreground = Brushes.Black;
            label.FontFamily = new System.Windows.Media.FontFamily("Arial");
            label.FontSize   = 14.0;
            label.Text       = String5;
            Canvas.SetTop(label, 80);
            Canvas.SetLeft(label, 0);
            canvas1.Children.Add(label);

            fixedPage.Children.Add(canvas1);

            double pageWidth  = 96 * 8.5;
            double pageHeight = 96 * 11;

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

            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:CreateThirdPageContent()
Beispiel #11
0
 public override void WriteAsync(FixedPage fixedPage, PrintTicket printTicket, object userSuppliedState);
Beispiel #12
0
 public override void WriteAsync(FixedPage fixedPage, PrintTicket printTicket);
Beispiel #13
0
 public override void WriteAsync(FixedPage fixedPage, object userSuppliedState);
 static void SetPosition(UIElement element, IExportColumn exportColumn)
 {
     FixedPage.SetLeft(element, exportColumn.Location.X);
     FixedPage.SetTop(element, exportColumn.Location.Y);
 }
Beispiel #15
0
        /// <summary>
        /// A first hack to do the job...
        /// </summary>
        public static void RenderPage_Test01(PdfPage page, string xpsFilename)
        {
            //XpsDocument xpsdoc = new XpsDocument(xpsFilename, System.IO.FileAccess.Read);
            //FixedDocument fds = xpsdoc.GetFixedDocument();
            //DocumentReferenceCollection docrefs = fds.References;
            //DocumentReference docref = docrefs[0];
            //Uri uri1 = docref.Source;
            //FixedDocument fixeddoc = docref.GetDocument(false);
            //PageContent content = fixeddoc.Pages[0];
            //Uri uri2 = content.Source;
            //FixedPage fixedPage = content.Child;
            //xpsdoc.Close();
            // /Documents/1/Pages/1.fpage

            try
            {
#if true
                XpsDocument doc   = XpsDocument.Open(xpsFilename);
                FixedPage   fpage = doc.GetDocument().GetFixedPage(0);

                //ZipPackage pack = ZipPackage.Open(xpsFilename) as ZipPackage;
                Uri            uri  = new Uri("/Documents/1/Pages/1.fpage", UriKind.Relative);
                ZipPackagePart part = doc.Package.GetPart(uri) as ZipPackagePart;
                using (Stream stream = part.GetStream())
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        string xml = sr.ReadToEnd();
#if true
                        string xmlPath = IOPath.Combine(IOPath.GetDirectoryName(xpsFilename), IOPath.GetFileNameWithoutExtension(xpsFilename)) + ".xml";
                        using (StreamWriter sw = new StreamWriter(xmlPath))
                        {
                            sw.Write(xml);
                        }
#endif
                        DocumentRenderingContext context = new DocumentRenderingContext(page.Owner);
                        //XpsElement el = PdfSharp.Xps.Parsing.XpsParser.Parse(xml);
                        PdfRenderer renderer = new PdfRenderer();
                        renderer.RenderPage(page, fpage);
                    }
                }
#else
                ZipPackage     pack = ZipPackage.Open(xpsFilename) as ZipPackage;
                Uri            uri  = new Uri("/Documents/1/Pages/1.fpage", UriKind.Relative);
                ZipPackagePart part = pack.GetPart(uri) as ZipPackagePart;
                using (Stream stream = part.GetStream())
                {
                    using (StreamReader sr = new StreamReader(stream))
                    {
                        string xml = sr.ReadToEnd();
#if true
                        string xmlPath = IOPath.Combine(IOPath.GetDirectoryName(xpsFilename), IOPath.GetFileNameWithoutExtension(xpsFilename)) + ".xml";
                        using (StreamWriter sw = new StreamWriter(xmlPath))
                        {
                            sw.Write(xml);
                        }
#endif
                        XpsElement  el       = PdfSharp.Xps.Parsing.XpsParser.Parse(xml);
                        PdfRenderer renderer = new PdfRenderer();
                        renderer.RenderPage(page, el as PdfSharp.Xps.XpsModel.FixedPage);
                    }
                }
#endif
            }
            catch
            {
                //DaSt :
            }
        }
 public static IObservable <EventPattern <MouseButtonEventArgs> > PreviewMouseLeftButtonUpObserver(this FixedPage This)
 {
     return(Observable.FromEventPattern <MouseButtonEventHandler, MouseButtonEventArgs>(h => This.PreviewMouseLeftButtonUp += h, h => This.PreviewMouseLeftButtonUp -= h));
 }
Beispiel #17
0
        /// <summary>
        ///
        /// </summary>
        public static void Parser_Test01(string xpsFilename)
        {
            //XpsDocument xpsdoc = new XpsDocument(xpsFilename, System.IO.FileAccess.Read);
            //FixedDocument fds = xpsdoc.GetFixedDocument();
            //DocumentReferenceCollection docrefs = fds.References;
            //DocumentReference docref = docrefs[0];
            //Uri uri1 = docref.Source;
            //FixedDocument fixeddoc = docref.GetDocument(false);
            //PageContent content = fixeddoc.Pages[0];
            //Uri uri2 = content.Source;
            //FixedPage fixedPage = content.Child;
            //xpsdoc.Close();
            // /Documents/1/Pages/1.fpage

            try
            {
                XpsDocument document = new PdfSharp.Xps.XpsModel.XpsDocument(xpsFilename);

                FixedDocument fdoc  = document.GetDocument();
                FixedPage     fpage = fdoc.GetFixedPage(0);
                //string s = fpage.c.Source;
                //s.GetType();

                //Uri uri;
                //ZipPackage package = ZipPackage.Open(xpsFilename) as ZipPackage;

                //PackagePartCollection parts = package.GetParts();
                //PackageRelationshipCollection relships = package.GetRelationships();


                //uri = new Uri("/FixedDocSeq.fdseq", UriKind.Relative);
                //string x = GetPartAsString(package, uri);
                ////ZipPackagePart part = pack.GetPart(uri) as ZipPackagePart;


                //PdfSharp.Xps.Parsing.XpsParser.Parse(GetPartAsXmlReader(package, uri));


                //        Uri uri = new Uri("/Documents/1/Pages/1.fpage", UriKind.Relative);
                //        ZipPackagePart part = pack.GetPart(uri) as ZipPackagePart;
                //        using (Stream stream = part.GetStream())
                //        {
                //          using (StreamReader sr = new StreamReader(stream))
                //          {
                //            string xml = sr.ReadToEnd();
                //#if true
                //            string xmlPath = IOPath.Combine(IOPath.GetDirectoryName(xpsFilename), IOPath.GetFileNameWithoutExtension(xpsFilename)) + ".xml";
                //            using (StreamWriter sw = new StreamWriter(xmlPath))
                //            {
                //              sw.Write(xml);
                //            }
                //#endif
                //            XpsElement el = PdfSharp.Xps.Parsing.XpsParser.Parse(xml);
                //            PdfRenderer renderer = new PdfRenderer();
                //            renderer.RenderPage(page, el as PdfSharp.Xps.XpsModel.FixedPage);
                //          }
                //        }
            }

            catch (Exception ex)
            {
                Debug.WriteLine("Exception: " + ex.Message);
            }
        }
Beispiel #18
0
        private void SaveFile(object sender, RoutedEventArgs e)
        {
            PrintDialog pd = new PrintDialog();

            if (pd.ShowDialog() == true)
            {
                FixedDocument doc = new FixedDocument();
                doc.DocumentPaginator.PageSize = new Size(pd.PrintableAreaWidth, pd.PrintableAreaHeight);

                List <Question> questions = this.DataContext as List <Question>;
                for (int p = 0; p <= questions.Count() / 17; p++)
                {
                    FixedPage fxpg = new FixedPage();
                    Grid      grid = new Grid();
                    if (p == 0)
                    {
                        RowDefinition titleRow = new RowDefinition();
                        grid.RowDefinitions.Add(titleRow);
                        Label label = new Label();
                        label.Content = titleBox.Text;
                        Grid.SetRow(label, 0);
                        Grid.SetColumn(label, 0);
                        grid.Children.Add(label);
                    }
                    fxpg.Width  = doc.DocumentPaginator.PageSize.Width;
                    fxpg.Height = doc.DocumentPaginator.PageSize.Height;

                    grid.Margin = new Thickness(20, 20, 20, 20);
                    int row = 1;
                    for (int i = 0; i < 17; i++)
                    {
                        RowDefinition rowD  = new RowDefinition();
                        RowDefinition rowD2 = new RowDefinition();
                        grid.RowDefinitions.Add(rowD);
                        grid.RowDefinitions.Add(rowD2);
                        int currentElement = i + p * 17;
                        if (currentElement >= questions.Count())
                        {
                            break;
                        }
                        Question question = questions[i + p * 17];
                        Label    label    = new Label();
                        label.Content = question.Number + ". " + question.QuestionText;
                        Grid.SetRow(label, row++);
                        Grid.SetColumn(label, 0);
                        grid.Children.Add(label);
                        DockPanel dockPanel = new DockPanel();
                        Grid.SetRow(dockPanel, row++);
                        Grid.SetColumn(dockPanel, 0);
                        for (int j = 0; j < question.Answers.Count(); j++)
                        {
                            CheckBox checkBox = new CheckBox();
                            checkBox.Margin  = new Thickness(10, 10, 10, 10);
                            checkBox.Content = question.Answers[j].Number + ") " + question.Answers[j].AnswerText;
                            dockPanel.Children.Add(checkBox);
                        }
                        grid.Children.Add(dockPanel);
                    }
                    fxpg.HorizontalAlignment = HorizontalAlignment.Center;

                    fxpg.Children.Add(grid);
                    PageContent pc = new PageContent();
                    pc.HorizontalAlignment = HorizontalAlignment.Center;

                    ((IAddChild)pc).AddChild(fxpg);
                    doc.Pages.Add(pc);
                }

                pd.PrintDocument(doc.DocumentPaginator, "Print Job Name");
            }
        }
Beispiel #19
0
 protected void AddText(FixedPage Page, string Text, double Top, double Left, int FontSize)
 {
     AddText(Page, Text, Top, Left, FontSize, 30, TextAlignment.Left);
 }
        private void InsertEntityChartPageHeader(FixedPage fp, int pageNumber, string slideName, int pageIndex)
        {
            var slideNameAvailableWidth = PageSize.Width - 2 * Constants.CsBook.PageNumberTextLength;

            var pageNumberLabel = new TextBlock {
                Text = string.Format("Page {0}", pageNumber)
            };

            FixedPage.SetLeft(pageNumberLabel, PageSize.Width - Constants.CsBook.PageNumberTextLength);
            FixedPage.SetTop(pageNumberLabel, 10);
            fp.Children.Add(pageNumberLabel);

            var       noOfTotal         = string.Format("({0} of {1})", pageIndex, PageCount);
            const int noOfTotalFontSize = 10;
            var       ft1 = new FormattedText(noOfTotal, Thread.CurrentThread.CurrentCulture,
                                              FlowDirection.LeftToRight, new Typeface("Verdana"), noOfTotalFontSize, Brushes.Black);
            var pageNumberTextWidth     = ft1.Width;
            var availableSlideNameWidth = slideNameAvailableWidth - pageNumberTextWidth;

            ft1 = new FormattedText(slideName, Thread.CurrentThread.CurrentCulture,
                                    FlowDirection.LeftToRight, new Typeface("Verdana"), 20, Brushes.Black);
            var slideNameTextWidth     = ft1.Width;
            var txtBlockSlideNameWidth = (slideNameTextWidth > availableSlideNameWidth)
                                             ? availableSlideNameWidth
                                             : slideNameTextWidth;
            var stackPanel = new StackPanel {
                Orientation = Orientation.Horizontal
            };
            var txtBlockSlideName = new TextBlock
            {
                Text              = slideName,
                Width             = Math.Max(0, txtBlockSlideNameWidth),
                FontFamily        = new FontFamily("Verdana"),
                FontSize          = 20,
                TextTrimming      = TextTrimming.CharacterEllipsis,
                Padding           = new Thickness(0),
                Margin            = new Thickness(0),
                VerticalAlignment = VerticalAlignment.Bottom
            };
            var txtBlockPageNo = new TextBlock
            {
                Text              = noOfTotal,
                Width             = pageNumberTextWidth,
                FontFamily        = new FontFamily("Verdana"),
                FontSize          = noOfTotalFontSize,
                TextTrimming      = TextTrimming.None,
                VerticalAlignment = VerticalAlignment.Bottom,
                Padding           = new Thickness(0, 0, 0, 2),
                Margin            = new Thickness(0)
            };

            stackPanel.Children.Add(txtBlockSlideName);
            stackPanel.Children.Add(txtBlockPageNo);
            var label = new Label
            {
                Width   = slideNameAvailableWidth,
                Content = stackPanel,
                HorizontalContentAlignment = HorizontalAlignment.Center,
                Padding = new Thickness(0),
                Margin  = new Thickness(0)
            };


            FixedPage.SetLeft(label, Constants.CsBook.PageNumberTextLength);
            FixedPage.SetTop(label, 10);
            fp.Children.Add(label);
        }
Beispiel #21
0
 /// <summary>
 /// Text einer Seite hinzufügen
 /// </summary>
 /// <param name="Page">Die Seire</param>
 /// <param name="Text">Text</param>
 /// <param name="Top">in Cm</param>
 /// <param name="Left">in Cm</param>
 /// <param name="FontSize">in Punkten</param>
 /// <param name="Width"></param>
 /// <param name="alignment"></param>
 protected void AddText(FixedPage Page, string Text, double Top, double Left, int FontSize, double Width, TextAlignment alignment)
 {
     AddText(Page, Text, Top, Left, FontSize, Width, 3, alignment, FontWeights.Normal, 0);
 }
        /// <summary>
        /// Divides elements of reportContainer into pages and exports them as PDF
        /// </summary>
        /// <param name="reportContainer">StackPanel containing report elements</param>
        /// <param name="dataContext">Data Context used in the report</param>
        /// <param name="margin">Margin of a report page</param>
        /// <param name="orientation">Landscape or Portrait orientation</param>
        /// <param name="resourceDictionary">Resources used in report</param>
        /// <param name="backgroundBrush">Brush that will be used as background for report page</param>
        /// <param name="reportHeaderDataTemplate">
        /// Optional header for each page
        /// Note: You can use DynamicResource PageNumber in this template to display page number
        /// </param>
        /// <param name="headerOnlyOnTheFirstPage">Use header only on the first page (default is false)</param>
        /// <param name="reportFooterDataTemplate">
        /// Optional footer for each page
        /// Note: You can use DynamicResource PageNumber in this template to display page number
        /// </param>
        /// <param name="footerStartsFromTheSecondPage">Do not use footer on the first page (default is false)</param>
        /// <param name="direction">Document Flow Direction</param>
        public static void ExportReportAsPdf(
            StackPanel reportContainer,
            object dataContext,
            Thickness margin,
            ReportOrientation orientation,
            ResourceDictionary resourceDictionary = null,
            Brush backgroundBrush = null,
            DataTemplate reportHeaderDataTemplate = null,
            bool headerOnlyOnTheFirstPage         = false,
            DataTemplate reportFooterDataTemplate = null,
            bool footerStartsFromTheSecondPage    = false,
            FlowDirection direction = FlowDirection.LeftToRight)
        {
            SaveFileDialog saveFileDialog = new SaveFileDialog
            {
                DefaultExt = ".pdf",
                Filter     = "PDF Documents (.pdf)|*.pdf"
            };

            bool?result = saveFileDialog.ShowDialog();

            if (result != true)
            {
                return;
            }

            Size reportSize = GetReportSize(reportContainer, margin, orientation);

            List <FrameworkElement> ReportElements = new List <FrameworkElement>(reportContainer.Children.Cast <FrameworkElement>());

            reportContainer.Children.Clear(); //to avoid exception "Specified element is already the logical child of another element."

            List <ReportPage> ReportPages =
                GetReportPages(
                    resourceDictionary,
                    backgroundBrush,
                    ReportElements,
                    dataContext,
                    margin,
                    reportSize,
                    reportHeaderDataTemplate,
                    headerOnlyOnTheFirstPage,
                    reportFooterDataTemplate,
                    footerStartsFromTheSecondPage);

            FixedDocument fixedDocument = new FixedDocument();

            try
            {
                using (MemoryStream memoryStream = new MemoryStream())
                {
                    System.IO.Packaging.Package package = System.IO.Packaging.Package.Open(memoryStream, FileMode.Create);
                    XpsDocument       xpsDocument       = new XpsDocument(package);
                    XpsDocumentWriter xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

                    foreach (Grid reportPage in ReportPages.Select(reportPage => reportPage.LayoutRoot))
                    {
                        reportPage.Width         = reportPage.ActualWidth;
                        reportPage.Height        = reportPage.ActualHeight;
                        reportPage.FlowDirection = direction;

                        FixedPage newFixedPage = new FixedPage();
                        newFixedPage.Children.Add(reportPage);
                        newFixedPage.Measure(reportSize);
                        newFixedPage.Arrange(new Rect(reportSize));
                        newFixedPage.Width      = newFixedPage.ActualWidth;
                        newFixedPage.Height     = newFixedPage.ActualHeight;
                        newFixedPage.Background = backgroundBrush;
                        newFixedPage.UpdateLayout();
                        newFixedPage.FlowDirection = direction;

                        PageContent pageContent = new PageContent();
                        pageContent.FlowDirection = direction;

                        ((IAddChild)pageContent).AddChild(newFixedPage);

                        fixedDocument.Pages.Add(pageContent);
                    }

                    xpsDocumentWriter.Write(fixedDocument);
                    xpsDocument.Close();

                    var packageUri = new Uri("memorystream://myXps.xps");
                    PackageStore.AddPackage(packageUri, package);
                    XpsDocument doc = new XpsDocument(package, CompressionOption.SuperFast, packageUri.AbsoluteUri);

                    XpsConverter.Convert(doc, saveFileDialog.FileName, 0);

                    package.Close();
                    //var pdfXpsDoc = PdfSharp.Xps.XpsModel.XpsDocument.Open(memoryStream);
                    //XpsConverter.Convert(pdfXpsDoc, saveFileDialog.FileName, 0);
                }
            }
            finally
            {
                ReportPages.ForEach(reportPage => reportPage.ClearChildren());
                ReportElements.ForEach(elm => reportContainer.Children.Add(elm));
                reportContainer.UpdateLayout();
            }
        }
Beispiel #23
0
 /// <summary>method update page layout after item adding
 /// </summary>
 public void UpdatePageLayout()
 {
     FixedPage.Measure(PageSize);
     FixedPage.Arrange(new Rect(new Point(), PageSize));
     FixedPage.UpdateLayout();
 }
 /// <summary>
 /// Write a single FixedPage and close package
 /// </summary>
 public override void Write(FixedPage fixedPage, PrintTicket printTicket)
 {
     SerializeObjectTree(fixedPage);
 }
Beispiel #25
0
        public List <PageContent> PrintPage()
        {
            List <PageContent> Pages = new List <PageContent>();

            InitializePages();

            PrintDialog printDialog = new PrintDialog();

            int ViewNumber = 1;

            foreach (RenderedImage renderedImage in m_RenderedImages)
            {
                PageContent pageContent = new PageContent();
                FixedPage   fixedPage   = new FixedPage();

                bool rotate = false;

                double width  = printDialog.PrintableAreaWidth;
                double height = printDialog.PrintableAreaHeight;

                if (renderedImage.Image.Width > renderedImage.Image.Height)
                {
                    width  = printDialog.PrintableAreaHeight;
                    height = printDialog.PrintableAreaWidth;
                    rotate = true;
                }

                PrintPreview printPreview = new PrintPreview(m_CaseObject, width, height, ViewNumber);
                printPreview.SetImage(renderedImage.Image);

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

                double pageWidth  = printDialog.PrintableAreaWidth;
                double pageHeight = printDialog.PrintableAreaHeight;

                if (rotate)
                {
                    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);

                if (renderedImage.IsAnnotationsShown && renderedImage.AnnotationComments.Count > 0)
                {
                    PageContent annotationPageContent = new PageContent();
                    FixedPage   annotationFixedPage   = new FixedPage();

                    //UserControl annotationPage = new UserControl();
                    AnnotCommentPrintPreview annotationPage;

                    if (m_RenderedImages.Count > 0)
                    {
                        annotationPage = new AnnotCommentPrintPreview(m_CaseObject, ViewNumber);
                    }
                    else
                    {
                        annotationPage = new AnnotCommentPrintPreview(m_CaseObject);
                    }

                    //annotationPage.MaxWidth = pageWidth - 48;
                    //annotationPage.MaxHeight = pageHeight - 48;

                    //WrapPanel annotationPanel = new WrapPanel();
                    //annotationPage.Content = annotationPanel;

                    FixedPage.SetLeft(annotationPage, 48);
                    FixedPage.SetTop(annotationPage, 48);

                    annotationPage.annotationPanel.Width  = pageWidth;
                    annotationPage.annotationPanel.Height = pageHeight;

                    annotationFixedPage.Children.Add((UIElement)annotationPage);

                    char[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };

                    int count = 0;

                    foreach (string comment in renderedImage.AnnotationComments)
                    {
                        AnnotationPage ap    = new AnnotationPage();
                        string         index = string.Empty;

                        int div = (count / 26) - 1;
                        int rem = count % 26;

                        if (div >= 0)
                        {
                            index += letters[div];
                        }

                        index += letters[rem];

                        ap.AnnotationIndex.Text = index;

                        ap.AnnotationComment.Text = comment;

                        annotationPage.annotationPanel.Children.Add(ap);

                        count++;
                    }

                    ((IAddChild)annotationPageContent).AddChild(annotationFixedPage);

                    Pages.Add(annotationPageContent);
                }

                ViewNumber++;
            }

            return(Pages);
        }
 /// <summary>
 /// Asynchronous Write a single FixedPage and close package
 /// </summary>
 public override void WriteAsync(FixedPage fixedPage, PrintTicket printTicket, object userState)
 {
     throw new NotSupportedException();
 }
Beispiel #27
0
        public static FixedDocumentSequence GetDocumentSequence(object dataContext, Stream inputStream, Size paperSize)
        {
            //承载一个可移植、高保真、格式固定的文档。
            FixedDocument _document = new FixedDocument();
            //为高保真度、固定格式的页面提供内容。
            FixedPage page = new FixedPage();

            //高度
            page.Height = paperSize.Height;
            //宽度
            page.Width = paperSize.Width;

            //提供有关FixedDocument中的FixedPage元素的信息。
            PageContent content = new PageContent();

            //Child:获取或设置与此PageContent关联的FixedPage。
            content.Child = page;

            //属性Pages:获取文档的PageContent元素的集合。
            //Add方法:向页集合中添加新页。
            _document.Pages.Add(content);

            FrameworkElement template = (FrameworkElement)XamlReader.Load(inputStream);

            template.BeginInit();
            template.DataContext = dataContext;

            template.Measure(paperSize);
            template.Arrange(new Rect(paperSize));
            template.EndInit();
            template.UpdateLayout();

            page.Children.Add(template);

            //构造一个基于内存的xps document  为什么?
            MemoryStream ms = new MemoryStream();
            //为XPS内容创建包
            Package package = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
            //每个包都需要一个URI。形式:"pack:// syntax"
            Uri documentUri = new Uri("pack://InMemoryDocument.xps");

            PackageStore.RemovePackage(documentUri);
            //加入该包
            PackageStore.AddPackage(documentUri, package);
            //基于该包创建XPS的XpsDocument对象
            XpsDocument xpsDocument = new XpsDocument(package, CompressionOption.Fast, documentUri.AbsoluteUri);

            //将flow document写入基于内存的xps document中去
            XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

            //分页
            writer.Write(((IDocumentPaginatorSource)_document).DocumentPaginator);

            //获取这个基于内存的xps document的fixed document
            FixedDocumentSequence pages = xpsDocument.GetFixedDocumentSequence();

            //关闭基于内存的xps document  关闭流以释放内存
            xpsDocument.Close();

            return(pages);
        }
Beispiel #28
0
        public override FixedDocument CreateFixedDocument()
        {
            FixedDocument fd = new FixedDocument();

            ReportProgressUpdate updateFunc = GetProgressUpdateFunc();
            ReportStatusUpdate   doneFunc   = GetProgressDoneFunc();

            fd.DocumentPaginator.PageSize = PageSize;

            if (doneFunc != null)
            {
                doneFunc(false, false);
            }

            if (Parameter.GetFieldValue("COSTING_TYPE").Equals("IMPORT"))
            {
                Parameter.SetFieldValue("DOCUMENT_TYPE", "1");
            }
            else if (Parameter.GetFieldValue("COSTING_TYPE").Equals("EXPORT"))
            {
                Parameter.SetFieldValue("DOCUMENT_TYPE", "2");
            }
            else if (Parameter.GetFieldValue("COSTING_TYPE").Equals("ADJUST"))
            {
                Parameter.SetFieldValue("DOCUMENT_TYPE", "4");
            }

            ArrayList arr = OnixWebServiceAPI.GetInventoryTransactionList(Parameter);

            if (arr == null)
            {
                return(fd);
            }

            int         cnt  = arr.Count;
            UReportPage area = null;

            createRowTemplates();
            int i = 0;

            Size areaSize = GetAreaSize();

            AvailableSpace = areaSize.Height;

            CReportDataProcessingProperty property = null;

            #region First Header Case : Row is 0
            if (arr.Count == 0)
            {
                arr.Add(Parameter); //add for show header and first row empty
            }
            #endregion
            while (i < arr.Count)
            {
                CTable o = (CTable)arr[i];
                if ((i == 0) || (property.IsNewPageRequired))
                {
                    AvailableSpace = areaSize.Height;

                    CurrentPage++;

                    FixedPage fp = new FixedPage();
                    fp.Margin = Margin;

                    PageContent pageContent = new PageContent();
                    ((System.Windows.Markup.IAddChild)pageContent).AddChild(fp);

                    fd.Pages.Add(pageContent);
                    area = initNewArea(areaSize);

                    pages.Add(area);
                    fp.Children.Add(area);
                }

                property = DataToProcessingProperty(o, arr, i);
                if (property.IsNewPageRequired)
                {
                    //Do not create row if that row caused new page flow
                    //But create it in the next page instead
                    i--;
                }
                else
                {
                    ConstructUIRows(area, property);
                }

                if (updateFunc != null)
                {
                    updateFunc(i, cnt);
                }

                i++;
            }

            if (doneFunc != null)
            {
                doneFunc(true, false);
            }

            keepFixedDoc = fd;
            return(fd);
        }
Beispiel #29
0
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            var document    = new FixedDocument();
            var report_page = new FixedPage();

            report_page.Width  = document.DocumentPaginator.PageSize.Width;
            report_page.Height = document.DocumentPaginator.PageSize.Height;
            report_page.Margin = new Thickness(20, 50, 20, 50);

            //Створення та запис заголовку.
            var title_text = new TextBlock();

            title_text.Text     = "Звіт";
            title_text.FontSize = 30;
            title_text.Margin   = new Thickness(document.DocumentPaginator.PageSize.Width * 0.45, 0, 0, 50);
            report_page.Children.Add(title_text);

            //Створення та запис графіків.
            StringReader stringReader = new StringReader(gridXaml);
            XmlReader    xmlReader    = XmlReader.Create(stringReader);
            Canvas       newGrid      = (Canvas)XamlReader.Load(xmlReader);

            report_page.Children.Add(newGrid);

            //Створення та запис правила.
            var main_text = new TextBlock();

            main_text.Text     = "Поточний рівень загрози: " + danger_level.Text;
            main_text.FontSize = 20;
            main_text.Margin   = new Thickness(20, 700, 0, 0);
            report_page.Children.Add(main_text);

            var report_page_сontent = new PageContent();

            ((IAddChild)report_page_сontent).AddChild(report_page);
            document.Pages.Add(report_page_сontent);

            using (MemoryStream xpsStream = new MemoryStream())
            {
                using (Package package = Package.Open(xpsStream, FileMode.Create, FileAccess.ReadWrite))
                {
                    string packageUriString = "memorystream://file_report.xps";
                    Uri    packageUri       = new Uri(packageUriString);

                    PackageStore.AddPackage(packageUri, package);

                    XpsDocument       xpsDocument = new XpsDocument(package, CompressionOption.Maximum, packageUriString);
                    XpsDocumentWriter writer      = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

                    writer.Write(document);

                    FixedDocumentSequence document_report = xpsDocument.GetFixedDocumentSequence();
                    xpsDocument.Close();

                    PrintPreviewWindow printPreviewWnd = new PrintPreviewWindow(document_report);
                    printPreviewWnd.Owner = Owner;
                    printPreviewWnd.ShowDialog();
                    PackageStore.RemovePackage(packageUri);
                }
            }
        }
        public void printInPrinter()
        {
            int fd = 0, fm = 0, fy = 0, td = 0, tm = 0, ty = 0;

            fd = int.Parse(FdateTxbx);
            fm = int.Parse(FmonthTxbx);
            fy = int.Parse(FyearTxbx);

            td = int.Parse(TdateTxbx);
            tm = int.Parse(TmonthTxbx);
            ty = int.Parse(TyearTxbx);
            ShowingReport[0].startDate = "" + fd + "/" + fm + "/" + fy;
            ShowingReport[0].endDate   = "" + td + "/" + tm + "/" + ty;
            for (int i = 0; i < ShowingReport.Count; i++)
            {
                ShowingReport[i].SL = i + 1;
            }


            StaticPageForAllData.printPerioDicReturn = ShowingReport;
            StaticPageForAllData.printNumber         = 3;

            if (ShowingReport.Count % 30 > 0)
            {
                StaticPageForAllData.pageNumber = (ShowingReport.Count / 30) + 1;
            }
            else
            {
                StaticPageForAllData.pageNumber = (ShowingReport.Count / 30);
            }
            StaticPageForAllData.PrintedpageNumber = 1;

            PrintDialog myPrintDialog = new PrintDialog();

            var pageSize = new Size(8.26 * 96, 11.69 * 96);
            var document = new FixedDocument();

            document.DocumentPaginator.PageSize = pageSize;
            for (int i = 0; i < StaticPageForAllData.pageNumber; i++)
            {
                PeriodicReturnPrint print = new PeriodicReturnPrint();
                // Create Fixed Page.
                var fixedPage = new FixedPage();
                fixedPage.Width  = pageSize.Width;
                fixedPage.Height = pageSize.Height;

                // Add visual, measure/arrange page.
                fixedPage.Children.Add((UIElement)print);
                fixedPage.Measure(pageSize);
                fixedPage.Arrange(new Rect(new Point(), pageSize));
                fixedPage.UpdateLayout();

                // Add page to document
                var pageContent = new PageContent();
                ((IAddChild)pageContent).AddChild(fixedPage);
                document.Pages.Add(pageContent);
            }


            // Send to the printer.
            var pd = new PrintDialog();

            if (myPrintDialog.ShowDialog() == true)
            {
                pd.PrintDocument(document.DocumentPaginator, "My Document");
            }
            //up = new UpdateViewCommand(viewModel);
        }
        PersistObjectData(
            SerializableObjectContext serializableObjectContext
            )
        {
            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializationBegin);

            if (serializableObjectContext == null)
            {
                throw new ArgumentNullException("serializableObjectContext");
            }

            if (SerializationManager is IXpsSerializationManager)
            {
                (SerializationManager as IXpsSerializationManager).RegisterPageStart();
            }

            FixedPage fixedPage = serializableObjectContext.TargetObject as FixedPage;

            ReachTreeWalker treeWalker = new ReachTreeWalker(this);

            treeWalker.SerializeLinksInFixedPage((FixedPage)serializableObjectContext.TargetObject);

            String xmlnsForType = SerializationManager.GetXmlNSForType(serializableObjectContext.TargetObject.GetType());

            if (xmlnsForType == null)
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name);
            }
            else
            {
                XmlWriter.WriteStartElement(serializableObjectContext.Name);

                XmlWriter.WriteAttributeString(XpsS0Markup.Xmlns, xmlnsForType);
                XmlWriter.WriteAttributeString(XpsS0Markup.XmlnsX, XpsS0Markup.XmlnsXSchema);

                XmlLanguage language = fixedPage.Language;
                if (language == null)
                {
                    //If the language property is null, assign the language to the default
                    language = XmlLanguage.GetLanguage(XpsS0Markup.XmlLangValue);
                }

                SerializationManager.Language = language;

                XmlWriter.WriteAttributeString(XpsS0Markup.XmlLang, language.ToString());
            }
            {
                Size fixedPageSize = new Size(fixedPage.Width, fixedPage.Height);
                ((IXpsSerializationManager)SerializationManager).FixedPageSize = fixedPageSize;

                //
                // Before we serialize any properties on the FixedPage, we need to
                // serialize the FixedPage as a Visual
                //
                Visual fixedPageAsVisual = serializableObjectContext.TargetObject as Visual;

                bool needEndVisual = false;

                if (fixedPageAsVisual != null)
                {
                    needEndVisual = SerializePageAsVisual(fixedPageAsVisual);
                }

                if (serializableObjectContext.IsComplexValue)
                {
                    PrintTicket printTicket = ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket;

                    if (printTicket != null)
                    {
                        PrintTicketSerializer serializer = new PrintTicketSerializer(SerializationManager);
                        serializer.SerializeObject(printTicket);
                        ((IXpsSerializationManager)SerializationManager).FixedPagePrintTicket = null;
                    }

                    SerializeObjectCore(serializableObjectContext);
                }
                else
                {
                    throw new XpsSerializationException(SR.Get(SRID.ReachSerialization_WrongPropertyTypeForFixedPage));
                }

                if (needEndVisual)
                {
                    XmlWriter pageWriter = ((XpsSerializationManager)SerializationManager).
                                           PackagingPolicy.AcquireXmlWriterForPage();

                    XmlWriter resWriter = ((XpsSerializationManager)SerializationManager).
                                          PackagingPolicy.AcquireXmlWriterForResourceDictionary();


                    VisualTreeFlattener flattener = ((IXpsSerializationManager)SerializationManager).
                                                    VisualSerializationService.AcquireVisualTreeFlattener(resWriter,
                                                                                                          pageWriter,
                                                                                                          fixedPageSize);

                    flattener.EndVisual();
                }
            }

            ((XpsSerializationManager)SerializationManager).PackagingPolicy.PreCommitCurrentPage();

            //
            // Copy hyperlinks into stream
            //
            treeWalker.CommitHyperlinks();

            XmlWriter.WriteEndElement();
            //
            //Release used resources
            //
            XmlWriter = null;
            //
            // Free the image table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageImageTable = null;
            //
            // Free the colorContext table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageColorContextTable = null;
            //
            // Free the resourceDictionary table in use for this page
            //
            ((XpsSerializationManager)SerializationManager).ResourcePolicy.CurrentPageResourceDictionaryTable = null;

            ((IXpsSerializationManager)SerializationManager).VisualSerializationService.ReleaseVisualTreeFlattener();

            if (SerializationManager is IXpsSerializationManager)
            {
                (SerializationManager as IXpsSerializationManager).RegisterPageEnd();
            }

            //
            // Signal to any registered callers that the Page has been serialized
            //
            XpsSerializationProgressChangedEventArgs progressEvent =
                new XpsSerializationProgressChangedEventArgs(XpsWritingProgressChangeLevel.FixedPageWritingProgress,
                                                             0,
                                                             0,
                                                             null);

            ((IXpsSerializationManager)SerializationManager).OnXPSSerializationProgressChanged(progressEvent);

            Toolbox.EmitEvent(EventTrace.Event.WClientDRXSerializationEnd);
        }
Beispiel #32
0
        public void printInPrinter()
        {
            StaticPageForAllData.printRecieptVoucher = ShowingVoucher;
            ObservableCollection <ReceiptVoucher> showThisPage = new ObservableCollection <ReceiptVoucher>();

            for (int i = 0; i < StaticPageForAllData.printRecieptVoucher.Count; i++)
            {
                StaticPageForAllData.printRecieptVoucher[i].SL = i + 1;

                for (int j = 0; j < StaticPageForAllData.StockData.Count; j++)
                {
                    if (StaticPageForAllData.printRecieptVoucher[i].itemNumber == StaticPageForAllData.StockData[j].itemNO)
                    {
                        StaticPageForAllData.printRecieptVoucher[i].unit = StaticPageForAllData.StockData[j].unit;
                    }
                }
                showThisPage.Add(StaticPageForAllData.printRecieptVoucher[i]);
            }
            StaticPageForAllData.printRecieptVoucher = showThisPage;
            StaticPageForAllData.printNumber         = 1;
            if (ShowingVoucher.Count % 30 > 0)
            {
                StaticPageForAllData.pageNumber = (ShowingVoucher.Count / 30) + 1;
            }
            else
            {
                StaticPageForAllData.pageNumber = (ShowingVoucher.Count / 30);
            }
            StaticPageForAllData.PrintedpageNumber = 2;

            PrintDialog myPrintDialog = new PrintDialog();

            var pageSize = new Size(8.26 * 96, 11.69 * 96);
            var document = new FixedDocument();

            document.DocumentPaginator.PageSize = pageSize;
            for (int i = 0; i < StaticPageForAllData.pageNumber; i++)
            {
                // Create Fixed Page.
                var fixedPage = new FixedPage();
                fixedPage.Width  = pageSize.Width;
                fixedPage.Height = pageSize.Height;

                // Add visual, measure/arrange page.
                PrintIssueVoucherView print = new PrintIssueVoucherView();
                fixedPage.Children.Add((UIElement)print);
                fixedPage.Measure(pageSize);
                fixedPage.Arrange(new Rect(new Point(), pageSize));
                fixedPage.UpdateLayout();

                // Add page to document
                var pageContent = new PageContent();
                ((IAddChild)pageContent).AddChild(fixedPage);
                document.Pages.Add(pageContent);
            }


            // Send to the printer.
            var pd = new PrintDialog();

            if (myPrintDialog.ShowDialog() == true)
            {
                pd.PrintDocument(document.DocumentPaginator, "My Document");
            }
            //up = new UpdateViewCommand(viewModel);
        }
Beispiel #33
0
        private void Print_Click(object sender, RoutedEventArgs e)
        {
            //If you reduce the size of the view area of the window, so the text does not all fit into one page, it will print separate pages
            string        str         = " If you reduce the size of the view area of the window, so \nthe text does not all fit into one page, it will print separate pages ";
            List <string> PrinterList = new List <string>();
            /*******************************/
            //printicket
            PrintTicket ticket = new PrintTicket();

            ticket.PageMediaSize   = new PageMediaSize(100, 100);
            ticket.PageOrientation = PageOrientation.Portrait;
            ticket.PageOrder       = PageOrder.Standard;


            LocalPrintServer     prntserver      = new LocalPrintServer();
            PrintQueueCollection queueCollection = prntserver.GetPrintQueues();
            PrintDialog          printDialog     = new PrintDialog();

            foreach (string printer in System.Drawing.Printing.PrinterSettings.InstalledPrinters)
            {
                PrinterList.Add(printer);
                //MessageBox.Show(printer);
            }
            PageRange pr = new PageRange(1, 3);

            string[] tempPrint     = PrinterList.ToArray();
            string   printFullName = printDialog.PrintQueue.FullName;

            printDialog.PrintQueue  = prntserver.GetPrintQueue(PrinterList[0]);
            printDialog.PrintTicket = ticket;
            printDialog.PageRange   = pr;
            //DocumentPaginator paginatro = new DocumentPaginator();



            /***************************************************************/
            // add exptra pages
            FixedPage     page = new FixedPage();
            FixedDocument Doc  = new FixedDocument();


            //if(printDialog.ShowDialog() == true)
            //printDialog.PrintDocument(((IDocumentPaginatorSource)flowDocument).DocumentPaginator, str + "This is a Flow Document");

            string NewSelectedPrinter = printDialog.PrintQueue.FullName;


            /*****************new code*********************/

            // select printer and get printer settings
            PrintDialog pd = new PrintDialog();
            //if (pd.ShowDialog() != true) return;
            //Create a document
            double width  = 400;
            double height = 600;

            FixedDocument fxDoc = new FixedDocument();

            fxDoc.DocumentPaginator.PageSize = new Size(width, height);

            // Create fixed page1
            //FixedPage page1 = new FixedPage();
            //page1.Width = width;
            //page1.Height = height;

            //// Create fixed page2
            //FixedPage page2 = new FixedPage();
            //page2.Width = width;
            //page2.Height = height;

            ////Add some text1
            TextBlock tx1 = new TextBlock();
            //tx1.Width = width;
            //tx1.FontSize = 12;
            //tx1.Text = " Page1 And add the page to the document, this is a little tricky because we need to use a PageContent object as an intermediary and it looks like there is no way to add the page to the page content, the trick is to use the IAddChild interface – according to the documentation you’re not supposed to use IAddChild directly but it’s the only way to build a fixed document.";
            //tx1.TextAlignment = TextAlignment.Justify;
            //tx1.TextWrapping = TextWrapping.Wrap;
            //page1.Children.Add(tx1);

            ////Add some text2
            //tx1 = new TextBlock();
            //tx1.Width = width;
            //tx1.FontSize = 20;
            //tx1.Text = "  Page 2 And add the page to the document, this is a little tricky because we need to use a PageContent object as an intermediary and it looks like there is no way to add the page to the page content, the trick is to use the IAddChild interface – according to the documentation you’re not supposed to use IAddChild directly but it’s the only way to build a fixed document.";
            //tx1.TextAlignment = TextAlignment.Justify;
            //tx1.TextWrapping = TextWrapping.Wrap;
            //page2.Children.Add(tx1);



            // add page to document bye PageContent object
            //PageContent pgCont = new PageContent();
            //pgCont.Child = page1;
            //fxDoc.Pages.Add(pgCont);
            //pgCont = new PageContent();
            //pgCont.Child = page2;
            //fxDoc.Pages.Add(pgCont);

            FixedPage page1;
            Grid      grd1;
            TextBlock tx2;

            fxDoc = new FixedDocument();
            FixedDocument fixDocument2 = new FixedDocument();
            PageContent   pgCont       = new PageContent();
            Grid          grd;

            FixedPage[] pageCollection = new FixedPage[10];
            //List<FixedPage> listPageCollection = new List<FixedPage>();
            for (int i = 0; i < 8; i++)
            {
                //CreatePage
                page        = new FixedPage();
                page.Name   = "Page" + i;
                page.Width  = width;
                page.Height = height;
                /***********(2)*************/
                page1        = new FixedPage();
                page1.Name   = "Page" + i;
                page1.Width  = width;
                page1.Height = height;

                //Add text to Page.
                grd       = new Grid();
                grd.Width = width;
                /*******(2)**********/
                grd1       = new Grid();
                grd1.Width = width;

                //Grid
                RowDefinition row = new RowDefinition();
                grd.RowDefinitions.Add(row);
                row = new RowDefinition();
                grd.RowDefinitions.Add(row);
                /************(2)******************/
                RowDefinition row1 = new RowDefinition();
                grd1.RowDefinitions.Add(row1);
                row1 = new RowDefinition();
                grd1.RowDefinitions.Add(row1);

                //Header TextBlock
                tx1               = new TextBlock();
                tx1.Width         = width;
                tx1.FontSize      = 20;
                tx1.Text          = "Page Index " + i;
                tx1.TextAlignment = TextAlignment.Center;
                //tx1.TextWrapping = TextWrapping.Wrap;
                Grid.SetRow(tx1, 0);
                grd.Children.Add(tx1);
                /***********(2)**************/
                //Header TextBlock
                tx2               = new TextBlock();
                tx2.Width         = width;
                tx2.FontSize      = 20;
                tx2.Text          = "Page Index " + i;
                tx2.TextAlignment = TextAlignment.Center;
                //tx1.TextWrapping = TextWrapping.Wrap;
                Grid.SetRow(tx2, 0);
                grd1.Children.Add(tx2);



                //Paragraph
                tx1               = new TextBlock();
                tx1.Width         = width;
                tx1.FontSize      = 14;
                tx1.Text          = "Page " + i + " And add the page to the document, this is a little tricky because we need to use a PageContent object as an intermediary and it looks like there is no way to add the page to the page content, the trick is to use the IAddChild interface – according to the documentation you’re not supposed to use IAddChild directly but it’s the only way to build a fixed document.";
                tx1.TextAlignment = TextAlignment.Justify;
                tx1.TextWrapping  = TextWrapping.Wrap;
                Grid.SetRow(tx1, 1);
                grd.Children.Add(tx1);

                /**************(2)*********************/
                //Paragraph
                tx2               = new TextBlock();
                tx2.Width         = width;
                tx2.FontSize      = 14;
                tx2.Text          = "Page " + i + " And add the page to the document, this is a little tricky because we need to use a PageContent object as an intermediary and it looks like there is no way to add the page to the page content, the trick is to use the IAddChild interface – according to the documentation you’re not supposed to use IAddChild directly but it’s the only way to build a fixed document.";
                tx2.TextAlignment = TextAlignment.Justify;
                tx2.TextWrapping  = TextWrapping.Wrap;
                Grid.SetRow(tx2, 1);
                grd1.Children.Add(tx2);



                page.Children.Add(grd);
                //Add text to pagecontent
                page1.Children.Add(grd1);

                CloneObject c1 = new CloneObject();
                pageCollection[i] = (FixedPage)c1.DeepCopy();

                pgCont       = new PageContent();
                pgCont.Child = page;
                fxDoc.Pages.Add(pgCont);
            }

            ticket = new PrintTicket();
            ticket.PageMediaSize   = new PageMediaSize(width, height);
            ticket.PageOrientation = PageOrientation.Portrait;
            //ticket.PagesPerSheet = 2;
            pd.PrintTicket = ticket;
            pd.PrintDocument(fxDoc.DocumentPaginator, "My First Document");


            /*****************Print According to Index************************************/

            pgCont = new PageContent();
            //pgCont= fxDoc.Pages[4];

            page         = new FixedPage();
            page         = pageCollection[3];
            pgCont.Child = page;

            fxDoc = new FixedDocument();
            fxDoc.Pages.Add(pgCont);

            ticket = new PrintTicket();
            ticket.PageMediaSize   = new PageMediaSize(width, height);
            ticket.PageOrientation = PageOrientation.Portrait;
            //ticket.PagesPerSheet = 2;
            pd.PrintTicket = ticket;
            pd.PrintDocument(fxDoc.DocumentPaginator, "My First Document");

            /*****************************Cloning of Object******************************************************/
        }
 public static IObservable <EventPattern <MouseButtonEventArgs> > MouseRightButtonDownObserver(this FixedPage This)
 {
     return(Observable.FromEventPattern <MouseButtonEventHandler, MouseButtonEventArgs>(h => This.MouseRightButtonDown += h, h => This.MouseRightButtonDown -= h));
 }
Beispiel #35
0
 public override void Write(FixedPage fixedPage);