Help printing files with custom extensions after association

About the programming interface for the virtual PDF printer driver.

Moderator: jr

Help printing files with custom extensions after association

Postby denious » Wed Feb 08, 2012 6:14 pm

Hello,

I have downloaded Bullzip PDF Printer in hopes of finally resolving my long-wished-for requirement of printing files of any extension that I can open.

Manually printing documents seems to function well. However, I have noticed numerous limitations in terms of printing from code (I am using .NET 4).

For example:
1. Create a new file called customFile.cf
2. Associate .cf to Notepad
3. Open customFile.cf, add some content to it, save and close
4. Try printing to PDF

Error: Win32Exception - No application is associated with the specified file for this operation

Notice that .cf has been associated to Notepad, a simple, Microsoft program. The same error occurs when trying to print document associated to any "custom" program, for example Photoshop CS5.
Performing the same exact steps for .txt files works like a charm. What gives?

Here's the code I am using in my C# application:

// get reference to selected file
var fileInfo = new FileInfo(openFileDialog1.FileName);

// set runonce pdf printer settings
var settings = new PdfSettings { PrinterName = "Bullzip PDF Printer" };
settings.SetValue("output", fileInfo.FullName.Replace(fileInfo.Extension, ".pdf"));
settings.SetValue("showsettings", "never");
settings.SetValue("showpdf", "no");
settings.SetValue("confirmoverwrite", "no");
settings.WriteSettings(PdfSettingsFileType.RunOnce);

// request file to be printed to pdf
PdfUtil.PrintFile(fileInfo.FullName, "Bullzip PDF Printer");

I am working on Windows 7 x64.

Is there something I am missing? Is there a workaround?

Thank you.
denious
 
Posts: 1
Joined: Wed Feb 08, 2012 5:45 pm

Re: Help printing files with custom extensions after associa

Postby admin » Sun Feb 12, 2012 5:16 pm

Normal associations between file extensions and programs are for the "open" verb. This means that you tell the system which program to use when you double click a file and wants to open it. It is a different kind of association you need to use for the "print" verb. If you right click a .doc file and have Microsoft Word installed then you will see a print command in the context menu. Only file types with a "print" association will work with the PrintFile command on the PdfUtil assembly and COM object.

The print verb is associated with a program (and often a command line argument) in the registry.
admin
 
Posts: 58
Joined: Fri Oct 28, 2011 8:09 pm

Re: Help printing files with custom extensions after associa

Postby ccanning » Wed May 16, 2012 11:40 pm

I am receiving the same error message when trying to print .msg files through C#. The code is the posted sample code, I only changed the print and output locations to point at the files I wanted. When right clicking on an msg file it prints just fine but I receive this error when doing it through C#:

Error: Win32Exception - No application is associated with the specified file for this operation

Other office files and image files are working fine. Anyone have any ideas?
ccanning
 
Posts: 2
Joined: Wed May 16, 2012 11:35 pm


Return to Programming

Who is online

Users browsing this forum: No registered users and 2 guests

cron