【发布时间】:2019-05-19 00:49:12
【问题描述】:
如何截取我的 Windows 窗体程序的屏幕截图并保存为 pdf ???
我试过这个代码:输出是一个白页
// generate a file name as the current date/time in unix timestamp format
string file = (string)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds.ToString();
// the directory to store the output.
string directory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
PrintDocument doc = new PrintDocument()
{
PrinterSettings = new PrinterSettings()
{
// set the printer to 'Microsoft Print to PDF'
PrinterName = "Microsoft Print to PDF",
// tell the object this document will print to file
PrintToFile = true,
// set the filename to whatever you like (full path)
PrintFileName = Path.Combine(directory, file + ".pdf"),
}
};
doc.PrintPage+= new PrintPageEventHandler(PrintImage);
CaptureScreen();
doc.Print();
【问题讨论】:
-
因为您实际上并没有保存任何东西?您需要将屏幕截图保存到文件(.jpg、gif 等),然后打印该文件
标签: c# .net forms pdf printing