Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing PDF From web server

Status
Not open for further replies.

asmith555

Programmer
Oct 7, 2002
97
US
I have an app written in asp.net. I need it to print several pdf's with no user interaction. I need to be able to select the printer as well. I have tried shelling adobe reader but there is a permissions issue I cant seem to get around. This works when I run it locally but not when I deploy it to a web server. Does anyone know of a way to do this. Here is the code I have:

Dim oProcSI As New System.Diagnostics.ProcessStartInfo("C:\Program Files\Adobe\Acrobat 4.0\Reader\AcroRd32.exe")
oProcSI.Arguments = "/t """ & PDFLocation & """ """ & DefaultPrinter & """"
oProcSI.CreateNoWindow = True
oProcSI.RedirectStandardOutput = True
oProcSI.UseShellExecute = False

Dim oProc As New System.Diagnostics.Process
oProc.StartInfo = oProcSI
oProc.Start()
 
A printer on the web servers network. The client machines printer will be stored in a database and accesed as the printer input for this app. All the client printers will be set up as network printers
 
OK, in that case it's just a question of figuring out what permissions aren't correct on your web server (if the above code is correct and works as you expect). So, what are the differences between your local machine and the server? Are they the same version of windows?


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244.
 
When I run the app in debug(WebDev.Webserver.exe) it works fine when I run it from my local box(aspnet_wp.exe) via it doesn't work. I have set the app up to use impersonation of a higher user and set the processmodel in the machine.config to execute under a higher username. I have also set the ASPNET user to the administrators group on the local box. Bottom line it seems to execute under Webserver.exe running under my NT Login Name but not under aspnet_wp.exe running under a local admin login.
 
Also. Acro reader is started and visible in the task manager. I guess that perhaps the local Admin does not have any printers set up for it as opposed to my NT Login name.
 
I am using impersonation from the web.config. Also what is the ASPNET/NETWORK SERVICE user.
 
Yes the ASPNet and Network Service all have full rights to all relevant folders
 
I was not getting any errors. However I think I have made some progress. When I set the ProcessModel of the machine.config to use my NT Loginname It seems to work. Do I need to set up a domain account for the aspnet_wp to run under? as opposed to ASPNET
 
OK I came accross a problem. I have to remained logged in to the web server with the identity I am running the worker process under to print. Is there anyway around this. This may have something to do with the access to the printer drivers
 
your client machine and the server are two distinct boxes. printers are configured to the local box/username so the printers on your local box may not be available on the server.

this works while you're developing because your local box is the server so the printer is available.

I would recommend streaming the pdf to the client and have the client search/print/view the report.

in it's crudest form you would
[ol]
[li]open file with a stream[/li]
[li]load stream into byte array[/li]
[li]configure response headers (file type, size, name, attachement or inline)[/li]
[li]write bytes to response.[/li]
[/ol]
now the user can view the report on the local box with AdobeReader and can view/print/search the document as needed.

If you go this route there is a "feature/bug" with IE6 and AdobeReader. You can only view the file as an attachment (not inline). This means the use would be prompted to Open, Save, Cancel the report.

this can be remendied by
using a different browser(IE7, FireFox, Opera) with AdobeReader.
installing Adobe Acrobat to use with IE6.
allowing the user to response to the Open, Save, Cancel options.

here is a simple code sample if your interested
Code:
//AS[b]H[/b]X
<%@ WebHandler Language="C#" Class="WebApplication1.Handler1" %>
namespace WebApplication1
{
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            string fileName = context.Request.QueryString["filename"];
            if(File.Exists(fileName))
            {
                byte[] bytes;
                using (Stream reader = new StreamReader(fileName))
                {
                    bytes = new byte[reader.Length];
                    reader.Read(bytes, bytes.Length);
                }
                context.Response.Clear();
                context.Response.ContentType = "application/pdf";
                context.Response.AppendHeader("Content-Length", bytes.Length.ToString());
                context.Response.AppendHeader("Content-Disposition", "attachment;filename=myfile.pdf");
                context.Response.BinaryWrite(bytes);
                context.Response.Flush();
                context.Response.End();
            }
        }

        public bool IsReusable { get { return true; } }
    }
}
then you can access the report like this: Handler1.ashx?filename=C:\myFile.pdf


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
OK here is the situation.
I have created a domain acct called "DOMAIN\ASPNETPROC"
I have my application running under a new application pool called NetPool. I have set the NetPool Identity to "DOMAIN\ASPNETPROC" I have added "DOMAIN\ASPNETPROC" to the IIS_WPG group. I logged on to the server as "DOMAIN\ASPNETPROC" and set up the nessasary printers for the users. When a user logs on it pulls thier info from a database one field of that user info is called "DefaultPrinter" This is the printer they will print to which have all been set up under "DOMAIN\ASPNETPROC" on the web server. If I log on to the web server via remote desktop as "DOMAIN\ASPNETPROC" the users can use the app and printing works great. If I log off of the web server the users can use the app but it will not print. No errors are generated. I guess what I am asking is why does "DOMAIN\ASPNETPROC" have to be logged into the web server for the printing to work.
 
I have been struggling with a similar issue. I have a web service that I want to have print a file. The solution that seems to be working is to create a local printer on the webserver. Then point this local printer to the address of the network printer. So far this is working.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top