gpt4 book ai didi

c# - 自动将 PDF 打印到特定打印机和纸盘

转载 作者:行者123 更新时间:2023-12-02 11:25:13 25 4
gpt4 key购买 nike

我有一个 C# 应用程序,当用户单击“打印”时,该应用程序使用 ITextSharp 在内存流中创建 PDF。我需要将此 PDF 自动打印到特定的打印机和托盘。我已经搜索过这个,但我能找到的只是使用 javascript,但它不会打印到特定的托盘。有人有这样做的例子吗?谢谢。

最佳答案

您可以使用此代码更改打印机托盘。

string _paperSource = "TRAY 2"; // Printer Tray
string _paperName = "8x17"; // Printer paper name

//Tested code comment. The commented code was the one I tested, but when
//I was writing the post I realized that could be done with less code.

//PaperSize pSize = new PaperSize() //Tested code :)
//PaperSource pSource = new PaperSource(); //Tested code :)

/// Find selected paperSource and paperName.
foreach (PaperSource _pSource in printDoc.PrinterSettings.PaperSources)
if (_pSource.SourceName.ToUpper() == _paperSource.ToUpper())
{
printDoc.DefaultPageSettings.PaperSource = _pSource;
//pSource = _pSource; //Tested code :)
break;
}
foreach (PaperSize _pSize in printDoc.PrinterSettings.PaperSizes)
if (_pSize.PaperName.ToUpper() == _paperName.ToUpper())
{
printDoc.DefaultPageSettings.PaperSize = _pSize;
//pSize = _pSize; //Tested code :)
break;
}

//printDoc.DefaultPageSettings.PaperSize = pSize; //Tested code :)
//printDoc.DefaultPageSettings.PaperSource = pSource; //Tested code :)

关于c# - 自动将 PDF 打印到特定打印机和纸盘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4808125/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com