Click here to Skip to main content
Rate this: bad
good
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 7:30am
iKsn213
Comments
Sergey Alexandrovich Kryukov at 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

Rate this: bad
good
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:
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
  Permalink  
v2

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

  Print Answers RSS
0 OriginalGriff 195
1 ProgramFOX 130
2 Maciej Los 105
3 Sergey Alexandrovich Kryukov 105
4 Afzaal Ahmad Zeeshan 82
0 OriginalGriff 6,564
1 Sergey Alexandrovich Kryukov 6,048
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web03 | 2.8.1411022.1 | Last Updated 26 Nov 2012
Copyright © CodeProject, 1999-2014
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