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.

PDF2

Variables pdf2.PNG

Code

PDF1

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.

pdf3.PNG

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

pdf4.PNG

2. Add web service reference

pdf5.PNG

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.

pdf6.PNG

4. Strip down Default.aspx or create a new Web page. Insert a Form who posts to a new web page.

pdf7.PNG

5. Create the new web page.

pdf8.PNG

6. Time for test.

pdf9.PNG

And if you lucky its works.. :-)

pdf10.PNG

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:

Leave a Reply

*
To prove you're a person (not a spam script), type the security text shown in the picture. Click here to regenerate some new text.
Click to hear an audio file of the anti-spam word