![](/img/trans.png)
[英]Is it possible to create a base64 string which has all frames of a multi page tiff file?
[英]How can I create a multi page Tiff file from a large string value
我有以下代码,它接受一个字符串并创建一个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页面的高度,则需要将文本转移到下一页。
任何人都可以提供我如何实现这一目标的任何例子吗?
您已经在测量字符串并知道A4的大小,因此我认为您的问题是您不知道如何创建包含多个页面的TIFF。
如果是这样,请查看类似问题的答案:
https://stackoverflow.com/a/7675996/3937
结果是使用Bitmap.SaveAdd()
将图像添加到现有TIFF
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.