How to print GDI+ objects with correct dimensions? - c#

I need to develop an application to print labels previously created with an editor. Each labels has some graphic objects, like images, barcodes, texts,... and when I use the GDI+ drawing methods to print in a PrintDocument, the result is that the object dimensions are always smaller than what I expect. What unit of measure I should use for the objects? What is the best practice for printing objects with GDI?
Any help would be pleasant.
Thanks in advance.

Your question is not very detailed and lacks code example of what you have so far, but anyways. It seems like you have issues setting up your print graphics. You would have to define how to map your graphics to e.g. 300dpi print document.
If you would just google for your question about how to print something with GDI+ you'll find tons of examples and tips like this
http://www.codeproject.com/Articles/2648/Printing-using-GDI-a-few-tips
:edit
if you have millimeter as unit, you can tell your graphics object to use it by defining
gr.PageUnit = GraphicsUnit.Millimeter;

crystal report would be your solution.

Related

WPF Printing Large Canvas over multiple Pages

I've got this problem:
I created a pretty large Canvas in WPF with a lot children.
I want to add a Print Button. PrintVisual seems not to work, because the image is to big. (I am using a scrollbar) I want to split the Canvas between multiple pages.
What i've done so far:
I am taking a Visual Brush for every part of the Canvas
Create a new Canvas and make the visual brush its background
Adding the new Canvas to a page, add the page to a FixedDocument.
Well, now i've got a FixedDocument and going to print it via printDocument.
The Problem is, that the whole process of printing takes a lot of time and sometimes it doesn't work at all. It's like there is a preprocessing step to convert the fixed document into a bitmap.
My Question: Is a Visualbrush in a Canvas to big? Should i convert the Canvas first into a bitmap?
I've found this great article: http://www.codeproject.com/Articles/339416/Printing-large-WPF-UserControls.
Whatever.
Is it a good way to convert a huge canvas into a bitmap first and then print parts of the bitmap? I could very well imagine, that one could get problems with blurring effects this way.
I've got also no idea how to add a bitmap to a page in wpf.
The worst thing is, that i couldn't found some really good sorces or a standardway (and i think there has to be one, cause this should be a pretty standard problem) for printing dynamic produced canvas in wpf.
I am really greatful for every really good source, help or code.
Thank you for your time.

Improving clarity of images in PictureBox C#

I have Panel on windows form containing labels for displaying information and 2 PictureBox controls. One for Company logo & other for captured photo. When i print them either on Printer or just save in PDF format, both images looking very blur. I want to improve quality of images. So they will appear clear even after zoom.
Any suggestion.
You can set this property of the Graphics object.
// g is type of Graphics.
g.InterpolationMode = InterpolationMode.High;
I don't know which technique you are using for printing but if you are using print form it is not good for decent picture or text. Therefore when you send form/PictureBox to the print object it would lose quality.The Solution is to use PrintDocument.
Share your code for more help.
Your printer has better resolution than your monitor. That bitmap won't work. You will have to recreate the print items directly on the e.Graphics of the PrintPageEventArgs.
Other work around is the technique that guy explain in his article.
http://www.dahuatu.com/3vy2K5z5mr.html

print winform screen

I have c# winform application.
I want to print all form objects, labels,textboxes etc..
Capture screen is not the solution for me because my form has scroll.
How can I do this?
Thanks.
A simple google search:
http://msdn.microsoft.com/en-us/library/aa287529%28VS.71%29.aspx
This just doesn't work. It is pretty inappropriate anyway, the resolution of the printer is much better than the resolution of your screen. The screenshot looks very ugly on paper, especially text gets blobby with the anti-aliasing pixels becoming painfully obvious.
Bite the bullet and drop the PrintDocument component on the form. You typically need to write a fair amount of code in the PrintPage event handler. But it isn't hard code and it will look great and you can make it look just the way you want it. Be sure to make it look like a report, not a screenshot. Use PrintPreviewDialog to avoid wasting a lot of paper. Report generators like RDLC and Crystal Reports are common solutions as well.
try this it will make a bitmap of your form `
Bitmap b = new Bitmap(this.Bounds.Width, this.Bounds.Height);
this.DrawToBitmap(b, new Rectangle(0,0,this.Width,this.Height));
b.Save("C:\\a.bmp");`
by this image you can print also rather than saving it...

Printing in C#/.NET, scaling on a whole page

I am wondering how to do the following ( couldn't get google to help me here ):
I got a .jpg file of about 250px*250px in scale..
I want this image on a DIN-A4 page as often as possible
I need an "overlay" for every image on the page with a unique code ( lets say a unique barcode for example )
How would i start here? I have really no idea which classes or methods to use for this...
Also it'd be interesting to know which "formats" i can create the documents in...
Thanks for any help!
Well, you know how big the image is, and how big the paper is, so it's easy to work out how many you can fit on a page.
Then you'll want to create an instance if the Bitmap class from your jpg, then get a Graphics object from the bitmap, call the Graphics object's DrawString method with your text (plus a font, a brush, and a point). Remember to release the Graphics object or, ideally, wrap it in a using statement.Then, as Henk says, use a PrintDocument to print it - there's an example here of that - and write your images in as required to fill the page using the PrintPageEventArgs' Graphics object.

GraphicsUnit.Point, isn't converting well to PDF... GraphicsUnit.World is, but how can I convert it to Point?

I have some code in .Net to draw some text content using GDI+. I used GraphicsUnit.Point to size the text. It's working wonderfully on-screen, and even if Print it.
I've been asked to make a system that generates a PDF, and I got ComponentOne's PDF control. It has got similar interface to GDI+.
The problem is: Font sizes are not working. If I use GraphicsUnit.Point, the text is much smaller, and I am getting empty space below the text. When I use GraphicsUnit.World, the text is still small, but there's no extra empty space below the text.
I want to understand how to convert GraphicsUnit.World to GraphicsUnit.Point.
All help will be appreciated.
Thanks
After some Googeling and from what I know from personal experience with GDI+ and String drawing it comes down to DPI (Dots per Inch). Basically the different devices (and as far as GDI+ is concerned, PDF is probably a device) have different DPI values. Displays usually have something like 70 DPI. Printers use 72. I don't know what PDFs use, but it might be 100 (as this is a common value for device independence and would explain the smaller text).
Now, Points are defined as being 72 DPI. This is always true. What GDI+ should do, when drawing to a PDF with a different DPI is, to transform the string drawing accordingly. But this does not always work, especially with text.
The GraphicsUnit.World should (according to some googeling) be device independent and should look the same on all devices.
You're right, GraphicsUnit.World looks the same on print, and also on screen. My final solution was to use GraphicsUnit.World as the unit of measure, and shun points. I still don't know the conversion ratio, but I approximated the value till the look was okay.
For my purpose this was enough.

Categories

Resources