private FixedDocumentSequence CreateFixedDocumentSequence(IEnumerable <IEnumerable <string> > projects,
                                                                  Size areaExtent,
                                                                  Size areaOrigin,
                                                                  bool fixedStrokeThickness,
                                                                  DiagramTable table)
        {
            var fixedDocumentSeq = new FixedDocumentSequence()
            {
                Name = "diagrams"
            };

            foreach (var diagrams in projects)
            {
                var fixedDocument = CreateFixedDocument(diagrams,
                                                        areaExtent,
                                                        areaOrigin,
                                                        fixedStrokeThickness,
                                                        table);

                var documentRef = new DocumentReference();
                documentRef.BeginInit();
                documentRef.SetDocument(fixedDocument);
                documentRef.EndInit();

                (fixedDocumentSeq as IAddChild).AddChild(documentRef);
            }

            return(fixedDocumentSeq);
        }
예제 #2
0
        /// <summary>
        /// Attaches a FixedDocument to a FixedDocumentSequence.
        /// </summary>
        /// <param name="document">The document to attach.</param>
        /// <param name="fds">The document sequence to attach to.</param>
        private static void AttachDocumentToSequence(FixedDocument document, FixedDocumentSequence fds)
        {
            DocumentReference dr = new DocumentReference();

            dr.BeginInit();
            dr.SetDocument(document);
            dr.EndInit();

            ((IAddChild)fds).AddChild(dr);
        }
예제 #3
0
        public FixedDocumentSequence GetResult()
        {
            // wrap the FixedDocument object in a DocumentReference object
            DocumentReference docRef = new DocumentReference();

            docRef.BeginInit();
            docRef.SetDocument(_document);
            docRef.EndInit();
            // add the DocumentReference object above to a FixedDocumentSequence object
            FixedDocumentSequence docSeq = new FixedDocumentSequence();

            (docSeq as IAddChild).AddChild(docRef);
            // return the FixedDocumentSequence object
            return(docSeq);
        }
예제 #4
0
        public static void ConvertToXps(FixedDocument fixedDocument, Stream outputStream)
        {
            Package               package           = Package.Open(outputStream, FileMode.Create);
            XpsDocument           xpsDocument       = new XpsDocument(package, CompressionOption.Normal);
            XpsDocumentWriter     xpsDocumentWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);
            FixedDocumentSequence fixedDocSeq       = new FixedDocumentSequence();
            DocumentReference     docRef            = new DocumentReference();

            docRef.BeginInit();
            docRef.SetDocument(fixedDocument);
            docRef.EndInit();
            ((IAddChild)fixedDocSeq).AddChild(docRef);
            xpsDocumentWriter.Write(fixedDocSeq.DocumentPaginator);
            xpsDocument.Close();
            package.Close();
        }
    /// <summary>
    /// encapsulater for a UIElement in an DocumentReference
    /// DocumentReference(FixedDocument(PageContent(FixedPage(UIElement))))
    /// to simplify the print of multiple pages
    /// </summary>
    /// <param name="uiElement">the UIElement which</param>
    /// <returns>creates a DocumentReference</returns>
    private DocumentReference toDocumentReference(UIElement uiElement)
    {
        if (uiElement == null)
        {
            throw new NullReferenceException("the UIElement has to be not null");
        }

        FixedPage         fixedPage   = new FixedPage();
        PageContent       pageContent = new PageContent();
        FixedDocument     fixedDoc    = new FixedDocument();
        DocumentReference docRef      = new DocumentReference();

        #region Step1

        // add the UIElement object the FixedPage
        fixedPage.Children.Add(uiElement);

        #endregion

        #region Step2

        // add the FixedPage to the PageContent collection
        pageContent.BeginInit();
        ((IAddChild)pageContent).AddChild(fixedPage);
        pageContent.EndInit();

        #endregion

        #region Step 3

        //// add the PageContent to the FixedDocument collection
        ((IAddChild)fixedDoc).AddChild(pageContent);

        #endregion

        #region Step 4

        //// add the FixedDocument to the document reference collection
        docRef.BeginInit();
        docRef.SetDocument(fixedDoc);
        docRef.EndInit();

        #endregion

        return(docRef);
    }
예제 #6
0
        public void Print(string printerName)
        {
            string receiptPath = Path.GetDirectoryName(_receiptFile) + "\\" + Path.GetFileNameWithoutExtension(_receiptFile) + ".xps";

            if (File.Exists(receiptPath))
            {
                File.Delete(receiptPath);
            }

            using (FileStream outputStream = File.Create(receiptPath))
            {
                var package   = Package.Open(outputStream, FileMode.Create);
                var xpsDoc    = new XpsDocument(package, CompressionOption.Normal);
                var xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

                var fixedDocSeq = new FixedDocumentSequence();
                var docRef      = new DocumentReference();
                docRef.BeginInit();
                docRef.SetDocument(_template);
                docRef.EndInit();
                ((IAddChild)fixedDocSeq).AddChild(docRef);

                xpsWriter.Write(fixedDocSeq.DocumentPaginator);

                xpsDoc.Close();
                package.Close();
            }

            using (var printServer = new LocalPrintServer())
            {
                EnumeratedPrintQueueTypes[] enumerationFlags = { EnumeratedPrintQueueTypes.Local, EnumeratedPrintQueueTypes.Connections };

                foreach (PrintQueue queue in printServer.GetPrintQueues(enumerationFlags))
                {
                    if (queue.Name == printerName)
                    {
                        queue.AddJob("Photo Kiosk", receiptPath, false);
                        break;
                    }
                }
            }
        }
        public static void ConvertToXps(FixedDocument fixedDoc, Stream outputStream)
        {
            var package = Package.Open(outputStream, FileMode.Create);
            var xpsDoc = new XpsDocument(package, CompressionOption.Normal);
            XpsDocumentWriter xpsWriter = XpsDocument.CreateXpsDocumentWriter(xpsDoc);

            // xps documents are built using fixed document sequences
            var fixedDocSeq = new FixedDocumentSequence();
            var docRef = new DocumentReference();
            docRef.BeginInit();
            docRef.SetDocument(fixedDoc);
            docRef.EndInit();
            ((IAddChild)fixedDocSeq).AddChild(docRef);

            // write out our fixed document to xps
            xpsWriter.Write(fixedDocSeq.DocumentPaginator);

            xpsDoc.Close();
            package.Close();
        }
예제 #8
0
        private void PrintImage(string fileName, Int32Rect crop, int quantity)
        {
            Console.WriteLine("    Print image " + fileName + " in " + quantity.ToString() + " copies.");

            PrintTicket ticket = _printer.UserPrintTicket;
            Size        paper  = new Size(Math.Max(ticket.PageMediaSize.Width.Value, ticket.PageMediaSize.Height.Value), Math.Min(ticket.PageMediaSize.Width.Value, ticket.PageMediaSize.Height.Value));
            Size        format = new Size(Math.Max(_width, _height) * 96 / 25.4, Math.Min(_width, _height) * 96 / 25.4);

            double printableWidth;
            double printableHeight;

            if (format.Width <= paper.Width && format.Height <= paper.Height)
            {
                printableWidth  = format.Width;
                printableHeight = format.Height;
            }
            else if (format.Width <= paper.Height && format.Height <= paper.Width)
            {
                printableWidth  = format.Height;
                printableHeight = format.Width;
            }
            else
            {
                printableWidth  = paper.Width;
                printableHeight = paper.Height;
            }

            // Swap printable width and height if page orientation is portarait
            if (ticket.PageOrientation == PageOrientation.Portrait || ticket.PageOrientation == PageOrientation.ReversePortrait)
            {
                double temp = printableWidth;
                printableWidth  = printableHeight;
                printableHeight = temp;
            }

            fileName = _orderFolder + fileName;

            // Create FixedDocument containing the image
            var fixedDocument = new FixedDocument();
            var pageContent   = new PageContent();
            var fixedPage     = new FixedPage();
            var image         = CreateImage(fileName, printableWidth, printableHeight, crop);

            fixedPage.Width  = printableWidth;
            fixedPage.Height = printableHeight;
            fixedPage.Children.Add(image);
            ((IAddChild)pageContent).AddChild(fixedPage);
            fixedDocument.Pages.Add(pageContent);

            // Save FixedDocument to XPS file
            string xpsFilePath = fileName + _width.ToString() + "x" + _height.ToString() + ".xps";

            using (FileStream outputStream = File.Create(xpsFilePath))
            {
                var package     = Package.Open(outputStream, FileMode.Create);
                var xpsDoc      = new XpsDocument(package, CompressionOption.Normal);
                var xpsWriter   = XpsDocument.CreateXpsDocumentWriter(xpsDoc);
                var fixedDocSeq = new FixedDocumentSequence();
                var docRef      = new DocumentReference();
                docRef.BeginInit();
                docRef.SetDocument(fixedDocument);
                docRef.EndInit();
                ((IAddChild)fixedDocSeq).AddChild(docRef);

                xpsWriter.Write(fixedDocSeq.DocumentPaginator);

                xpsDoc.Close();
                package.Close();
            }

            // Add the XPS file to print queue
            for (int i = 0; i < quantity; i++)
            {
                _printer.AddJob("Photo Kiosk", xpsFilePath, false);
                _success = true;
            }
        }