Beispiel #1
0
        public virtual int SaveAsXps(string fileName)
        {
            object doc;

            if (Draft == null)
                return -1;

            FileInfo fileInfo = new FileInfo(fileName);
            SavableDocument sav = new SavableDocument(Draft);
            doc = sav.CloneDoc();

            //using (FileStream file = fileInfo.OpenRead())
            //{
            //    System.Windows.Markup.ParserContext context = new System.Windows.Markup.ParserContext();
            //    context.BaseUri = new Uri(fileInfo.FullName, UriKind.Absolute);
            //    //doc = System.Windows.Markup.XamlReader.Load(file, context);
                
            //}


            if (!(doc is IDocumentPaginatorSource))
            {
                Console.WriteLine("DocumentPaginatorSource expected");
                return -1;
            }

            File.Delete(fileName);
            using (Package container = Package.Open(fileName, FileMode.Create))
            {
                using (XpsDocument xpsDoc = new XpsDocument(container, CompressionOption.Maximum))
                {
                    XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);

                    DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;


                    // 8 inch x 6 inch, with half inch margin
                    paginator = new DocumentPaginatorWrapper(paginator, new Size(595*1.33, 842*1.3), new Size(48, 48));


                    rsm.SaveAsXaml(paginator);
                    
                }
            }


            return 0;
        }
Beispiel #2
0
        public override int SaveAsXps(string fileName)
        {
            object doc;

            if (Draft == null)
                return -1;

            FileInfo fileInfo = new FileInfo(fileName);

            List<FlowDocument> Docs = new List<FlowDocument>();
            for (int x = 0; x < Chapters.Count; x++)
                Docs.Add(((Chapter)Chapters[x]).getFlow());

            doc = SavableDocument.CombineDocs(Docs);


            if (!(doc is IDocumentPaginatorSource))
            {
                Console.WriteLine("DocumentPaginatorSource expected");
                return -1;
            }

            File.Delete(fileName);
            using (Package container = Package.Open(fileName, FileMode.Create))
            {
                using (XpsDocument xpsDoc = new XpsDocument(container, CompressionOption.Maximum))
                {
                    XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(xpsDoc), false);

                    DocumentPaginator paginator = ((IDocumentPaginatorSource)doc).DocumentPaginator;


                    // 8 inch x 6 inch, with half inch margin
                    paginator = new DocumentPaginatorWrapper(paginator, new Size(595 * 1.33, 842 * 1.3), new Size(48, 48));


                    rsm.SaveAsXaml(paginator);

                }
            }


            return 0;
        }