Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i'm working in one APP that print some Drawings, diferent sizes we hace 3 diferent models of printers and CutePDF Printer.

if i print my image with this code

VB
Dim im As Image
im = Image.FromFile("C:\Image.jpg")
Dim p As New PointF(0, 3)
e.Graphics.DrawImage(im, p)
e.Graphics.DrawString("Copy", New Font("Arial", 12, FontStyle.Regular), Brushes.Black, 3, 0)


with the CUTEPDF The image is printed fine
but if i send the image to one of our printers, it doesnt fit all at page.

My questions are:

With e.Graphics i can send images with default size or fit to the page?
With e.Graphics i cant autoajust the image to the printer default DPI?

Thank you.
Posted
Comments
Sergey Alexandrovich Kryukov 26-Nov-12 13:20pm    
To get answers, you need to ask proper questions. In this case, you don't show us what's e. I can guess this is an event arguments parameter, but you should show it. This can be exactly your problem. You are asking about the size of the page, but you are not showing the context where the size could be got. Why would you care of DPI? It's not your concern: it depends on user selection.
--SA

1 solution

Please see my comment to the question and, next time, make sure you provide enough information.

Now, think logically: you either need to know pixel size of the printable area of the page or size in inches + DPI (dots per inch), not both, because these variables depend on each other and can contradict if you take them all. In this case, you are given the printable area in pixels; it is given you in the event arguments when you print a page; this value is System.Drawing.Printing.PrintPageEventArgs.MarginBounds:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printpageeventargs.marginbounds.aspx[^].

You get this parameters when you print a page in your handler of the of event System.Drawing.Printing.PrintDocument.PrintPage:
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.aspx[^],
http://msdn.microsoft.com/en-us/library/system.drawing.printing.printdocument.printpage.aspx[^].

In the two last articles referenced above, there are short code samples. If you are doing something else, you are doing it wrong. Again, too bad you did not show essential context of your code.

I would also advice that you develop a single method for rendering some control, form or part of it for rendering on both screen and print page, and pass relevant parameters to this method. You can do it, because in both cases you are dealing with the instance of System.Drawing.Graphics:
http://msdn.microsoft.com/en-us/library/system.drawing.graphics.aspx[^].

Additionally, you can pass margin and/or other relevant parameters. This will make your printing consistent with on-screen rendering and will help you to avoid repeating of code.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900