コード例 #1
0
        /// <summary>
        /// Helper method to create page header or footer from flow document template
        /// </summary>
        /// <param name="data">enumerable report data</param>
        /// <returns></returns>
        /// <exception cref="ArgumentNullException">data</exception>
        public XpsDocument CreateXpsDocument(IEnumerable <ReportData> data)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            int count = 0; ReportData firstData = null;

            foreach (ReportData rd in data)
            {
                if (firstData == null)
                {
                    firstData = rd;
                }
                count++;
            }
            if (count == 1)
            {
                return(CreateXpsDocument(firstData));            // we have only one ReportData object -> use the normal ReportPaginator instead
            }
            MemoryStream ms   = new MemoryStream();
            Package      pkg  = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
            string       pack = "pack://report.xps";

            PackageStore.RemovePackage(new Uri(pack));
            PackageStore.AddPackage(new Uri(pack), pkg);
            XpsDocument             doc       = new XpsDocument(pkg, CompressionOption.NotCompressed, pack);
            XpsSerializationManager rsm       = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
            DocumentPaginator       paginator = ((IDocumentPaginatorSource)CreateFlowDocument()).DocumentPaginator;

            MultipleReportPaginator rp = new MultipleReportPaginator(this, data);

            rsm.SaveAsXaml(rp);
            return(doc);
        }
コード例 #2
0
        /// <summary>
        /// Helper method to create page header or footer from flow document template
        /// </summary>
        /// <param name="data">enumerable report data</param>
        /// <param name="fileName">file to save XPS to</param>
        /// <returns></returns>
        public XpsDocument CreateXpsDocument(IEnumerable <ReportData> data, string fileName)
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }
            int count = 0; ReportData firstData = null;

            foreach (ReportData rd in data)
            {
                if (firstData == null)
                {
                    firstData = rd;
                }
                count++;
            }
            if (count == 1)
            {
                return(CreateXpsDocument(firstData));            // we have only one ReportData object -> use the normal ReportPaginator instead
            }
            Package pkg  = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite);
            string  pack = "pack://report.xps";

            PackageStore.RemovePackage(new Uri(pack));
            PackageStore.AddPackage(new Uri(pack), pkg);
            XpsDocument             doc = new XpsDocument(pkg, _xpsCompressionOption, pack);
            XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);

            MultipleReportPaginator rp = new MultipleReportPaginator(this, data);

            rsm.SaveAsXaml(rp);
            rsm.Commit();
            pkg.Close();
            return(new XpsDocument(fileName, FileAccess.Read));
        }
コード例 #3
0
ファイル: ReportDocument.cs プロジェクト: xbadcode/Rubezh
		/// <summary>
		/// Helper method to create page header or footer from flow document template
		/// </summary>
		/// <param name="data">enumerable report data</param>
		/// <param name="fileName">file to save XPS to</param>
		/// <returns></returns>
		public XpsDocument CreateXpsDocument(IEnumerable<ReportData> data, string fileName)
		{
			if (data == null)
				throw new ArgumentNullException("data");
			int count = 0;
			ReportData firstData = null;
			foreach (ReportData rd in data) { if (firstData == null) firstData = rd; count++; }
			if (count == 1)
				return CreateXpsDocument(firstData); // we have only one ReportData object -> use the normal ReportPaginator instead

			Package pkg = Package.Open(fileName, FileMode.Create, FileAccess.ReadWrite);
			string pack = "pack://report.xps";
			PackageStore.RemovePackage(new Uri(pack));
			PackageStore.AddPackage(new Uri(pack), pkg);
			XpsDocument doc = new XpsDocument(pkg, _xpsCompressionOption, pack);
			XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
			//DocumentPaginator paginator = ((IDocumentPaginatorSource)CreateFlowDocument()).DocumentPaginator;

			MultipleReportPaginator rp = new MultipleReportPaginator(this, data);
			rsm.SaveAsXaml(rp);
			rsm.Commit();
			pkg.Close();
			return new XpsDocument(fileName, FileAccess.Read);
		}
コード例 #4
0
ファイル: ReportDocument.cs プロジェクト: xbadcode/Rubezh
		/// <summary>
		/// Helper method to create page header or footer from flow document template
		/// </summary>
		/// <param name="data">enumerable report data</param>
		/// <returns></returns>
		/// <exception cref="ArgumentNullException">data</exception>
		public XpsDocument CreateXpsDocument(IEnumerable<ReportData> data)
		{
			using (var counter = new TimeCounter("CreateXpsDocument Total:		{0}", true, true))
			{
				if (data == null)
					throw new ArgumentNullException("data");
				int count = 0;
				ReportData firstData = null;
				foreach (ReportData rd in data) { if (firstData == null) firstData = rd; count++; }
				if (count == 1)
					return CreateXpsDocument(firstData); // we have only one ReportData object -> use the normal ReportPaginator instead

				MemoryStream ms = new MemoryStream();
				Package pkg = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
				string pack = "pack://report.xps";
				PackageStore.RemovePackage(new Uri(pack));
				PackageStore.AddPackage(new Uri(pack), pkg);
				XpsDocument doc = new XpsDocument(pkg, CompressionOption.NotCompressed, pack);
				XpsSerializationManager rsm = new XpsSerializationManager(new XpsPackagingPolicy(doc), false);
				//DocumentPaginator paginator = ((IDocumentPaginatorSource)CreateFlowDocument()).DocumentPaginator;
				counter.ShowTick("CreateXpsDocument Prepare:	{0}");

				MultipleReportPaginator rp = new MultipleReportPaginator(this, data);
				counter.ShowTick("CreateXpsDocument Paginator:	{0}");
				rsm.SaveAsXaml(rp);
				counter.ShowTick("CreateXpsDocument SaveAsXaml:	{0}");
				return doc;
			}
		}