c# - 当我使用drawing.printing打印pdf文档时,pdf文档存在字节不足
问题描述
当我打印文档时,文档变成这样: https ://gyazo.com/1b0ba3daf5b6ac8435c70adb822feaae
我已经以这种方式将其发送到打印机,但打印机打印我喜欢这样。
我在互联网上搜索了一些解决方案,但我一无所获。我从 Windows 站点获得此代码。
我已经尝试了很多,但我的想法已经用完了,我在互联网上找不到任何东西
//print function
for (int i = 0; i < 1; i++)
{
try
{
streamToPrint = new StreamReader(FilePath);
try
{
printFont = new Font("Arial", 10);
PrintDocument pd = new PrintDocument();
pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
pd.PrinterSettings.PrinterName = printers;
pd.Print();
}
finally
{
streamToPrint.Close();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
//print page function
private void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
float linesPerPage = 0;
float yPos = 0;
int count = 0;
float leftMargin = ev.MarginBounds.Left;
float topMargin = ev.MarginBounds.Top;
string line = null;
// Calculate the number of lines per page.
linesPerPage = ev.MarginBounds.Height /
printFont.GetHeight(ev.Graphics);
// Print each line of the file.
while (count < linesPerPage &&
((line = streamToPrint.ReadLine()) != null))
{
yPos = topMargin + (count *
printFont.GetHeight(ev.Graphics));
ev.Graphics.DrawString(line, printFont, Brushes.Black,
leftMargin, yPos, new StringFormat());
count++;
}
// If more lines exist, print another page.
if (line != null)
{
ev.HasMorePages = true;
else
ev.HasMorePages = false;
}
}
解决方案
推荐阅读
- python - /brooklyn/beachs 的 Django TypeError
- sql - 使用 PostgreSQL 计算年同比增长
- python - 齿轮下的命令不显示
- unity3d - 将 CAD(步骤 .stp)文件拆分为单独的部分,然后可以将其导入 Unity 并相对于彼此移动?
- anylogic - AnyLogic:具有不同优先级的两个客户类别
- google-apps-script - Google Script - 将二维数组的一部分应用于工作表
- android - 带有 Gradle 7 的 CMake 二进制目录
- mysql - 根据同一张表的结果优化选择表中的所有行?
- python - 在 Python 中创建一个以特定方式重新排列其他列表的新列表
- python - 使用python PIL批量平铺图像,按文件夹重复填充背景图像