Print any outside document from NAV

NagiNagi Member Posts: 151
Hello,

I'm trying to write code that will enable the user to select a document and print this from NAV. The document should not be opened, but sendt directly to the default printer.

I came across a topic on Mibuso that supposedly solves this issue, but I've been having some problems getting the code to work correctly.

http://www.mibuso.com/forum/viewtopic.php?t=7293

When I execute this code (or at least my version of it :oops: ), my only result is that the properties window for the selected file is opened.

Here is my full code;
OBJECT Form 50101 Print Any File
{
  OBJECT-PROPERTIES
  {
    Date=16.09.08;
    Time=13:24:08;
    Modified=Yes;
    Version List=NLO;
  }
  PROPERTIES
  {
    Width=7920;
    Height=1870;
  }
  CONTROLS
  {
    { 1101101001;TextBox;3630 ;220  ;4070 ;440  ;CaptionML=[ENU=Select a file;
                                                            NOR=Velg fil];
                                                 SourceExpr=PrintThisFile;
                                                 OnAssistEdit=BEGIN
                                                                PrintThisFile := CommonDialogMgt.OpenFile(Text001,'',1,'',0);
                                                              END;
                                                               }
    { 1101101002;Label  ;220  ;220  ;3300 ;440  ;ParentControl=1101101001 }
    { 1101101003;CommandButton;1540;990;2200;550;CaptionML=[ENU=Print File;
                                                            NOR=Skriv ut fil];
                                                 OnPush=BEGIN
                                                          CREATE(objShell);

                                                          IF NOT EXISTS(PrintThisFile) THEN
                                                            EXIT;

                                                          SplitDirFile(PrintThisFile,Dir,FileName);

                                                          objFolder := objShell.NameSpace(Dir);
                                                          objFolderItems := objFolder.Items;
                                                          objFolderItem := objFolderItems.Item(FileName);
                                                          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
                                                            objVerb.DoIt
                                                          ELSE
                                                            ERROR(Text002, PrintThisFile);

                                                          MESSAGE('Ferdig!');
                                                        END;
                                                         }
    { 1101101005;CommandButton;3960;990;2200;550;PushAction=Close }
  }
  CODE
  {
    VAR
      CommonDialogMgt@1101101002 : Codeunit 412;
      PrintThisFile@1101101013 : Text[250];
      Dir@1101101010 : Text[250];
      FileName@1101101012 : Text[250];
      objShell@1101101001 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{13709620-C279-11CE-A49E-444553540000}:'Microsoft Shell Controls And Automation'.Shell";
      Text001@1101101003 : TextConst 'ENU=Select a file...;NOR=Velg fil...';
      Text002@1101101004 : TextConst 'ENU=Could not print file %1.\Make sure you use a file extension you can print from Windows Explorer.;NOR=Kunne ikke skrive ut fil %1.\Det er kun mulig † skrive ut filtyper som kan skrives ut fra Windows Explorer.';
      objFolder@1101101005 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{BBCBDE60-C3FF-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.Folder";
      objFolderItems@1101101006 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{744129E0-CBE5-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.FolderItems";
      objFolderItem@1101101007 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{FAC32C80-CBE4-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.FolderItem";
      objVerb@1101101011 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{08EC3E00-50B0-11CF-960C-0080C7F4EE85}:'Microsoft Shell Controls And Automation'.FolderItemVerb";
      objVerbs@1101101009 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{1F8352C0-50B0-11CF-960C-0080C7F4EE85}:'Microsoft Shell Controls And Automation'.FolderItemVerbs";
      i@1101101008 : Integer;

    PROCEDURE SplitDirFile@1101101000(FullString@1101101000 : Text[250];VAR JustDir@1101101001 : Text[250];VAR JustFileName@1101101002 : Text[250]);
    VAR
      ExitLoop@1101101003 : Boolean;
      PointBreak@1101101004 : Integer;
    BEGIN
      ExitLoop := FALSE;
      PointBreak := STRLEN(FullString);
      WHILE (NOT ExitLoop) OR (PointBreak <= 1) DO
        IF COPYSTR(FullString,PointBreak,1) = '\' THEN BEGIN
          JustFileName := COPYSTR(FullString,PointBreak + 1);
          ExitLoop := TRUE;
        END ELSE
          PointBreak -= 1;

      JustDir := COPYSTR(FullString,1,PointBreak);
    END;

    BEGIN
    END.
  }
}

If anybody could help me with this I would be very grateful.

Answers

  • NagiNagi Member Posts: 151
    objFolder := objShell.NameSpace(Dir);
    objFolderItems := objFolder.Items;
    objFolderItem := objFolderItems.Item(FileName);
    objFolderItem.InvokeVerb('Print');  //Modified
    objVerbs := objFolderItem.Verbs;
    

    Okey, so I figured out where I had to modify the code to print the file. Now the file prints, but still the properties window of the file is displayed. Also, the file selected for printing is opened, printed, and then automatically closed. It would be better if the user never saw the file during the process.

    Can anybody help me? :-k
  • NagiNagi Member Posts: 151
    Does anybody know how to clear a verb in the InvokeVerb statement? For some reason, the 'Properties' verb seems to be invoked as default. How can I clear this verb? :-k :-k :-k
  • NagiNagi Member Posts: 151
    Solution, in case somebody is interested in it..
    OBJECT Form 50101 Print Any File
    {
      OBJECT-PROPERTIES
      {
        Date=17.09.08;
        Time=13:08:22;
        Modified=Yes;
        Version List=NLO;
      }
      PROPERTIES
      {
        Width=7920;
        Height=1870;
      }
      CONTROLS
      {
        { 1101101001;TextBox;3630 ;220  ;4070 ;440  ;CaptionML=[ENU=Select a file;
                                                                NOR=Velg fil];
                                                     SourceExpr=PrintThisFile;
                                                     OnAssistEdit=BEGIN
                                                                    PrintThisFile := CommonDialogMgt.OpenFile(Text001,'',1,'',0);
                                                                  END;
                                                                   }
        { 1101101002;Label  ;220  ;220  ;3300 ;440  ;ParentControl=1101101001 }
        { 1101101003;CommandButton;1540;990;2200;550;CaptionML=[ENU=Print File;
                                                                NOR=Skriv ut fil];
                                                     OnPush=BEGIN
                                                              IF ISCLEAR(objShell) THEN
                                                                CREATE(objShell);
    
                                                              IF NOT EXISTS(PrintThisFile) THEN
                                                                ERROR(Text003,PrintThisFile);
    
                                                              SplitDirFile(PrintThisFile,Dir,FileName);
    
                                                              objFolder := objShell.NameSpace(Dir);
                                                              objFolderItems := objFolder.Items;
                                                              objFolderItem := objFolderItems.Item(FileName);
                                                              objFolderItem.InvokeVerb('PRINT');
                                                              objVerbs := objFolderItem.Verbs;
    
                                                              CurrForm.CLOSE;
                                                            END;
                                                             }
        { 1101101005;CommandButton;3960;990;2200;550;PushAction=Close }
      }
      CODE
      {
        VAR
          CommonDialogMgt@1101101002 : Codeunit 412;
          PrintThisFile@1101101013 : Text[250];
          Dir@1101101010 : Text[250];
          FileName@1101101012 : Text[250];
          objShell@1101101001 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{13709620-C279-11CE-A49E-444553540000}:'Microsoft Shell Controls And Automation'.Shell";
          Text001@1101101003 : TextConst 'ENU=Select a file...;NOR=Velg fil...';
          Text002@1101101004 : TextConst 'ENU=Could not print file %1.\Make sure you use a file extension you can print from Windows Explorer.;NOR=Kunne ikke skrive ut fil %1.\Det er kun mulig † skrive ut filtyper som kan skrives ut fra Windows Explorer.';
          objFolder@1101101005 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{BBCBDE60-C3FF-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.Folder";
          objFolderItems@1101101006 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{744129E0-CBE5-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.FolderItems";
          objFolderItem@1101101007 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{FAC32C80-CBE4-11CE-8350-444553540000}:'Microsoft Shell Controls And Automation'.FolderItem";
          objVerbs@1101101009 : Automation "{50A7E9B0-70EF-11D1-B75A-00A0C90564FE} 1.0:{1F8352C0-50B0-11CF-960C-0080C7F4EE85}:'Microsoft Shell Controls And Automation'.FolderItemVerbs";
          i@1101101008 : Integer;
          Text003@1101101000 : TextConst 'ENU=Couldn''t find the file %1.\Please check that the path and filename is correct.;NOR=Fant ikke filen %1.\Vennligst sjekk at filstien og filnavnet er riktig.';
          Text004@1101101014 : TextConst 'ENU=PROPERTIES;NOR=EGENSKAPER';
          Text005@1101101015 : TextConst 'ENU=OPEN;NOR=PNE';
    
        PROCEDURE SplitDirFile@1101101000(FullString@1101101000 : Text[250];VAR JustDir@1101101001 : Text[250];VAR JustFileName@1101101002 : Text[250]);
        VAR
          ExitLoop@1101101003 : Boolean;
          PointBreak@1101101004 : Integer;
        BEGIN
          ExitLoop := FALSE;
          PointBreak := STRLEN(FullString);
          WHILE (NOT ExitLoop) OR (PointBreak <= 1) DO
            IF COPYSTR(FullString,PointBreak,1) = '\' THEN BEGIN
              JustFileName := COPYSTR(FullString,PointBreak + 1);
              ExitLoop := TRUE;
            END ELSE
              PointBreak -= 1;
    
          JustDir := COPYSTR(FullString,1,PointBreak);
        END;
    
        BEGIN
        END.
      }
    }
    
    [/code]
  • ajhvdbajhvdb Member Posts: 672
    Good work. This is working for me. :)
Sign In or Register to comment.