跨平台打印尝试
作者:互联网
网站实现跨平台部署后怎么实现客户端打印环境跨平台支持呢。让客户端也能使用linux。先给linux安装cups-pdf虚拟打印机。然后尝试控制台打印。好使的画考虑把打印客户端也做DotNetCore网站当客户程序使用,用JS做桌面界面。
测试代码和效果
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Drawing.Printing;
using System.IO;
namespace PrintTest
{
class Program
{
static void Main(string[] args)
{
/// <summary>
/// 打印文档
/// </summary>
PrintDocument pdDocument = new PrintDocument();
//订阅BeginPrint事件
pdDocument.BeginPrint += new PrintEventHandler(pdDocument_BeginPrint);
//定义打印内容
pdDocument.PrintPage += new PrintPageEventHandler(OnPrintPage);
//訂閱EndPrint事件,释放资源
pdDocument.EndPrint += new PrintEventHandler(pdDocument_EndPrint);
pdDocument.Print();
Console.WriteLine("打印测试!");
string ii=Console.ReadLine();
}
/// <summary>
/// 绘制打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static private void OnPrintPage(object sender, PrintPageEventArgs e)
{
Font mFontMi = new Font("宋体", 16);
e.Graphics.DrawString("打印测试", mFontMi, Brushes.Black, 30, 30);
e.Graphics.DrawString("打印测试1", mFontMi, Brushes.Black, 30, 60);
e.Graphics.DrawString("打印测试2", mFontMi, Brushes.Black, 30, 90);
e.Graphics.DrawString("打印测试3", mFontMi, Brushes.Black, 30, 120);
e.Graphics.DrawString("打印测试4", mFontMi, Brushes.Black, 30, 150);
System.Drawing.Image img = System.Drawing.Image.FromFile(Path.Combine(AppContext.BaseDirectory,"1.jpg"));
e.Graphics.DrawImage(img, 30, 180, 200, 200);
e.HasMorePages = false;
}
/// <summary>
/// 开始打印
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void pdDocument_BeginPrint(object sender, PrintEventArgs e)
{
}
/// <summary>
///5、EndPrint事件,释放资源
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
static void pdDocument_EndPrint(object sender, PrintEventArgs e)
{
}
}
}
标签:尝试,打印,30,System,跨平台,pdDocument,mFontMi,Graphics 来源: https://blog.csdn.net/zhanglianzhu_91/article/details/116669526