How can I print HTML files to a specified printer using shellexecute? - c#

I have an application that has records that can have a number of attachments associated to them, which may be a collection of JPG, TIF, PDF or HTM files (theoretically this list is arbitrary, and these are the most typical types).
One of the actions I need to be able to do is to allow these to be printed en mass to a specific printer.
For most file types, I can emulate the shell and perform the same action as had they dragged the file and dropped it onto a printer in explorer, by using the "PrintTo" verb, and using ShellExecute (via ProcessStartInfo); however, I've been scratching my head for a while wondering why this wasn't working for HTM files - instead it always prompts to select a printer for each file, even though the registry settings appear to be there for it.
It is when I went back to first principles, and checked to see if the shell behaves "properly" when I discovered that it behaves the same way (so, lets say you drag and drop any old HTML file onto a printer in explorer, it always prompts to print, defaulting the printer to be your default printer, even if that isn't the printer you dropped the file onto)
Now, it appears this behaviour was introduced in IE7 (whether intentionally, or not, I'm unsure); but is there any way of getting this to work as expected?
EDIT: This is for an internal application, so it would be permissible to fix up the registry if that would work.

You could use the webbrowser control and call the .Print() method. I just tested it and it went right to my default printer without prompting me. I know that might not be ideal, but I think it should get the job done.

Related

Embedding a font in a standalone exe

I want to create a console application but it will sometimes display a large amount of text that I will need to read. So I want to make it to use a custom font that will be more readable (for example like Roboto).
The problem is that firstly I want it to display it wherever the exe is launched (even if the computer doesn't have Roboto installed), and secondly I want the entire program to be a standalone exe, which means that including the font in a local folder and importing it is not an option.
I tried to search google and other forums but I couldn't find a solution that fits.
If anyone can think of a solution please do tell...

Copy a File Without a Confirmation Dialog

I have a video editing app. If a process completes then I would like to have the app copy the video to the user folder; however, if i use this command:
System.IO.File.Copy(TempVid, OutVid, True)
then Windows shows a copy dialog box. I would like a 'hidden' copy of the videos.
How can I copy the file without having a pop-up confirmation box appear?
There's nothing to stop you using more detailed calls to open both input and output files, continuously reading from one and writing to the other, stopping when the source file has been exhausted, then closing (or disposing of) both.
Granted it's a little more cumbersome than a simple File.Copy call but that's the price you may have to pay more greater control.
But you may want to check which calls you're actually using. From memory, the System.IO ones don't provide a dialog box, you have to use the FileSystem ones for that (such as here).
If you're absolutely sure you have enough memory to hold the entire file without issues, you can just use something like:
Dim MyFileContent() as Byte = File.ReadAllBytes (SourceFileName)
File.WriteAllBytes (DestFileName, MyFileContent)
But I tend to prefer the piecemeal (e.g., 1M at a time) to ensure your application doesn't fall to bits with truly huge files.

Filesystem Hook for .doc open C#

I'm writing an application that needs to be notified of every doc file that is opened, I've tried using the FileSystemWatcher but it seems that these days NotifyFilter.LastAccess is disabled due to a large overhead.
There is LastWrite which I suppose I could use but it would mean I'd need to try and figure out the original file name from the temporary file that word creates when it opens a document.
I also need to keep watch on 4 directories so ideally I don't want to be polling them.
I'm aware I could write a WordAddin which is one option but that means another deployment to manage, another codebase and another product to support along with the problem that many users always see addins as a source of slowdowns.
Is there a straightforward way to tell windows Vista upward that I want to know about doc or docx that is opened?
One thing I was wondering about is if I could alter the default program associated with .doc to mine, which is running as a service and then passing the details through it to mine to be opened? This seems like a bit of a hack so I was wondering if there was an easy way to hook into these sorts of file open?
UPDATE
From talking it through with various people here the most reliable way(and most resource effective) would seem to be to replace the existing file association for .doc. & .docx to my own program and then use Microsoft.Office.Interop.Word to launch word and then hook into the DocumentOpen event.
That way I get the file name thats being opened along with any future documents that are open in word.
If I recall correctly, the temporary file that is created in the same folder has the file name format of ~$ + filename, for example:
~$very_important_file.doc
It contains the name of the user that opened the file. Note that the file has the hidden attribute set.
This makes it quite easy to figure out which document is actually open and by whom.
Such tasks are usually accomplished using filesystem filter drivers. Procmon works this way. You can create your own filter driver or use the precreated one (eg. our CallbackFilter).

ASP.Net Print PDF directly to Printer With Preferences

I'm working on a project that requires us to send PDFs to a printing press. We've previously done this with a desktop app and Acrobat, but I'd like to switch to an ASP.Net app to give us more flexibility on what device the end user is using (there will likely only be one user at any given time).
Following something similar to this MS KB article is working well for sending the PDFs - the printer prints the documents, decent quality, etc.
The only issue I've found though, is that our files may require different printer configurations - e.g. one may need to be booklet folded, while the next may not.
Previously we had set these up in preconfigured drivers (i.e. "MyPrinter1" is set to booklet folded, "MyPrinter2" is not - both point to the same physical printer).
Sending the raw data, however, seems to ignore these. I'm assuming it's due to some header data not being included, or something similar; but I haven't found any info on how to include it.
I'm open to other methods. I've tried GhostScript, but it threw errors about the files. PDFSharp seems to work fine locally or while logged in to the web server, but doesn't do anything when logged out (not even an error message; assuming this is Adobe more than PDFSharp).
I'm potentially open to a paid option, but would (obviously) prefer free.
It's been a while and I forgot I had asked this question, but what we wound up doing was:
PdfView4Net (http://www.o2sol.com/pdfview4net/overview.htm) for opening the PDF and managing the print job.
Setting up default printing preferences for each configuration on the print server.
Making sure all printer configurations were installed for the same user as the service.

Server side printing of PDF files over the network installed Printers

Gone through the already existing posts on this topic, but my requirement is some what bit different.
Print jobs over the Network installed printers, upon a action in client side browser. Web server has got all printers in it, based on the client data, we need to print with client given configuration straight away, sending the job to printer(may be a different locations - but this is not a problem since the printers are in same network). I have seen printing architecture, Win32_print Class, SNMP, System.drawing.Printing, System.Printing.... but couldn't find the way to achieve this.. (Asp.net,C#)
-Files are been already existed in a server folder, just I need to pick up and send to a printer with client Selected Configuration...
update:I have to use JDF approach because all the files are PDF files. I am able to create JDF files with the selected configuration but sending this JDF to printer(JDF enabled) making me tough... There is JMF which post the JDF to printer, but not sure how to implement it.. still finding the ways, will be great if some one helps in this.
Something I can answer! 8-) I'm actually working on a project that uses this, right now.
Do not use Acrobat Reader as any sort of server application. It has a User Interface that will pop up on a screen that doesn't exist, at an unexpected time and freeze your app, waiting for a click that will never happen.
Use Ghostscript. Ghostscript is free, Open Source and will work perfectly for what you want. Out-of-the-box it consists of a DLL and a command line inhterface, however there is an API and a ton of different interfaces including .Net, and versions for both Windows and Linux.
On a more "overview" type of note, the reason you can drag a PDF into a printer on your workstation is because Acrobat Reader contains the code and hooks to allow this. Windows doesn't actually contain native functionality to print PDFs.

Categories

Resources