Ejemplo n.º 1
0
    private FixedPage CreateFifthPageContent()
    {
      //PageContent pageContent = new PageContent();
      FixedPage fixedPage = new FixedPage();
      UIElement visual = BuildDrawing(); // 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 fixedPage;
    }
Ejemplo n.º 2
0
        private PageContent CreatePawnTicketContent()
        {
            PageContent pageContent = new PageContent();
            FixedPage fixedPage = new FixedPage();
            UIElement visual = PawnTicketUIElement();

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

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

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

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

            Size sz = new Size(8.5 * 96, 11 * 96);
            fixedPage.Measure(sz);
            fixedPage.Arrange(new Rect(new Point(), sz));
            fixedPage.UpdateLayout();

            ((IAddChild)pageContent).AddChild(fixedPage);
            return pageContent;
        }
Ejemplo n.º 3
0
        public void Create()
        {
            var uri    = new Uri("pack://application:,,,/ypi_client_order.xps");
            var stream = System.Windows.Application.GetResourceStream(uri).Stream;

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

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

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

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

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

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

            doc.Close();
            xpsStream.Position = 0;
            Package     finalPackage          = Package.Open(xpsStream, FileMode.Open);
            XpsDocument finalDoc              = new XpsDocument(finalPackage, CompressionOption.Fast, memoryStreamUri);
            var         fixedDocumentSequence = xpsDoc.GetFixedDocumentSequence();
        }
Ejemplo n.º 4
0
        public static IDocumentPaginatorSource CreateXpsDocument(string ss, string ssname)
        {
            FixedPage fp = new FixedPage();
            TextBox ll = new TextBox();
            ll.Margin = new Thickness(20, 40, 20, 40);
            fp.Children.Add(ll);
            fp.UpdateLayout();

            ll.TextWrapping = TextWrapping.WrapWithOverflow;
            ll.Text = ssname + Environment.NewLine + Environment.NewLine + ss;
            PageContent pc = new PageContent();
            ((System.Windows.Markup.IAddChild)pc).AddChild(fp);
            FixedDocument fd = new FixedDocument();
            fd.Pages.Add(pc);
            return fd;
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
0
        public static void DoItTTT()
        {
            string filename    = "c:\\tmp\\goof.xps";
            string newFilename = "c:\\tmp\\new_goof.xps";

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

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

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

            foreach (System.Windows.Documents.DocumentReference r in seqOld.References)
            {
                System.Windows.Documents.FixedDocument d = r.GetDocument(false);
                foreach (System.Windows.Documents.PageContent pc in d.Pages)
                {
                    System.Windows.Documents.FixedPage fixedPage = pc.GetPageRoot(false);
                    double width           = fixedPage.Width;
                    double height          = fixedPage.Height;
                    System.Windows.Size sz = new System.Windows.Size(width, height);
                    fixedPage.Measure(sz);
                    fixedPage.Arrange(new System.Windows.Rect(new System.Windows.Point(), sz));
                    fixedPage.UpdateLayout();
                    ContainerVisual newpage = new ContainerVisual();
                    newpage.Children.Add(fixedPage);
                    newpage.Children.Add(CreateWatermark(400, 400, "hello world"));
                    pageno++;
                    vxpsd.Write(newpage);
                }
            }
            vxpsd.EndBatchWrite();
            container.Close();
            xpsOld.Close();
        }
        private void PrintDocument()
        {
            FixedDocument fixedDocument = new FixedDocument();
            fixedDocument.DocumentPaginator.PageSize = new Size(96 * 8.5, 96 * 11);

            foreach (BitmapSource bitmapSource in this.m_BitmapSourceList)
            {
                PageContent pageContent = new PageContent();

                FixedPage fixedPage = new FixedPage();
                fixedPage.Background = Brushes.White;
                fixedPage.Width = 96 * 8.5;
                fixedPage.Height = 96 * 11;

                Image image = new Image();
                image.Width = 96 * 8;
                image.Height = 96 * 10.5;
                image.Source = bitmapSource;

                FixedPage.SetLeft(image, 96 * .25);
                FixedPage.SetTop(image, 96 * .25);
                fixedPage.Children.Add((UIElement)image);

                ((IAddChild)pageContent).AddChild(fixedPage);
                fixedDocument.Pages.Add(pageContent);

                Size pageSize = new Size(96 * 8.5, 96 * 11);
                fixedPage.Measure(pageSize);
                fixedPage.Arrange(new Rect(new Point(), pageSize));
                fixedPage.UpdateLayout();
            }

            PrintDialog printDialog = new PrintDialog();
            printDialog.ShowDialog();
            printDialog.PrintDocument(fixedDocument.DocumentPaginator, "Print TIF Document");
        }
		public static void ArrangePage(Size pageSize, FixedPage page)
		{
			page.Measure(pageSize);
			page.Arrange(new Rect(new System.Windows.Point(), pageSize));
			page.UpdateLayout();
		}
Ejemplo n.º 9
0
        /// <summary>
        /// Called when the Ddl property has changed.
        /// </summary>
        void DdlUpdated()
        {
            if (_ddl != null)
            {
                _document = DdlReader.DocumentFromString(_ddl);
                _renderer = new DocumentRenderer(_document);

                //this.renderer.PrivateFonts = this.privateFonts;
                _renderer.PrepareDocument();

                //IDocumentPaginatorSource source = this.documentViewer.Document;

                //IDocumentPaginatorSource source = this.documentViewer.Document;

                int pageCount = _renderer.FormattedDocument.PageCount;
                if (pageCount == 0)
                    return;

                // HACK: hardcoded A4 size
                //double pageWidth = XUnit.FromMillimeter(210).Presentation;
                //double pageHeight = XUnit.FromMillimeter(297).Presentation;
                //Size a4 = new Size(pageWidth, pageHeight);

                XUnit pageWidth, pageHeight;
                Size size96 = GetSizeOfPage(1, out pageWidth, out pageHeight);

                FixedDocument fixedDocument = new FixedDocument();
                fixedDocument.DocumentPaginator.PageSize = size96;

                for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++)
                {
                    try
                    {
                        size96 = GetSizeOfPage(1, out pageWidth, out pageHeight);

                        DrawingVisual dv = new DrawingVisual();
                        DrawingContext dc = dv.RenderOpen();
                        //XGraphics gfx = XGraphics.FromDrawingContext(dc, new XSize(XUnit.FromMillimeter(210).Point, XUnit.FromMillimeter(297).Point), XGraphicsUnit.Point);
                        XGraphics gfx = XGraphics.FromDrawingContext(dc, new XSize(pageWidth.Point, pageHeight.Presentation), XGraphicsUnit.Point);
                        _renderer.RenderPage(gfx, pageNumber, PageRenderOptions.All);
                        dc.Close();

                        // Create page content
                        PageContent pageContent = new PageContent();
                        pageContent.Width = size96.Width;
                        pageContent.Height = size96.Height;
                        FixedPage fixedPage = new FixedPage();
                        fixedPage.Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0xFE, 0xFE, 0xFE));

                        UIElement visual = new DrawingVisualPresenter(dv);
                        FixedPage.SetLeft(visual, 0);
                        FixedPage.SetTop(visual, 0);

                        fixedPage.Width = size96.Width;
                        fixedPage.Height = size96.Height;

                        fixedPage.Children.Add(visual);

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

                        ((IAddChild)pageContent).AddChild(fixedPage);

                        fixedDocument.Pages.Add(pageContent);
                    }
                    catch (Exception)
                    {
                        // eat exception
                    }

                    viewer.Document = fixedDocument;
                }
            }
            else
                viewer.Document = null;
        }
        //*************************************************************************
        //  Method: SaveToXps()
        //
        /// <summary>
        /// Saves the graph to the specified XPS file.
        /// </summary>
        ///
        /// <param name="imageSize">
        /// Size of the XPS image, in WPS units.
        /// </param>
        ///
        /// <param name="fileName">
        /// File name to save to.
        /// </param>
        ///
        /// <remarks>
        /// This could conceivably be put in the base-class NodeXLControl class,
        /// but that would force all users of the control to add references to the
        /// XPS assemblies.
        /// </remarks>
        //*************************************************************************
        public void SaveToXps(
            Size imageSize,
            String fileName
            )
        {
            Debug.Assert( !String.IsNullOrEmpty(fileName) );
            AssertValid();

            CheckIfLayingOutGraph("SaveToXps");

            // This control will be rehosted by a FixedPage.  It can't be a child
            // of logical trees, so disconnect it from its parent after saving the
            // current vertex locations.

            LayoutSaver oLayoutSaver = new LayoutSaver(this.Graph);

            Debug.Assert(this.Parent is Panel);
            Panel oParentPanel = (Panel)this.Parent;
            UIElementCollection oParentChildren = oParentPanel.Children;
            Int32 iChildIndex = oParentChildren.IndexOf(this);
            oParentChildren.Remove(this);

            GraphImageCenterer oGraphImageCenterer = new GraphImageCenterer(this);

            FixedDocument oFixedDocument = new FixedDocument();
            oFixedDocument.DocumentPaginator.PageSize = imageSize;
            PageContent oPageContent = new PageContent();

            FixedPage oFixedPage = new FixedPage();
            oFixedPage.Width = imageSize.Width;
            oFixedPage.Height = imageSize.Height;

            this.Width = imageSize.Width;
            this.Height = imageSize.Height;

            // Adjust the control's translate transforms so that the image will be
            // centered on the same point on the graph that the control is centered
            // on.

            oGraphImageCenterer.CenterGraphImage(imageSize);

            oFixedPage.Children.Add(this);
            oFixedPage.Measure(imageSize);

            oFixedPage.Arrange(new System.Windows.Rect(
            new System.Windows.Point(), imageSize) );

            oFixedPage.UpdateLayout();

            ( (System.Windows.Markup.IAddChild)oPageContent ).AddChild(
            oFixedPage);

            oFixedDocument.Pages.Add(oPageContent);

            try
            {
            XpsDocument oXpsDocument = new XpsDocument(fileName,
                FileAccess.Write);

            XpsDocumentWriter oXpsDocumentWriter =
                XpsDocument.CreateXpsDocumentWriter(oXpsDocument);

            oXpsDocumentWriter.Write(oFixedDocument);
            oXpsDocument.Close();
            }
            finally
            {
            // Reconnect the NodeXLControl to its original parent.  Reset the
            // size to Auto in the process.

            oFixedPage.Children.Remove(this);
            this.Width = Double.NaN;
            this.Height = Double.NaN;
            oGraphImageCenterer.RestoreCenter();
            oParentChildren.Insert(iChildIndex, this);

            // The graph may have shrunk when it was connected to the
            // FixedPage, and even though it will be expanded to its original
            // dimensions when UpdateLayout() is called below, the layout may
            // have lost "resolution" and the results may be poor.
            //
            // Fix this by restoring the original layout and redrawing the
            // graph.

            this.UpdateLayout();
            oLayoutSaver.RestoreLayout();
            this.DrawGraph(false);
            }
        }
Ejemplo n.º 11
0
        private void Window_Initialized(object sender, EventArgs e)
        {
            //ConvertWordDocToXPSDoc("H:\\资料\\客户端流程设计.doc");
            //Uri source = new Uri(@"http://www.jjgjt.com/download/1.xps");

            //FtpWeb fw = new FtpWeb("www.jjgjt.com:8889", @"xps/", "Huiyou", "huiyouhuiyou");

            //Stream stream=fw.DownloadStream("1.xps");
            //if (stream != null)
            //{
            //    System.IO.Packaging.Package package = System.IO.Packaging.Package.Open(stream,FileMode.Open);
            //    string memoryStreamUri = "memorystream://printstream";
            //    Uri packageUri = new Uri(memoryStreamUri);
            //    System.IO.Packaging.PackageStore.AddPackage(packageUri, package);

            //    XpsDocument xps = new XpsDocument(package,System.IO.Packaging.CompressionOption.SuperFast, memoryStreamUri);

            //string memoryStreamUri = "memorystream://printstream";
            //Uri packageUri = new Uri(memoryStreamUri);
            //MemoryStream ms=new MemoryStream(Properties.Resources._1);
            //System.IO.Packaging.Package package = System.IO.Packaging.Package.Open(ms,FileMode.Open);
            //System.IO.Packaging.PackageStore.AddPackage(packageUri, package);
            //foreach(System.IO.Packaging.PackagePart pp in package.GetParts())
            //{
            //    MessageBox.Show(pp.ContentType);
            //}
                FixedPage fp = new FixedPage();
                Label ll = new Label();
                ll.Content = "测试数据可以吗?" + Environment.NewLine + "回车换行可以吗?";
                ll.Margin = new Thickness(20, 40, 20, 40);
                fp.Children.Add(ll);
                fp.UpdateLayout();
                PageContent pc = new PageContent();
                ((System.Windows.Markup.IAddChild)pc).AddChild(fp);
                FixedDocument fd = new FixedDocument();
                fd.Pages.Add(pc);
                FixedDocumentSequence fds = new FixedDocumentSequence();
                ((System.Windows.Markup.IAddChild)fds).AddChild(fd);
            documentViewer1.Document=fds;

            //System.Net.NetworkInformation.NetworkInterface[] nics = System.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces();
            //foreach( System.Net.NetworkInformation.NetworkInterface ni in  nics )
            //{
            //    MessageBox.Show(ni.Description);
            //    System.Net.NetworkInformation.PhysicalAddress address = ni.GetPhysicalAddress();
            //    byte[] bytes = address.GetAddressBytes();
            //    StringBuilder sb=new StringBuilder();
            //    for (int i = 0; i < bytes.Length; i++)
            //    {
            //        sb.Append(bytes[i].ToString("X2"));
            //        if(i<bytes.Length-1)
            //            sb.Append("-");
            //    }
            //    MessageBox.Show(sb.ToString());
            //}
            //fd. = "1234";

            //}
            //else
            //    MessageBox.Show(FtpWeb.error);
        }
Ejemplo n.º 12
0
    /// <summary>
    /// Renders the current visual as a FixedPage and save it as XPS file.
    /// </summary>
    public void SaveXps()
    {
      XpsDocument xpsDocument = new XpsDocument(Path.Combine(OutputDirectory, Name + ".xps"), FileAccess.ReadWrite);
      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();

      // 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);
    }
Ejemplo n.º 13
0
    internal void OnRender()
    {
      if (RenderEvent != null)
      {
        //IDocumentPaginatorSource source = this.documentViewer.Document;

        DrawingVisual dv = new DrawingVisual();
        DrawingContext dc = dv.RenderOpen();

        XGraphics gfx = XGraphics.FromDrawingContext(dc,
          new XSize(XUnit.FromMillimeter(210).Point, XUnit.FromMillimeter(297).Point), XGraphicsUnit.Point);
        try
        {
          RenderEvent(gfx);
        }
        catch { }
        dc.Close();
        //DrawingGroup dg = dv.Drawing;

        // Create page content
        PageContent pageContent = new PageContent();
        FixedPage fixedPage = new FixedPage();
        fixedPage.Background = Brushes.GhostWhite;
        //UIElement visual = dv; // CreateSecondVisual(false);

        UIElement visual = new DrawingVisualPresenter(dv);
        FixedPage.SetLeft(visual, 0);
        FixedPage.SetTop(visual, 0);

        double pageWidth = XUnit.FromMillimeter(210).Presentation;
        double pageHeight = XUnit.FromMillimeter(297).Presentation;

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

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

        Size size = new Size(pageWidth, pageHeight);
        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);

        this.documentViewer.Document = fixedDocument;

        string savedButton = System.Windows.Markup.XamlWriter.Save(fixedDocument);
      }
      else
        this.documentViewer.Document = null;



      //base.OnRender(drawingContext);
      ////drawingContext.DrawLine(new Pen(Brushes.Green, 10), new Point(10, 10), new Point(100, 150));

      //drawingContext.PushTransform(new ScaleTransform(0.75, 0.75));
      //XGraphics gfx = XGraphics.FromDrawingContext(drawingContext, new XSize(100, 100), XGraphicsUnit.Millimeter);
      //if (RenderEvent != null)
      //{
      //  try
      //  {
      //    RenderEvent(gfx);
      //  }
      //  catch
      //  {
      //    RenderEvent = null;
      //  }
      //}
      //else
      //  Draw(gfx);
    }
Ejemplo n.º 14
0
 private IDocumentPaginatorSource CreateXpsDocument(string ss, string ssname)
 {
     FixedPage fp = new FixedPage();
     Label ll = new Label();
     ll.Content = ssname + Environment.NewLine + Environment.NewLine + ss;
     ll.Margin = new Thickness(20, 40, 20, 40);
     fp.Children.Add(ll);
     fp.UpdateLayout();
     PageContent pc = new PageContent();
     ((System.Windows.Markup.IAddChild)pc).AddChild(fp);
     FixedDocument fd = new FixedDocument();
     fd.Pages.Add(pc);
     return fd;
 }