Ehsan Akbar Ehsan Akbar - 1 month ago 6
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;
pd.Print();
}


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

This might fix the issue.

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

or

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

or

ev.Graphics.DrawImage(Image.FromFile("C:\\My Folder\\MyFile.bmp"), ev.Graphics.VisibleClipBounds);
Comments