our company wants to print staff card for our personnel so we prepared a template which contains a placeholder for each person's photo, name and department.
we have a database table that includes path to photo, name and department of each person.
I would like to know if there is possibility to loop through that table and add person data into card template and save it.
I'm using C#.Net but if you know a better solution for this reason I'd be glad to listen.
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
This is no problem at all using C# and GDI+
Here is the short version:
Bitmap
of the right size and resolutionGraphics.DrawImage
andGraphics.DrawString
to create the graphicsPNG
as this will keep the text sharpHere come the details:
The Image you posted has no DPI setting and 1004x638 pixels; setting it to 150dpi results in a physical size of 170x108 mm. Let's assume that this is OK..
So we create a bitmap with these parameters:
Looking at your template we see 6 images (logo, photo and 4 icons) and 7 chunks of text (name, position, dept. and four contact texts).
The basic commands for drawing an image or a text with a
Graphics G
look like this:In our case this works fine for the logo and the photo since they are left aligned. All you need to do is to measure the positions and create the location points. Make sure you either create the images in the correct size&resolution or that you adapt the dpi to make up for differing pixel sizes!
Update: I have included code to adapt the photo's
dpi
to make the width fit in the 30mm frame in the template. This assumes that the proportions are correct and/or that we care more about the width than the height.. If we need to match both, either get the proportions right or ask for a cropping code ;-)Measuring the rest of our items is a little more complicated, since they all are right aligned. Here is an example how to do it for a string txt1:
You can (and must) measure the top (
Y
) of each location but the left (X
) must be calculated like above!Note that you need to tell the measurement command the font you want to use; ignore the other params! After measuring the right border these commands will work fine with the necessary data and graphics objects..
filename
dynamic with your records..4&5. See this code example:
I hope this gets you going. If you have questions, feel free to ask..
Here is the rudimentary result:
An afterthought: You may want to simplify the whole code by using the template as the start: You can have the logo, the icons and the vertical bar all in place and only need to draw one image and the texts..!
Okay, just an idea may not work, but I thought I would throw something out there to maybe help!
How about you create a program that does as you say , loops the database. But for the Staff cards create a User interface with like a GraphicsBox, and a few text boxes; Create/use a print function on the Ui, make the window borderless for the printout.
Im not sure if this would work as i use C++ and never really thought of doing something like this but i got this from the top of my head give it ago you never know!
But then you would obviously be printing to a high quality plastic i assume, or is it getting laminated? Not that is really matters just interested :)