Link to home
Start Free TrialLog in
Avatar of asp316

asked on

Print an image to a specific size paper (11x17)

Hey all -
I have an image that I'm trying to print on 11x17 paper. I've used the code below. Whenever i do a print preview, it comes up alined to the right and the right part is cropped by about 2 inches. I've tried several different resolutions and have attempted to set margins, thinking that's the problem. My code is below and I'm really up for other ideas, especially ones that allow for more flexability as the client may want to eventually print at 8.5/11. However, i'm really interested in 11x17 and to get all of teh image on the page. The image is portrait and I'd rather it didn't crop. I can resize the image. however,it somehow appears to do the same thing everytime I tweak the image size.
protected void btnPrint_Click(object sender, EventArgs e)
            PrintDocument pd = new PrintDocument();
            //set printer to use 11x17            
             foreach (PaperSize paperSz in pd.PrinterSettings.PaperSizes )
             if (paperSz.PaperName.StartsWith("11x17"))
             pd.DefaultPageSettings.PaperSize = paperSz;
            pd.PrintPage += new PrintPageEventHandler(pqr);
            PrintPreviewDialog dlgPrintPreview = new PrintPreviewDialog();
            // Set any optional properties of dlgPrintPreview here...
            dlgPrintPreview.Document = pd;
        void pqr(object o, PrintPageEventArgs e)
            System.Drawing.Image i = System.Drawing.Image.FromFile("C:\\TEMP\\test.jpg");
            Point p = new Point(100, 100);
            e.Graphics.DrawImage(i, p);

Open in new window

Avatar of MogalManic
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of asp316


Thanks! Works great!