3
다음 코드는 문자열을 사용하고 Tiff 파일을 만듭니다.큰 문자열 값에서 다중 페이지 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 페이지의 높이를 초과하면 텍스트를 다음 페이지로 가져와야합니다.
아무에게도 어떻게 달성 할 수있는 예를 제공 할 수 있습니까?