If I have adobe reader installed, is it possible to programmatically print the document to a specific printer without having adobe reader or the printer dialog display (no user intervention)? Any code snippets or sugestions are helpful. I can use any version of the .net framework to accomplish this
No, it is not. IIRC, you can tell acrobat reader to print the document for you via the command line. But when you do it's going to prompt you via the gui to tell it what printer to use.
Edit:
Hmm, maybe you can do it almost silently. Check this link:
http://support.adobe.com/devsup/devsup.nsf/docs/52080.htm
Found via this old answer:
Send document to printer with C#
Used to do this back in the novell print queue days so it should at least work in theory. If you can figure out a way to convert the PDF into postscript you can then stream it to a postscript printer and print that way.
Related
I searched houres about, how I can print a pdf silently from C# including AcroJs.
I know there are solutions for it, like starting AdobeReader as Process by CommandLine and Print the document. (http://www.codeproject.com/Tips/598424/How-to-Silently-Print-PDFs-using-Adobe-Reader-and)
But this solutions always open the Reader. Even if you can hide the window,depending on the speed of your computer, you can see the adobe reader window a few seconds. I need a workaround which doesn't open the reader but process the AcroJS forms in pdf jut like the normal reader.
Do you konw any alternatives oder libs, that I can use?
How do I print PDFs silently with procesing AcroJS and wthout open the Adobe Reader process in c#?
Thanks :)
Your application need to be built using the Adobe Reader OCX or some PDF library. Then, the application needs to be configured to use a default printer. It can then be issued commands to print documents without showing a window.
In the advanced print settings inside adobe acrobat reader, I have noticed that there is a print to file option. I am currently developing a library of functions in vb.net that prints files of various formats to print language files (postscript). I can't seem to find however a way to access this functionality programmatically, is there a way to do this without using a third party tool as I need to try and avoid using external libraries if at all possible.
You can use the PrintDocument class to print to a PostScript printer on the FILE: port. PostScript print drivers are provided with Windows by default. An example is HP LaserJet 2800 PS, which is provided with Server 2008. Generally if it has PS in the name the printer will be able to print to file.
https://learn.microsoft.com/en-us/dotnet/api/system.drawing.printing.printersettings.printtofile
...
printDocument1.PrinterSettings.PrintToFile = true
printDocument1.PrinterSettings.PrintFileName = "c:\temp\test.ps"
printDocument1.Print()
I tried this example from MSDN in an ASP.NET MVC project:
public void Print(string printQueueName, string printData)
{
PrintQueue printerQueue = new LocalPrintServer().GetPrintQueue(printQueueName);
// Call AddJob
PrintSystemJobInfo myPrintJob = printerQueue.AddJob();
// Write a Byte buffer to the JobStream and close the stream
Stream myStream = myPrintJob.JobStream;
Byte[] myByteBuffer = UnicodeEncoding.Unicode.GetBytes(printData);
myStream.Write(myByteBuffer, 0, myByteBuffer.Length);
myStream.Close();
}
I tried to print to PDF, XPS and OneNote virtual printers. After confirming printing dialog, printing job appears in printer queue then disappears, and the printed file is created, but with 0 byte size!!!
I don't know where is my fault, and hope to find help here.
Thanks in advance.
The example here which is close to MSDN does not work on my printer either. It's irrelevant because this example is not sufficient to print PDF or XPS as one cannot simply output a byte stream of these types as a stream to the printer. You have at least a few options:
Use PrintDocument. Convert the PDF/TIFF/Possibly onenote files to Images (E.G. tiff files) and you can print with this class using the event PrintDocument.PrintPage and Graphics.DrawImage.
Use/Buy 3rd party print API's for PDF. You can get away with direct XPS printing, but it's got some issues (see details below). OneNote I don't know.
Print the files via the command line using Process
Write your own print drivers
Further Details
I'm not familiar with OneNote printing. XPS printing can be quite tricky. The margins need to be calculated in code because they depend on the printer settings which can be found in the PrintTicket. Using WPF (which is closely tied to XPS) there's a bug I discovered somewhere in the XPS serialization process. XpsDocument does not preserve the calculated printable area. Documents will print with default printable areas which can result in cut off. I confirmed this bug on Microsoft Connect. See their response below.
Finally, if you just happen to be running SSRS then you can easily change the output type from PDF/XPS to image.
Feedback for XPS bug on Microsoft Connect (link is private):
Title: XpsDocument does not preserve the calculated arrangement for WPF's >FixedPage.Arrange()
The WPF team has recently reviewed this issue and will not be
addressing this issue as at this time the team is focusing on the bugs
impacting the highest number of WPF developers. If you believe that
this was resolved in error, please reactivate this bug with any
necessary supporting details.
We appreciate the feedback. However, this issue will not be addressed
in the next version of WPF. Thank you. –WPF Team
.
I need to take a PDF file url, send it as a parameter to a web service that will print it on a network printer. It has to be done server side without any user interaction.
Do you know some libraries that we can use to acheive that ? We look at different options like iTextSharp but it looks like there's no way to print from that library.
Thanks.
If you can download the file and save it as a PDF and have Acrobat Reader installed you can use a command line to print it (shell it).
http://www.robvanderwoude.com/commandlineswitches.php#Acrobat
Print a PDF file silently:
AcroRd32.exe /N /T PdfFile PrinterName [ PrinterDriver [ PrinterPort ] ]
It would be nice to know what commercial component you used...
I had to something like that, but using PCL. We used winspool.drv to open the printer, start a document then a page, write out the bytes, then end the page & document and close the printer. We installed PCL drivers for the printer on the local machine to print to a network printer.
You might be able to do something like that with Postscript drivers. A quick test would be to to a binary copy of a PDF to the printer using the command prompt and the /B switch on copy. I think you specify the PDF and the printers network share as source/destination. Use a small PDF to avoid getting a ream of random characters in case it doesn't work.
We'll finally use a commercial component that does all this by itself.
Thanks for your help.
With C#, how can I print a PDF document (without any dialog boxes in the background) to an indicated printer?
I have used the following PDF library in the past to perform batch printing of PDF documents from a C# Windows Service.
http://www.quickpdflibrary.com/
It's a pretty decent library and if I remember correctly it only took a few lines of code to print the document. It worked very well and saved me a consider amount of time.
Also, the recommended link that discusses using DDE to launch a desktop application on a server to perform the printing is a bad idea. Adobe Reader probably doesn't support this and since it is a desktop application running in a windowless session you may run into problems with message boxes and dialog boxes. That solution just doesn't scale in my humble opinion.
here we go
Disclaimer: I work for Atalasoft
If you don't want to depend on Acrobat being on the server, you need to rasterize the PDF pages yourself and send them to the printer using the normal .NET printing API. We have a product that can rasterize PDF that uses the Foxit engine underneath. It deploys as a normal .NET assembly and doesn't require any other software to be installed.