PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Aug 18, 2017 8:50 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
PostPosted: Wed Feb 03, 2016 5:34 pm 
Offline

Joined: Wed Feb 03, 2016 5:21 pm
Posts: 9
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


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 04, 2016 2:18 pm 
Offline
empira Employee
User avatar

Joined: Mon Oct 16, 2006 8:16 am
Posts: 2689
Location: Cologne, Germany
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.

_________________
Regards
Thomas Hoevel
PDFsharp Team


Top
 Profile  
Reply with quote  
PostPosted: Thu Feb 04, 2016 2:27 pm 
Offline

Joined: Wed Feb 03, 2016 5:21 pm
Posts: 9
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


Top
 Profile  
Reply with quote  
PostPosted: Tue Feb 09, 2016 5:18 pm 
Offline

Joined: Wed Feb 03, 2016 5:21 pm
Posts: 9
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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group