Houssam

Houssam

  • NA
  • 24
  • 26.6k

How to print one large image in many pages

Dec 28 2012 4:04 PM
Hello everyone.
I want to print one tall image in many pages, So in every page, I take a suitable part from the image and I draw it in the page.
the problem is that I have got the image shrunk (its shape is compressed) in the page,so I added an scale that its value is 1500 .
I think that i can solve the problem if I knew the length of the page (e.Graphics) in pixels.
to convert Inches to Pixel, Do I have to divide to (e.Graphics.DpiX = 600) or divide to 96 .

void printdocument_PrintPage(object sender, PrintPageEventArgs e)
        {
           if (pageImage ==  null) 
               return;
            e.Graphics.PageUnit = GraphicsUnit.Pixel;

            e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
            e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;

           
            float a = (e.MarginBounds.Width / 100) * e.Graphics.DpiX;
            float b = ((e.MarginBounds.Height / 100) * e.Graphics.DpiY);
            int scale = 1500;
            scale = 0; //try to comment this
            RectangleF srcRect = new RectangleF(0, startY, pageImage.Width, b - scale);
            RectangleF destRect = new RectangleF(0, 0, a, b);
            e.Graphics.DrawImage(pageImage, destRect, srcRect, GraphicsUnit.Pixel);
            startY = Convert.ToInt32(startY + b - scale);
            e.HasMorePages = (startY < pageImage.Height);
        }


could you please make it works correctly.
the code is attached .
thanks in advanced.

Answers (1)