/// <summary> /// Gets the fixed page with the specified index. /// </summary> public FixedPage GetFixedPage(int index) { if (FixedPages == null) FixedPages = new FixedPage[PageContentUriStrings.Count]; // Parse on demand FixedPage fpage = FixedPages[index]; if (fpage == null) { string source = IOPath.Combine(UriString, PageContentUriStrings[index]); source = source.Replace('\\', '/'); fpage = Parsing.XpsParser.Parse(XpsDocument.GetPartAsXmlReader(Package, source)) as FixedPage; if (fpage != null) { fpage.Parent = this; fpage.Document = this; source = IOPath.GetDirectoryName(source); source = source.Replace('\\', '/'); fpage.UriString = source; fpage.LoadResources(); FixedPages[index] = fpage; } } return fpage; }
internal void RenderPage(PdfPage page, FixedPage fixedPage) { this.page = page; this.context = new DocumentRenderingContext(page.Owner); //this.page.Width = fixedPage.Width; //this.page.Height = fixedPage.Height; //this.gsStack = new GraphicsStateStack(this); PdfContent content = null; //switch (options) //{ // case XGraphicsPdfPageOptions.Replace: // page.Contents.Elements.Clear(); // goto case XGraphicsPdfPageOptions.Append; // case XGraphicsPdfPageOptions.Prepend: // content = page.Contents.PrependContent(); // break; // case XGraphicsPdfPageOptions.Append: content = page.Contents.AppendContent(); // break; //} page.RenderContent = content; this.writer = new PdfContentWriter(this.context, this.page); //Initialize(); this.writer.BeginContent(false); this.writer.WriteElements(fixedPage.Content); this.writer.EndContent(); }
internal PdfPage CreatePage(PdfDocument doc, FixedPage fixedPage) { PdfPage page = doc.Pages.Add(); page.Width = XUnit.FromPresentation(fixedPage.Width); page.Height = XUnit.FromPresentation(fixedPage.Height); return page; }
/// <summary> /// HACK /// </summary> public PdfPage CreatePage(int xpsPageIndex) { FixedPage fixedPage = xpsDocument.GetDocument().GetFixedPage(xpsPageIndex); PdfPage page = pdfDocument.AddPage(); page.Width = XUnit.FromPresentation(fixedPage.Width); page.Height = XUnit.FromPresentation(fixedPage.Height); return(page); }
/// <summary> /// Renders an XPS document page to the specified PDF page. /// </summary> /// <param name="page">The target PDF page. The page must belong to the PDF document of this converter.</param> /// <param name="xpsPageIndex">The zero-based XPS page number.</param> public void RenderPage(PdfPage page, int xpsPageIndex) { if (page == null) { throw new ArgumentNullException("page"); } if (!ReferenceEquals(page.Owner, pdfDocument)) { throw new InvalidOperationException(PSXSR.PageMustBelongToPdfDocument); } // Debug.Assert(xpsPageIndex==0, "xpsPageIndex must be 0 at this stage of implementation."); try { FixedPage fpage = xpsDocument.GetDocument().GetFixedPage(xpsPageIndex); // ZipPackage pack = ZipPackage.Open(xpsFilename) as ZipPackage; Uri uri = new Uri("/Documents/1/Pages/1.fpage", UriKind.Relative); ZipPackagePart part = xpsDocument.Package.GetPart(uri) as ZipPackagePart; if (part != null) { using (Stream stream = part.GetStream()) using (StreamReader sr = new StreamReader(stream)) { string xml = sr.ReadToEnd(); #if true && DEBUG if (!String.IsNullOrEmpty(xpsDocument.Path)) { string xmlPath = IOPath.Combine(IOPath.GetDirectoryName(xpsDocument.Path), IOPath.GetFileNameWithoutExtension(xpsDocument.Path)) + ".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, fpage); } } } catch (Exception ex) { Debug.WriteLine(ex.ToString()); throw; } }