这是基本前提:
我的用户点击了一些小玩意儿,一个PDF文件被吐出到他的桌面上.我有办法将此文件发送到打印机队列并将其打印到本地连接的打印机吗?
string filePath = "filepathisalreadysethere";
SendToPrinter(filePath); //Something like this?
Run Code Online (Sandbox Code Playgroud)
他会多次这样做.对于教室里的每个学生,他必须打印一张小型成绩单.所以我为每个学生生成一个PDF,我想自动化打印过程,而不是让用户生成pdf,打印,生成pdf,打印,生成pdf,打印.
有关如何处理此问题的任何建议?我在Windows XP上使用Windows Forms .NET 4运行.
我发现这个StackOverflow问题,其中接受的答案表明:
创建文件后,可以通过命令行打印它们(可以使用System.Diagnostics命名空间中的Command类)
我怎么做到这一点?
从我正在构建的应用程序中,我需要打印现有的PDF(由另一个应用程序创建).如何在C#中执行此操作并提供一种机制,以便用户可以选择其他打印机或其他属性.
我看过PrintDialog,但不确定它试图打印什么文件,如果有的话,b/c输出总是一个空白页面.也许我只是错过了一些东西.
我是否需要使用"iTextSharp"(如其他地方所建议的那样)?这对我来说似乎很奇怪,因为我可以"将文件发送到打印机"我手边没有任何好的对话框来设置打印机等.我真的不想从头开始编写打印对话框但似乎我通过搜索找到的很多例子都是这样的.
任何建议,示例或示例代码都会很棒!
此外,如果PDF是问题,文件可以由另一个应用程序以差异格式创建,如位图或png,如果这使事情更容易.
我有以下代码:
using System;
using System.Diagnostics;
using System.IO;
using PdfSharp.Pdf.Printing;
namespace PrintPdfFile
{
class Program
{
[STAThread]
static void Main(string[] args)
{
// Set Acrobat Reader EXE, e.g.:
PdfFilePrinter.AdobeReaderPath = @"C:\\Documents and Settings\\mike.smith\\Desktop\\Adobe Reader 9.0.exe";
// -or-
//PdfPrinter.AdobeReaderPath = @"C:\Program Files\Adobe\[...]\AcroRd32.exe";
//// Ony my computer (running a German version of Windows XP) it is here:
//PdfFilePrinter.AdobeReaderPath = @"C:\\Documents and Settings\\mike.smith\\Desktop\\Adobe Reader 9.0.exe";
// Set the file to print and the Windows name of the printer.
// At my home office I …Run Code Online (Sandbox Code Playgroud) 我目前正在使用以下代码使用Foxit Reader软件打印pdf。现在我的问题是我想打印一个文件的多个副本。任何人都可以让我知道如何在以下代码中打印pdf时指定份数。
[编辑] 我不想使用循环来打印pdf的多个副本。我只想将其指定为命令行参数。
任何帮助表示赞赏:)
Process process = new System.Diagnostics.Process();
process.EnableRaisingEvents = false;
process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = foxitReaderInstalledPath;
string arguments = String.Format(@"-t ""{0}"" ""{1}""", this.Path, printerName);
process.StartInfo.Arguments = arguments;
process.Start();
process.WaitForExit();
Run Code Online (Sandbox Code Playgroud)