Search code examples
c#printingprintdocument

PrintDocument just prints some part of my JPG file


I created an application that allows users to print multiple jpg files. So I send my print request directly, 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?


Solution

  • 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);