Finding the width of a string in c# when printing to a pdf document

Need to find the width of a string when printing to a pdf

Page 1 of 1

3 Replies - 3630 Views - Last Post: 12 November 2008 - 12:07 PM Rate Topic: -----

#1 TheGingerEffect   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-November 08

Finding the width of a string in c# when printing to a pdf document

Posted 12 November 2008 - 10:02 AM

Hello,

I am working on finding the width of a string before i put it in a pdf because i want to size the column appropriately.

I have tried:
 this.CreateGraphics();

but because I have no GUI I can't get the graphics object to do a MeasureString() method with the graphics object.

I have tried:
TextRenderer.MeasureText();


but text renderer is underlined in red with no option to import it. I assume this is because i have no form and dont intend to get one.

This post has been edited by TheGingerEffect: 12 November 2008 - 10:03 AM


Is This A Good Question/Topic? 0
  • +

Replies To: Finding the width of a string in c# when printing to a pdf document

#2 eclipsed4utoo   User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Finding the width of a string in c# when printing to a pdf document

Posted 12 November 2008 - 10:19 AM

if you are the one that created the string, then you can use..

string test = "this is only a test";
int length = test.Length;



"length" would be 19.
Was This Post Helpful? 0
  • +
  • -

#3 PsychoCoder   User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1659
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: Finding the width of a string in c# when printing to a pdf document

Posted 12 November 2008 - 10:21 AM

I believe she's trying to get the length (in Pixels) to make sure each lines fits on the page she's printing. Let me see if I can come up with a solution for you :)
Was This Post Helpful? 0
  • +
  • -

#4 TheGingerEffect   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 12-November 08

Re: Finding the width of a string in c# when printing to a pdf document

Posted 12 November 2008 - 12:07 PM

View PostPsychoCoder, on 12 Nov, 2008 - 09:21 AM, said:

I believe she's trying to get the length (in Pixels) to make sure each lines fits on the page she's printing. Let me see if I can come up with a solution for you :)


PsychoCoder is right, I need to figure out the width of a string in pixels so i can print it into a chart in a pdf document and align the column appropriately.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1