0

I need to take a spreadsheet and convert it into a price tag. I've done that part but I'm not to sure how to go about making an image that contains both the price an item name (This is all stored in a list.) Then lay it out on a 8 1/2 x 11 piece of paper.

I read this question here but its using the size of the text, which may vary depending on the name of the item. The TextBox (Or whatever is holding the text) needs to be the same size but have the text scale based on its size.

Nitish Kumar Diwakar
  • 663
  • 4
  • 14
  • 25
  • What are you targetting: Winforms, WPF, ASP..? __Always__ tag your question correctly! – TaW Aug 03 '17 at 09:57
  • What shall the output be? A Png file or paper? You may want to study [this post..](https://stackoverflow.com/questions/28560319/generate-staff-card/28580657?s=1|1.9174#28580657) – TaW Aug 03 '17 at 09:58

1 Answers1

2

Take a look at these docs, in particular their example pd_PrintPage function. This takes a PrintPageEventArgs which contains a Graphics object that you can use to actually render your tag.

In particular, to leverage your linked question, there is a DrawImage(Image, Int32, Int32) method that renders the given image at a co-ordinate.

To handle scaling your text, you just need to compare how big your text would be with one font to how big you want it - work out the ratio of width/height, then scale the font you use to render so that it uses the smallest of those ratios. There's a good answer here which shows how to do that.

So:

  1. Handle a print event
  2. Find the right font size
  3. Create your image
  4. Print with your graphics object

I would do a mockup of the resulting code, but I don't have access to a C# IDE at the moment.

hnefatl
  • 5,860
  • 2
  • 27
  • 49