c# - Calculate PDF page height and width -


i've checked around , see potential solutions question, plus have potential solution i'll explain in question, i'm going try , reach angle. i'm using pdf4net convert computer output laser disc (cold) documents pdf. these cold documents plain text, not appear on standard page sizes (ie. letter, tabloid, legal, etc...) , i'm not able pull page size information document itself. causes issue, when tried convert them portrait (8.5 x 11) page, single line may end wrapping on next line. want able avoid this.

here knowns use when try convert document:

  1. cold document - know length of longest line of characters , know number of lines on page.
  2. font - resulting pdf document courier size 10
  3. margins - margins can vary each document have available
  4. dpi - 72 (pdf's default dpi)

with these knowns determine length longest line of characters with:

size textsize = textrenderer.measuretext(longestline, new font("courier", 10, fontstyle.regular, graphicsunit.point)); 

i use textsize.width set pdf page height & width, creating square page. "appears" keep text wrapping, there lot of white space on right side , bottom of page.

question:

is there better way calculate height , width of pdf page, given knowns, text can fit without having white space? if there more information needed in better calculation, other information needed? goal create document of such size no lines wrap , margins same around.

i think width in pixels provided textrenderer assumes definition of 96 dpi.

int pagewidth = textsize * 72 / 96 + 2*margin ; 

look if graphics (gdi+) returns different width textrenderer (gdi).

graphics graphics = graphics.fromimage(new bitmap(1, 1)); sizef size = graphics.measurestring(text,myfont) ; 

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

python - How to remove the Xframe Options header in django? -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -