SAVEASPDF and DOWNLOAD Function

bmccarthybmccarthy Member Posts: 48
edited 2009-12-21 in NAV Three Tier
Can I use Report.SAVEASPDF to save the pdf file from the RTC client side??? If I say call

SAVEASPDF(C:\temp\test.pdf) from a menu item in a page then it is saved server side.

If I use DOWNLOAD to copy the file from the server to the client then I am forced to ask the user where to save it. The DOWNLOAD function wants me to specify a dialog caption etc to ask the user where you save it.

Is there a way to save a report to pdf client side from the RTC???

Also, as a side line can I force the SAVEASPDF running of the report to display the request form?

Cheers

Comments

  • ara3nara3n Member Posts: 9,255
    Saveaspdf stores it on service tier. To send something client, you can save using '\\computername\C$\temp', or you save it to a shared drive. Or use an automation and instantiate it at the client stream the file across.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • Kerem_KiziltuncKerem_Kiziltunc Member, Microsoft Employee Posts: 10
    Is there a way to save a report to pdf client side from the RTC???

    You can export a report to a pdf or Excel file when you preview the report in the RoleTailored Client.

    This does not require any C/AL code as an end-user can now export a report to either format from the toolbar in the report preview window.
    “This posting is provided "AS IS" with no warranties, and confers no rights.”
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    Saveaspdf stores it on service tier. To send something client, you can save using '\\computername\C$\temp', or you save it to a shared drive. Or use an automation and instantiate it at the client stream the file across.
    Unfortunately you cannot create streams across the servicetier boundry.
    You have three options (which I can think of) for copying a file from the service tier to the client tier:
    1. Save to a share as suggested (either on the client computer or on a common file share) - but this might cause problems of various kinds and is really not suggested
    2. If you just need to show the file at the Client Tier, you can use FILE.DOWNLOAD and the user can select what to do - save/open etc.
    3. If you need to attach the file to something and you don't want user interaction you again have two options (that I know of)
    3.a. Read my blog post http://blogs.msdn.com/freddyk/archive/2008/11/04/transferring-data-to-from-com-automation-objects-and-webservices.aspx and make some code that works for you
    3.b. Use FILE.DOWNLOAD with the "magic" folder name <TEMP> - which suppresses user interaction and saves the file to a temporary folder with a temporary name.

    The following code:
    toFile := 'test.txt';
    if FILE.DOWNLOAD('c:\test.txt', '', '<TEMP>', '', toFile) THEN
    begin
      Message(toFile);
    end;
    
    Saved my test.txt in the following local file:

    C:\Users\freddyk\AppData\Local\Temp\Microsoft Dynamics NAV\9216\__TEMP__400f0b09d731435aad67af8c25e83378.txt

    Which as you can see contains a GUID - so it will change.
    You get this name (including full path) back in toFile (var parameter) - and you can use that to send to a Client Side COM component (maybe Outlook) to attach this file.
    Only "small" problem is that the name is rather stupid (and I guess the name is used if you attach a file to outlook) - so if you need test.txt, you will have to create a small Client side COM object if you want to rename this on the Client tier before attaching to a mail.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • freddy.dkfreddy.dk Member, Microsoft Employee Posts: 360
    BTW. a function to do that could look like this:
    /// <summary>
            /// Renames a temp file, created by FILE.DOWNLOAD in order to have a filename, that can be used for attaching to outlook etc.
            /// After this call filename.EndsWith(newfilename) is true.
            /// </summary>
            /// <param name="filename">Full path and filename of the temp file. This will contain the new file name (incl. path) after the call</param>
            /// <param name="newfilename">file name only of the new file</param>
            public void RenameTempFile(ref string filename, string newfilename)
            {
                // Just to ensure that newfilename doesn't contain ..\..\xxx
                if (newfilename.Contains(@"\"))
                    return;
                string path = System.IO.Path.GetDirectoryName(filename) + @"\" + Guid.NewGuid().ToString() + @"\";
                System.IO.Directory.CreateDirectory(path);
                System.IO.File.Move(filename, path + newfilename);
                filename = path + newfilename;
            }
    
    The client will remove temporary files and directories when you shut down.
    If you want to remove the file on the client after usage you would need to create a function to do that - but unless the Client is running 24/7 or your temp files are large, that shouldn't be necessary.
    Freddy Kristiansen
    Group Program Manager, Client
    Microsoft Dynamics NAV
    http://blogs.msdn.com/freddyk

    The information in this post is provided "AS IS" with no warranties, and confers no rights. This post does not represent the thoughts, intentions, plans or strategies of my employer. It is solely my opinion.
  • bmccarthybmccarthy Member Posts: 48
    Thanks you for such a detailed response. That should do the trick for us. =D>
  • matteo_montanarimatteo_montanari Member Posts: 189
    nabritta wrote:
    What is the fastest way to convert a book into a PDF file? I recently purchased a Sony Portable Reader System (PRS-505 RED). I have TONS of books I would like to scan to PDF and to OCR. Would it be quicker to scan these books one page at a time? Or would it be better to use a camera and take snapshots of each page (if so, what camera would you recommend)? In short: What's the quickest way to change a book into a PDF file?

    where is the connection with Navision?

    Matteo
    Reno Sistemi Navision Developer
  • TonyHTonyH Member Posts: 223
    Eto wrote:
    nabritta wrote:
    What is the fastest way to convert a book into a PDF file? I recently purchased a Sony Portable Reader System (PRS-505 RED). I have TONS of books I would like to scan to PDF and to OCR. Would it be quicker to scan these books one page at a time? Or would it be better to use a camera and take snapshots of each page (if so, what camera would you recommend)? In short: What's the quickest way to change a book into a PDF file?

    where is the connection with Navision?

    Matteo


    HA HA! Way too funny... :lol:
  • BeliasBelias Member Posts: 2,998
    -Mirko-
    "Never memorize what you can easily find in a book".....Or Mibuso
    My Blog
Sign In or Register to comment.