PDFsharp & MigraDoc Foundation
https://forum.pdfsharp.net/

XGraphics.DrawImage does not take srcRect into account
https://forum.pdfsharp.net/viewtopic.php?f=3&t=3285
Page 1 of 1

Author:  aleq_99 [ Wed Feb 03, 2016 5:34 pm ]
Post subject:  XGraphics.DrawImage does not take srcRect into account

Hi,

I have the following example using XForm:

Code:
var pdfDocument = new PdfDocument();

var form = new XForm(pdfDocument, XUnit.FromCentimeter(...), XUnit.FromCentimeter(..));
var formGfx = XGraphics.FromForm(form);

// draw images and other elements
formGfx.DrawImage(...)
formGfx.DrawImage(...)
formGfx.DrawImage(...)

var pdfPage = pdfDocument.AddPage();
pdfPage.Width = XUnit.FromCentimeter(...);
pdfPage.Height = XUnit.FromCentimeter(..);

var gfx = XGraphics.FromPdfPage(pdfPage);
gfx.DrawImage(form, new XRect(...),  new XRect(...), XGraphicsUnit.Point);


The srcRect (3rd) parameter is completely ignored as stated in XGraphicsPdfRenderer.DrawImage source file where I ended up after debugging. I want to draw only part of the "image" represented by XForm. If this is not supported right now, can you suggest how to accomplish this task. It is crucial to have this option in my project.

I'm using this library for years and really appreciate its functionality.
Thanks in advance.

Alex

Author:  Thomas Hoevel [ Thu Feb 04, 2016 2:18 pm ]
Post subject:  Re: XGraphics.DrawImage does not take srcRect into account

Hi, Alex,

It is not yet implemented. And as far as I know it is not yet implemented because an implementation will be very complicated.

Workaround: draw the complete XForm and then hide unwanted areas under white rectangles. Don't do this if the "hidden" areas contain confidential information.

Author:  aleq_99 [ Thu Feb 04, 2016 2:27 pm ]
Post subject:  Re: XGraphics.DrawImage does not take srcRect into account

Hi Thomas,

Thanks for your reply. I get your solution, but what I want to accomplish is get/extract a region from the Xform and then zoom it in (enlarge) into the page drawing surface. To make it work with white rectangles it will be quite challenging. I was hoping to find another workaround.

Alex

Author:  aleq_99 [ Tue Feb 09, 2016 5:18 pm ]
Post subject:  Re: XGraphics.DrawImage does not take srcRect into account

Hi Thomas,

I'm doing some tests drawing xform inside another xform. Do you see any issue using that approach as a workaround?

Code:
            var pdfDocument = new PdfDocument();

            // Inner Pdf Form
            var innerForm = new XForm(pdfDocument, XUnit.FromCentimeter(21), XUnit.FromCentimeter(21));
            var innerFormGfx = XGraphics.FromForm(innerForm);
            using (XImage image = XImage.FromFile(...))
            {
                .....
                innerFormGfx.DrawImage(image, 0, 0, width, height);
            }

            // Outer Pdf Form
            var outerForm = new XForm(pdfDocument, XUnit.FromCentimeter(21), XUnit.FromCentimeter(21));
            var outerFormGfx = XGraphics.FromForm(outerForm);
            outerFormGfx.DrawImage(innerForm, -200, -200, outerForm.PixelWidth, outerForm.PixelHeight);

            // PDF PAGE
            var pdfPage = pdfDocument.AddPage();
            pdfPage.Width = XUnit.FromCentimeter(42);
            pdfPage.Height = XUnit.FromCentimeter(42);

            var coef = 2;

            var gfx = XGraphics.FromPdfPage(pdfPage);
            gfx.DrawImage(outerForm, 50, 50, outerForm.PixelWidth * coef, (double)outerForm.PixelHeight * coef);

            pdfDocument.Save(pdfPath);


The idea of using -200, -200 when drawing onto the outerForm is to simulate srcRect i.e. drawing just part of the form.

Alex

Page 1 of 1 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/