简体   繁体   English

从C#中的多行文本框中生成Tiff文件

[英]Generating tiff file from a multi-line text box in C#

I am writing info entered on a web form into a tiff file. 我正在将在Web表单上输入的信息写到tiff文件中。 My issue is where the comment box comes into play for the web form. 我的问题是Web表单的注释框在哪里起作用。 The comment box is multi-line and when writing it on to the tiff file, some of the information entered into the comment box falls out of the tiff image. 注释框是多行的,将其写入到tiff文件时,输入到注释框中的某些信息会从tiff图像中消失。

The code for how I am trying to write it to the tiff file:- 我试图将其写入tiff文件的代码:-

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000); //Creates Bitmap
Graphics g = Graphics.FromImage(bitmap);
g.DrawString("Comment: " + CommentBox.Text, outputFont, Brushes.Black, new PointF(0, 700)); // Writing the text from the comment box on to the Tiff file.

so what that means to me is, if I am writing a multi line comment as:- 所以这对我来说意味着,如果我将多行注释写为:

"Hello Testing. “你好测试。

Hello Testing again and again and again and again and again and again and again. 你好,一次又一次,一次又一次,一次又一次。

Hello Testing again and again and again and again and again and again and again. 你好,一次又一次,一次又一次,一次又一次。 Hello Testing again and again and again and again and again and again and again." 你好,一次又一次,一次又一次,一次又一次。

My tiff-file captures line elements only upto the 1000 width, the elements beyond that width do not automatically get generated in a new line. 我的tiff文件仅捕获最大1000宽度的线元素,超过该宽度的元素不会自动在新行中生成。

Can anyone help me with this? 谁能帮我这个? ideas? 想法?

Try something like this - you can use the overload of DrawString that takes a containing rectangle, and the text should wrap within that: 尝试类似的事情-您可以使用DrawString的重载,该重载包含一个包含矩形,并且文本应在该矩形内换行:

System.Drawing.Bitmap bitmap = new System.Drawing.Bitmap(800, 1000); //Creates Bitmap
using(Graphics g = Graphics.FromImage(bitmap))
{
   RectangleF rect = new RectangleF(new PointF(0, 700), new SizeF(200,200)); // adjust these accordingly for your bounding rect
   StringFormat drawFormat = new StringFormat();
   drawFormat.Alignment = StringAlignment.Near;
   g.DrawString("Comment: " + CommentBox.Text, outputFont, Brushes.Black, rect, drawFormat); // Writing the text from the comment box on to the Tiff file.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM