【问题标题】:How can I create a multi page Tiff file from a large string value如何从大字符串值创建多页 Tiff 文件
【发布时间】:2014-01-22 18:14:21
【问题描述】:

我有以下代码,它接受一个字符串并创建一个 Tiff 文件。

string sFileData = "Hello World";
string sFileName = "Bitmap.bmp";

Font oFont = new Font("Arial", 11, FontStyle.Bold, System.Drawing.GraphicsUnit.Pixel);
var sz = GraphicsHelper.MeasureString(sFileData, oFont);

var oBitmap = new Bitmap((int)sz.Width, (int)sz.Height);

using (Graphics oGraphics = Graphics.FromImage(oBitmap)) {
    oGraphics.Clear(Color.White);
    oGraphics.DrawString(sFileData, oFont, new SolidBrush(System.Drawing.Color.Black), 0, 0);
    oGraphics.Flush();

}

oBitmap.Save(sFileName, System.Drawing.Imaging.ImageFormat.Tiff);

public static class GraphicsHelper {
    public static SizeF MeasureString(string s, Font font) {
        SizeF result;
        using (var image = new Bitmap(1, 1)) {
            using (var g = Graphics.FromImage(image)) {
                result = g.MeasureString(s, font);
            }
        }
     return result;
    }
}

当字符串的宽度和高度不超过 A4 页面的大小时,这可以正常工作。但是我现在遇到的问题是,我需要能够将此 Tiff 打印到打印机。

因此,我需要一种将任何文本包装到 A4 页面宽度的方法,如果高度超过 A4 页面的高度,则需要将文本转移到下一页。

谁能提供我如何实现这一目标的任何示例?

【问题讨论】:

    标签: c# text image-manipulation tiff


    【解决方案1】:

    您已经在测量字符串并且知道 A4 的大小,所以我认为您的问题是您不知道如何创建包含多个页面的 TIFF。

    如果是这样,请查看类似问题的答案:

    https://stackoverflow.com/a/7675996/3937

    结果是使用 Bitmap.SaveAdd() 将图像添加到现有 TIFF

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多