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

DrawImage from XGraphicsPdfRenderer
https://forum.pdfsharp.net/viewtopic.php?f=2&t=3938
Page 1 of 1

Author:  SammuelMiranda [ Tue Mar 26, 2019 1:17 pm ]
Post subject:  DrawImage from XGraphicsPdfRenderer

Hello. I'm using PdfSharp to print an image to a PDF, and my goal would be to draw the image in parts, for multiple pages (since it's a big image, requires multiple A3 pages - my biggest printer).

I used the XGraphics DrawImage method with 2 XRect arguments, similar to the GDI methods, to draw the part of the image on the first page, move X coordinate on source, add a page and draw the next section until it's done.

Debuging the source code to understand why instead of doing what i though instead it repeated the entire image "reduced" on every page, i found a comment on the code of the XGraphicsPdfRenderer class (that is called by the DrawImage method of the XGraphics class) that says: "incomplete - srcRect not used".

I have no clue on how to alter this procedure to use the srcRect argument and get sections of the image based on that rectangle. The code currently is (of the PdfSharp version that i have):

Code:
public void DrawImage(XImage image, XRect destRect, XRect srcRect, XGraphicsUnit srcUnit)
{
    double x = destRect.X;
    double y = destRect.Y;
    double width = destRect.Width;
    double height = destRect.Height;
    string name = this.Realize(image);
    if (!(image is XForm)) { if (this.gfx.PageDirection == XPageDirection.Downwards) { AppendFormat("q {2:0.####} 0 0 -{3:0.####} {0:0.####} {4:0.####} cm {5} Do\nQ\n", x, y, width, height, y + height, name); } else { AppendFormat("q {2:0.####} 0 0 {3:0.####} {0:0.####} {1:0.####} cm {4} Do Q\n", x, y, width, height, name); } }
    else
    {
        BeginPage();
        XForm xForm = (XForm)image;
        xForm.Finish();
        PdfFormXObject pdfForm = Owner.FormTable.GetForm(xForm);
        double cx = width / image.PointWidth;
        double cy = height / image.PointHeight;
        if (cx != 0 && cy != 0) { if (this.gfx.PageDirection == XPageDirection.Downwards) { AppendFormat("q {2:0.####} 0 0 -{3:0.####} {0:0.####} {4:0.####} cm 100 Tz {5} Do Q\n", x, y, cx, cy, y + height, name); } else { AppendFormat("q {2:0.####} 0 0 {3:0.####} {0:0.####} {1:0.####} cm {4} Do Q\n", x, y, cx, cy, name); } }
    }
}


By looking at it is clear that in fact the argument is ignored; but i don't knwo enought of the AppendFormat or the Realize(image) method to change that. Any help?

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