View NAV RTC Report as PDF on a Webpage with Web Service
If you want to publish a PDF-report on an Intranet/Intranet site you can use the following instructions. The PDF is created on the fly and sends to the webpage via Web Services and parses to a PDF in memory before it reach the user, there are no need for temporary save the PDF on the web server before showing it. The same procedure can be used to publishing other binary files for example images, excel, word and simple text-files.
1. NAV. Create a function with 2 parameters.
Code
Get temp path, create some random file name. Filter out the Record set and use the record set as a parameter to REPORT.SAVEASPDF function. I use the TempBlob table to temporary save the PDF and then pass it to a BigText via DotNet library Array, Convertm MemoryStream. The Parameter PDF is marked as var and accepts new data and returns it to the system who consume the web service. Save the code unit and publish it as a Web Service, open table Web Service and add a line.
That’s all that has to be done in NAV.
2. C# ASP.net
As an example here is a simple way to test this. Software Visual Studio Web Developer Express 2010
1. Create project
2. Add web service reference
3. Enter the address to the web service, do not forget the Company name and the the name of the code unit, in my example PDFCUSTOMERLIST. Select a Web reference name and click add reference.
4. Strip down Default.aspx or create a new Web page. Insert a Form who posts to a new web page.
5. Create the new web page.
And if you lucky its works..
I found this pretty fast, it will not take much longer to show is at web then in RTC Client. You may want to edit your Service settings to make the session to live longer to avoid the “cold start feeling” each time the web service is called.
Files:
NAV fob: pdf_to_web.zip
Web Project: webproject.ZIP
Tags: NAV 2009