Printing PDF directly from server...

Discussion in 'ASP .Net' started by Matt, Feb 28, 2007.

  1. Matt

    Matt Guest

    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);
    }
    }
    }
     
    Matt, Feb 28, 2007
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ellie
    Replies:
    1
    Views:
    535
    Andrew Thompson
    Jul 20, 2004
  2. Replies:
    7
    Views:
    3,947
    venkat.sadasivam
    Nov 5, 2008
  3. Ricardo Pog
    Replies:
    1
    Views:
    457
    Austin Ziegler
    Mar 26, 2008
  4. Sean Nakasone
    Replies:
    1
    Views:
    406
    Farrel Lifson
    Apr 14, 2008
  5. Aqua
    Replies:
    1
    Views:
    132
    Rick Nakroshis
    May 10, 2004
Loading...

Share This Page