printing - C# Can't print the right image size -


i'm trying make program print image file printer onto a4 sized paper. (the image scaled a4) code i'm using.

function.cs              image tmp;     public void printimage(string filename)     {         tmp = image.fromfile(filename);         printdocument printdoc = new printdocument();         printdoc.documentname = "my print document";         printdoc.printpage += new printpageeventhandler(onprintpage);         // send print message         console.writeline("sending print message...");         try         {             printdoc.print();         }         catch(exception)         {             console.writeline("error: no printer installed");         }         //         // event handler         //     }     private void onprintpage(object sender, printpageeventargs ppea)     {     console.writeline("printing...");     graphics g = ppea.graphics;     g.drawimage(tmp,0,0);     }    main.cs      string receiptfilepath = "c:\\receipt.jpg"; // image want print.      private void button1_click(object sender, eventargs e)     {         functions.printimage(receiptfilepath);     } 

with above code, can printed, not in a4 size, rather zoomed in 400%. how should modify code?

the image scaled a4

that's problem statement. printdocument scales. initializes graphics instance e.graphics in printpage event handler pageunit = graphicsunit.display. precooked scaling mode makes 1 pixel 0.01 inches on paper. or in other words, image that's 100 x 100 pixels becomes 1.00 x 1.00 inch on paper.

this convenient scaling mode, chosen make draw screen same size on paper. video adapters tend operate @ 96 dots-per-inch resolution. although that's changing, later windows versions make easy increase this.

so prescaling image, you'll end making image large. makes large on paper additional scaling done printer's graphics object.

giving better advice isn't easy since didn't describe how prescaled image. not prescaling solves problem. using graphics.drawimage(image, rectangle) overload can better bet, gives direct control on size of image on paper. giving opportunity deal different paper sizes , still making image fit.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -