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.
Related
I have requirement to create virtual printer which used to register my printer in the printer drive ,Whenever my printer invoked it should generate PDF file for respective page . I had created and invoked my printer functionality,here comes the problem,i could not find how to convert temp file(.PS) to PDF file or any image file.Please let me know if anyway I cld achieve this....
Thanks in advance,
Vinod
You need to find a library that will convert from PS to PDF for you. A quick Google shows that there are libraries available, but they may not be free. It's up to you to go and look for yourself now to see if any suit your requirements.
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 need an algorithm that converts any file format to its .PRN file equivalent which will be compatible for a specific printer (for example, only in CANON printers).
Or I need a source code or way to know how printer drivers work. Printer drivers are the one who specifies or creates the .PRN file of any type. So please help me. Thanks!
Since you said, from any format to .prn format, I am taking two cases here assuming Windows environment:
Let's say your source is MS_WORD (.doc) file. If you have the appopriate printer installed, you can easily get the .prn file, by opening the file in MS-WORD and doing print using the appropriate printer. However, before this, set the port to "File" in Control Panel for the particular driver.
However assuming you have a file in some xyz format, for which there is no rendering application needed, you may have to identify a converter on a case to case basis probably
Consider dowloading the windows driver kit (WDK), it has free printer driver sample code,
you can find the full list of sample code it has here. Also, you can look at the printer driver docs here
I'm not sure if this is possible but as I was looking for a way to convert docx -> pdf serverside (Aspose is a bit expensive), I wondered if I could do this by printing my document to a Pdf Printer.
Altho, I would need a decent one then, as it shouldn't show dialogs when trying to print ofc.
Does anyone know if:
This is possible
There exists such a printer which can be easily used in a WCF Service
Thanks
Try pdfcreator.
PDFCreator is a free tool to create PDF files from nearly any Windows application.
Key Features:
Create PDFs from any program that is able to print
...
Terminal Server: PDFCreator also runs on Terminal Servers without problems
If you can read DOCX content and print from your WCF service, the pdfcreator printer driver will generate PDF from anything.
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.