Printing PDF directly from server...

M

Matt

I am using Process.Start() and pdfp.exe to launch Adobe Reader to
print PDFs directly from the server. My website's Application Pool
runs under a domain account and I am having trouble getting the
permissions right. It works when I add the domain account to the web
server's administrators group, but this isn't something I want to do
in production. Any ideas on how to give the domain account the
correct permissions without adding it to the Admins group? TIA ~
Matt ... Code follows...

public static void PrintPdfForm(System.Type builderType, string
inPath,
string outDir, DataSet formData, string printer) {

string outPath = outDir + Guid.NewGuid().ToString() + ".pdf";
IPdfFormBuilder builder;
try {
builder = Activator.CreateInstance(builderType) as
IPdfFormBuilder;
builder.BuildForm(inPath, outPath, formData);
string pdfpPath =
Mcrcsip.Amwa.PdfFormHandler.Properties.Settings.Default.PdfpPath;
string args = "-p \"" + printer + "\" " + outPath;
RunExecutable(pdfpPath, args);
} catch (Exception ex) {
throw PdfFormException.GetException(
"Caught exception in
Mcrcsip.Amwa.PdfFormHandler.PrintPdfForm().", ex);
} finally {
if (System.IO.File.Exists(outPath)) {
try {
System.IO.File.Delete(outPath);
} catch (System.IO.IOException) {
}
}
}
}

private static void RunExecutable(string executable, string
arguments) {
ProcessStartInfo starter = new ProcessStartInfo(executable,
arguments);
starter.CreateNoWindow = true;
starter.RedirectStandardOutput = true;
starter.UseShellExecute = false;
Process process = new Process();
process.StartInfo = starter;
process.Start();
StringBuilder buffer = new StringBuilder();
using (StreamReader reader = process.StandardOutput) {
string line = reader.ReadLine();
while (line != null) {
buffer.Append(line);
buffer.Append(Environment.NewLine);
line = reader.ReadLine();
Thread.Sleep(100);
}
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top