Print files with an associated application

detlef
Member Posts: 38
Hi
I am looking at writing a function that takes a filename as parameter. This function would then print the file as setup in the registry for that particular file type. (These types are setup under Folder options, File Types)
Is there an easy way of doing this?
Any help appreciated.
Cheers
Detlef
I am looking at writing a function that takes a filename as parameter. This function would then print the file as setup in the registry for that particular file type. (These types are setup under Folder options, File Types)
Is there an easy way of doing this?
Any help appreciated.
Cheers
Detlef
0
Comments
-
I think that it will be not so easy... because many application are not able to automatically print document... (because you have no way how to say them - print this file...)0
-
Taking one file type, how would you print a pdf file, for example one stored in a BLOB?0
-
I'm struggling with the same problem.
I have a blob field, which contains a file (extension can be a number of things). I would like to print this file to a pdf file and send through email.
I think the solution is to make a print-procedure for every possible extension (.doc, .xls, .pdf, ...).
any suggestions?0 -
May be that you need something like http://www.softpedia.com/get/System/OS- ... ware.shtml
I did not test it, I only found it on google... may be that there is some interface to this or some similar application...0 -
Looks like the only way to do this is to read the registry, run the specified shell command and then optionally send dde messages (Office documents use dde). This must be, what Windows Explorer does, too (if you right-click and select print).0
-
Just finished my app. What I did:
- Export BLOB field to file name (extension is in attachment table).
- validate extension:
- if .doc: use word automation
- if .xls: use excel automation
- if .mpp: use project automation
- ...
- convert to pdf with amyuni
- open mail message with pdf document
may be not the best way to do it, but it works like a charm!0 -
But you can drag almost any filetype to the printer window, and then it will print the file using the right appliction. There must be a way to do the same using some API...Regards
Peter0 -
Well, to be honest, I think it works internally different then what you think.
You notice that when you right click on different files in explorer, sometimes you get the "print" functionality, sometimes you don't get it. So it depends on the filetype whether you can print the file or not.0 -
Good news. I've found a way to do it!
The following Function is using Automation Objects from 'Microsoft Shell Controls And Automation' (Shell32).
PrintFile( FileName : Text[250])
CREATE(objShell);
IF NOT EXISTS(FileName) THEN
EXIT;
SplitDirFile(FileName,Dir,File);
objFolder := objShell.NameSpace(Dir);
objFolderItems := objFolder.Items;
objFolderItem := objFolderItems.Item(File);
objVerbs := objFolderItem.Verbs;
i:=-1;
REPEAT
i+=1;
IF i<objVerbs.Count THEN
objVerb := objVerbs.Item(i);
UNTIL (STRPOS(UPPERCASE(objVerb.Name),'PRINT')>0) OR (i >=objVerbs.Count);
IF i<=objVerbs.Count THEN BEGIN
objVerb.DoIt;
END ELSE
ERROR('Could not print file %1\Make sure you use a file extension you can print from Windows Explorer', FileName);
This works fine. But now I have the next problem:
What I want to do is print several files into one PDF file using Amyuni and then email the file.
objVerb.DoIt; will do the printing but it does it asynchronus.
I need to find a way to find out when the printing is finished so I can pick up the pdf file and attach it to an email.
If I put a sleep(5000) command after all the PrintFile calls it actually delays the printing.
The only way I can think of is using the timer and check if the datetime on the file has not changed in x seconds. I hate using the timer! it stuffs up debugging.
Anybody got any ideas?
Cheers
Detlef0 -
I would like to convert a html-file to pdf using Amyuni so we don't need yet another component.
Did you find a solution to the problem?Regards
Peter0 -
I've tried your above code and it seems to work for everything but word documents - it will open the word Application, but doesnt even open the file.
Anyone taken this any farther?0 -
Anybody wants to share the code of functions SplitDirFile function
Thanks0 -
Thank u "Detlef", you're awesome, it worked like a charm still0
-
thanks! this helped me tremendously in printing a PDF file!kind of fell into this...0
-
Works great
Unfortunatly the solution is not language independant (or even setup independant).
So the only warning I could give is go to the file you want to print, right click it and see if you which command you can use to print it. Replace the 'PRINT' text in the code with the command specified.
Nevertheless thank you!0 -
You could make an OCX or DLL exposing Windows' ShellExecute API function, then use that as an automation variable from NAV to call it with the 'print' option.0
-
What I am missing here? It's not working for me. I have added a below code to Report-On Post Report trigger. I want to print the Terms pdf file immediately to purchase order print. When I click on PO -> Print, I'm getting only the PO report page out, not the terms page.
PrintThisFile := 'D:\Terms.pdf';
IF ISCLEAR(objShell) THEN
CREATE(objShell);
SplitDirFile(PrintThisFile,Dir,FileName);
objFolder := objShell.NameSpace(Dir);
objFolderItems := objFolder.Items;
objFolderItem := objFolderItems.Item(FileName);
objFolderItem.InvokeVerb('PRINT');
objVerbs := objFolderItem.Verbs;0 -
Below is the code I have used in the PrintFile function:
FileName := 'E:\OrderDetails.pdf'; Dir := 'E:\'; File := 'OrderDetails.pdf'; CREATE(objShell); IF NOT EXISTS(FileName) THEN EXIT; //SplitDirFile(FileName,Dir,File); objFolder := objShell.NameSpace(Dir); objFolderItems := objFolder.Items; objFolderItem := objFolderItems.Item(File); objVerbs := objFolderItem.Verbs; i:=-1; REPEAT i+=1; IF i<objVerbs.Count THEN objVerb := objVerbs.Item(i); UNTIL (STRPOS(UPPERCASE(objVerb.Name),'PRINT')>0) OR (i >=objVerbs.Count); IF i<=objVerbs.Count THEN BEGIN objVerb.DoIt; END ELSE ERROR('Could not print file %1\Make sure you use a file extension you can print from Windows Explorer', FileName);
The function runs but their is no print initiated. Kindly suggest what could be the problem in my code? I am stuck ](*,)
Awaiting for the responses. Thank u all in advance..Dilip
Falling down is not a defeat..defeat is when you refuse to get up.0 -
Your code won't work if PRINT is the last option. I'll suggest you replace
IF i<=objVerbs.Count THEN BEGIN
withIF STRPOS(UPPERCASE(objVerb.Name),'PRINT')>0 THEN BEGIN
(Untested - it just seemed wrong)
Edit: Not true - my bad...Regards
Peter0 -
Try to debug with
FileName := 'E:\OrderDetails.pdf'; Dir := 'E:\'; File := 'OrderDetails.pdf'; CREATE(objShell); IF NOT EXISTS(FileName) THEN EXIT; //SplitDirFile(FileName,Dir,File); objFolder := objShell.NameSpace(Dir); objFolderItems := objFolder.Items; objFolderItem := objFolderItems.Item(File); objVerbs := objFolderItem.Verbs; i:=-1; REPEAT i+=1; IF i<objVerbs.Count THEN BEGIN objVerb := objVerbs.Item(i); IF CONFIRM(objVerb.Name) THEN; // debug purpose END; UNTIL (STRPOS(UPPERCASE(objVerb.Name),'PRINT')>0) OR (i >=objVerbs.Count); IF i<=objVerbs.Count THEN BEGIN objVerb.DoIt; END ELSE ERROR('Could not print file %1\Make sure you use a file extension you can print from Windows Explorer', FileName);
0 -
Hi Peter,pdj wrote:Your code won't work if PRINT is the last option. I'll suggest you replace
IF i<=objVerbs.Count THEN BEGIN
withIF STRPOS(UPPERCASE(objVerb.Name),'PRINT')>0 THEN BEGIN
Any idea resolving the same would be very thankful..
Awaiting for the reply.Dilip
Falling down is not a defeat..defeat is when you refuse to get up.0 -
Now I have tried your code, and I think I know your problem. First of all I got a compilation error with the variabel File, as it is a reservered word. That indicated you have translated your code to English for Mibuso 8)
But that leads to the next problem. I guess you are not using an English PDF reader, and therefore the menu-item in the pdf-file context-menu-item does not contain "PRINT". In my case I had to change it to "UDSKRIV" which is Danish for PRINT.
The reason for your code showing the Properties window, is that it is the last menu-item. My original suggestion should prevent that, but then you just get the error below :?
I'll suggest you add this line to troubleshoot:MESSAGE('%1: %2',i,objVerb.Name);
just before the UNTIL line...
There doesn't seem to be a language independent solution to this problem, so you will need some way to determine which text to look for at the specifik users setup. It could be different for each file-extension for each user. ](*,)Regards
Peter0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions