Click here to Skip to main content
13,550,805 members
Rate this:
Please Sign up or sign in to vote.
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

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 26-Nov-12 6:30am
SAKryukov 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.

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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:[^],[^].

You get this parameters when you print a page in your handler of the of event System.Drawing.Printing.PrintDocument.PrintPage:[^],[^].

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:[^].

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.


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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web04-2016 | 2.8.180515.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2018
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100