Ehsan Akbar Ehsan Akbar - 1 year ago 66
C# Question

PrintDocument just prints some part of my JPG file

I create an application that makes my users to be able print multi jpg files.So i directly send my print request like this :

if (existfile == true)
PrinterSettings a=new PrinterSettings();
PrintDocument pd = new PrintDocument();
IEnumerable<PaperSize> size = a.PaperSizes.Cast<PaperSize>();
PaperSize a4 = size.First<PaperSize>(i => i.Kind == PaperKind.A4);
pd.DefaultPageSettings.Landscape = true;
pd.DefaultPageSettings.PaperSize = a4;
pd.PrintPage += PrintPage;

And the print function :

private void PrintPage(object o, PrintPageEventArgs e)
System.Drawing.Image img = System.Drawing.Image.FromFile(CurrentAddress);
Point loc = new Point(100, 100);
e.Graphics.DrawImage(img, loc);

But this code just prints some part of my image not all of it .I want to print them
scale to fit
. how can i do that?

Answer Source

This might fix the issue.

e.Graphics.DrawImage(img, e.MarginBounds);


e.Graphics.DrawImage(img, e.PageBounds);


ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download