Avatar of asp316
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;
            dlgPrintPreview.ShowDialog();
        }
 
 
        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

Microsoft Development.NET ProgrammingC#

Avatar of undefined
Last Comment
asp316

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
MogalManic

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
See how we're fighting big data
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
ASKER
asp316

Thanks! Works great!
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23