public XGraphicsPdfRenderer(PdfPage page, XGraphics gfx, XGraphicsPdfPageOptions options) { _page = page; _colorMode = page._document.Options.ColorMode; _options = options; _gfx = gfx; _content = new StringBuilder(); page.RenderContent._pdfRenderer = this; _gfxState = new PdfGraphicsState(this); }
public XGraphicsPdfRenderer(PdfPage page, XGraphics gfx, XGraphicsPdfPageOptions options) { this.page = page; this.colorMode = page.document.Options.ColorMode; this.options = options; #if MIGRADOC this.options = options & ~XGraphicsPdfPageOptions.PDFlibHack; pdflibHack = (options & XGraphicsPdfPageOptions.PDFlibHack) != 0; #endif this.gfx = gfx; this.content = new StringBuilder(); page.RenderContent.pdfRenderer = this; this.gfxState = new PdfGraphicsState(this); }
private void ExecuteApplyImage() { if (cbApplyBgImage.Checked) { LoadDocuments(); if (PdfDocuments != null && PdfDocuments.Any()) { foreach (KeyValuePair <string, PdfDocument> item in PdfDocuments) { if (item.Value.PageCount > 0) { XGraphicsPdfPageOptions position = cbApplyFrontImage.Checked ? XGraphicsPdfPageOptions.Append : XGraphicsPdfPageOptions.Prepend; PdfPage page = item.Value.Pages[0]; XGraphics gfx = XGraphics.FromPdfPage(page, position); XImage image = XImage.FromFile(txtBgImage.Text); gfx.DrawImage(image, 0, 0, page.Width.Point, page.Height.Point); } } } } }
/// <summary> /// Creates a new instance of the XGraphics class from a PdfSharp.Pdf.PdfPage object. /// </summary> public static XGraphics FromPdfPage(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit unit, XPageDirection pageDirection) { return new XGraphics(page, options, unit, pageDirection); }
/// <summary> /// Creates a new instance of the XGraphics class from a PdfSharp.Pdf.PdfPage object. /// </summary> public static XGraphics FromPdfPage(PdfPage page, XGraphicsPdfPageOptions options) { return new XGraphics(page, options, XGraphicsUnit.Point, XPageDirection.Downwards); }
/// <summary> /// Initializes a new instance of the XGraphics class for drawing on a PDF page. /// </summary> XGraphics(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit pageUnit, XPageDirection pageDirection) { if (page == null) throw new ArgumentNullException("page"); if (page.Owner == null) throw new ArgumentException("You cannot draw on a page that is not owned by a PdfDocument object.", "page"); if (page.RenderContent != null) throw new InvalidOperationException("An XGraphics object already exists for this page and must be disposed before a new one can be created."); if (page.Owner.IsReadOnly) throw new InvalidOperationException("Cannot create XGraphics for a page of a document that cannot be modified. Use PdfDocumentOpenMode.Modify."); 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; #if GDI // HACK: This does not work with MediumTrust //this.gfx = Graphics.FromHwnd(IntPtr.Zero); this.targetContext = XGraphicTargetContext.GDI; Bitmap bm = new Bitmap(10, 10); this.gfx = Graphics.FromImage(bm); #endif #if WPF && !SILVERLIGHT this.dv = new DrawingVisual(); this.dc = this.dv.RenderOpen(); this.targetContext = XGraphicTargetContext.WPF; #endif #if SILVERLIGHT this.dc = new DrawingContext(new Canvas()); this.targetContext = XGraphicTargetContext.WPF; #endif #if GDI && WPF this.targetContext = PdfSharp.Internal.TargetContextHelper.TargetContext; #endif this.renderer = new PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer(page, this, options); this.pageSizePoints = new XSize(page.Width, page.Height); switch (pageUnit) { case XGraphicsUnit.Point: this.pageSize = new XSize(page.Width, page.Height); break; case XGraphicsUnit.Inch: this.pageSize = new XSize(XUnit.FromPoint(page.Width).Inch, XUnit.FromPoint(page.Height).Inch); break; case XGraphicsUnit.Millimeter: this.pageSize = new XSize(XUnit.FromPoint(page.Width).Millimeter, XUnit.FromPoint(page.Height).Millimeter); break; case XGraphicsUnit.Centimeter: this.pageSize = new XSize(XUnit.FromPoint(page.Width).Centimeter, XUnit.FromPoint(page.Height).Centimeter); break; case XGraphicsUnit.Presentation: this.pageSize = new XSize(XUnit.FromPoint(page.Width).Presentation, XUnit.FromPoint(page.Height).Presentation); break; default: throw new NotImplementedException("unit"); } this.pageUnit = pageUnit; this.pageDirection = pageDirection; Initialize(); }
/// <summary> /// Initializes a new instance of the XGraphics class for drawing on a PDF page. /// </summary> XGraphics(PdfPage page, XGraphicsPdfPageOptions options, XGraphicsUnit pageUnit, XPageDirection pageDirection) { if (page == null) throw new ArgumentNullException("page"); if (page.Owner == null) throw new ArgumentException("You cannot draw on a page that is not owned by a PdfDocument object.", "page"); if (page.RenderContent != null) throw new InvalidOperationException("An XGraphics object already exists for this page and must be disposed before a new one can be created."); if (page.Owner.IsReadOnly) throw new InvalidOperationException("Cannot create XGraphics for a page of a document that cannot be modiefied"); 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.gfx = Graphics.FromHwnd(IntPtr.Zero); this.renderer = new PdfSharp.Drawing.Pdf.XGraphicsPdfRenderer(page, this, options); this.pageSizePoints = new XSize(page.Width, page.Height); switch (pageUnit) { case XGraphicsUnit.Point: this.pageSize = new XSize(page.Width, page.Height); break; case XGraphicsUnit.Inch: this.pageSize = new XSize(XUnit.FromPoint(page.Width).Inch, XUnit.FromPoint(page.Height).Inch); break; case XGraphicsUnit.Millimeter: this.pageSize = new XSize(XUnit.FromPoint(page.Width).Millimeter, XUnit.FromPoint(page.Height).Millimeter); break; case XGraphicsUnit.Centimeter: this.pageSize = new XSize(XUnit.FromPoint(page.Width).Centimeter, XUnit.FromPoint(page.Height).Centimeter); break; default: throw new NotImplementedException("unit"); } this.pageUnit = pageUnit; this.pageDirection = pageDirection; Initialize(); }