Knowledgebase: RAD PDF
Using RAD PDF with MVC
Posted by Chris (Staff), Last modified by Chris (Staff) on 07 May 2015 08:27 PM

While RAD PDF is primarily intended for use with ASP.NET's Web Forms, RAD PDF can be used with MVC as well. Because RAD PDF doesn't rely upon PostBacks, ViewState, or other Web Forms specific technologies, usage is pretty straightforward.

Attached to this article is sample code for using RAD PDF with MVC 3, MVC 4, or MVC 5 and Razor. Simply create a "Bin" directory in the root of the project and add the "RadPdf.dll" from the RAD PDF installation directory (typically C:\Program Files\RAD PDF\WebControl\).



Attachments 
 
 cs_mvc3.zip (56.16 KB)
 cs_mvc4.zip (56.19 KB)
 cs_mvc5.zip (56.79 KB)

Comments (20)
Wajahat
01 September 2012 11:09 AM
Hello,

We are working mvc and want to implement rad pdf in mvc we have implement the rad pdf in mvc with help of this article.


It is working but client api is not available in mvc. could you please guide us that how we register client api in mvc view.

Thanks

Regards
Wajahat
Chris Truxaw
05 September 2012 02:12 PM
RAD PDF's Client API can be used in ASP.NET with MVC. As shown in the example, it is important that the view layout's <HEAD> element contain the line of code:
@Html.Raw(RadPdf.Web.UI.PdfWebControl.RenderHead())

If you have additional questions, please open a support ticket at http://support.redsoftware.com/
Julius Hutzler
30 July 2013 06:02 PM
In the MVC Project, is the client side API available. Error is encountered when providing the "OnClientLoad" event on the control. How can I detect when the PdfWebControlApi object is available?
Red Software
31 July 2013 10:04 AM
Hi Julius,
The "OnClientLoad" event should work just fine in MVC. Most likely, the JS code needed for this to work simply wasn't added to the page's header using the .RenderHead() method (as WebForms is able to add this automatically for developers).

To assist you further, please provide the source code for page in question and open a support ticket at http://support.redsoftware.com/
Kamal
08 January 2014 04:53 AM
Hi

I am trying to save the filled pdf using MVC. Please can you tell how to save the document with other elements in the form.

Thanks.
Red Software
08 April 2014 11:05 AM
Hi Kamal,

Saves occur the same way in MVC as they do in Web Forms (e.g. via the GUI, Client API, etc).

Obviously though, with MVC, the PdfWebControl's Web Forms Saved event won't fire.

Instead, you should use one of the following methods for getting the saved document:
(1) Use a RAD PDF PdfIntegrationProvider to hook into when RAD PDF is performing a save. Here, you can be notified when a document has been saved and then update whatever storage location you wish. For more information, see:
http://www.radpdf.com/radpdfdocumentation/?topic=html/8fa200e5-72ae-1749-51ef-f1a42886c9a7.htm

(2) Use the PdfStorageAdapter to retrieve the PDF document as currently saved in the RAD PDF database. For more information, see:
http://www.radpdf.com/radpdfdocumentation/?topic=html/bb3b76dc-050d-4b08-be8c-47b3469d6de9.htm
or
http://www.radpdf.com/radpdfdocumentation/?topic=html/db1e83ac-4b87-bd8b-291b-480186af16e3.htm
This can also be done via the PdfWebControl if you prefer, see:
http://www.radpdf.com/radpdfdocumentation/?topic=html/9b28ec52-a5b4-adcc-60b1-a806979a1939.htm
Kamal
08 January 2014 05:00 AM
Hi

I am trying to save the filled pdf document using MVC. Please can you tell how to save the document with other details in the page.
Red Software
08 January 2014 01:20 PM
Hi Kamal,

Saves occur the same way in MVC as they do in Web Forms (e.g. via the GUI, Client API, etc).

Obviously though, with MVC, the PdfWebControl's Web Forms Saved event won't fire.

Instead, you should use one of the following methods for getting the saved document:
(1) Use a RAD PDF PdfIntegrationProvider to hook into when RAD PDF is performing a save. Here, you can be notified when a document has been saved and then update whatever storage location you wish. For more information, see:
http://www.radpdf.com/radpdfdocumentation/?topic=html/8fa200e5-72ae-1749-51ef-f1a42886c9a7.htm

(2) Use the PdfStorageAdapter to retrieve the PDF document as currently saved in the RAD PDF database. For more information, see:
http://www.radpdf.com/radpdfdocumentation/?topic=html/bb3b76dc-050d-4b08-be8c-47b3469d6de9.htm
or
http://www.radpdf.com/radpdfdocumentation/?topic=html/db1e83ac-4b87-bd8b-291b-480186af16e3.htm
This can also be done via the PdfWebControl if you prefer, see:
http://www.radpdf.com/radpdfdocumentation/?topic=html/9b28ec52-a5b4-adcc-60b1-a806979a1939.htm
dilpreet
17 January 2014 06:18 PM
How would this work on a mobil device like iphone? Will iphone be able to render the pdf using this reader or will iphone needs to install/download something?
Red Software
18 January 2014 09:31 AM
Yes RAD PDF will work on a mobile devices like the iPhone. An iPhone does NOT need to have any software installed. The RAD PDF viewer will work natively with Safari.
Soeren Dalby
19 February 2014 04:53 AM
I have this project up and running. It needed some adjustments in order to run in VS 2014.

I can start the project and the page renders correctly but it keeps "Loading" the page and I cannot switch to page 2 or to the other demo document.

What can cause this?
Red Software
19 February 2014 10:18 AM
Without additional information, it's hard to be certain what the issue here is.

It sounds like the RAD PDF System Service either:
* Is not properly installed using the RAD PDF installer
* Is not running
or
* Does not have the proper permissions to connect to the RAD PDF database

For one of these reasons (most likely the third), the content of the PDF's pages are not being rendered and placed in the database. Because of this, the document stays in the "Loading..." state.

I'd recommend going through our troubleshooting guide. It will explain RAD PDF System Service setup issues as well as where to get the full error message for RAD PDF issues like this (in the Windows Event Log). Please see:
http://www.radpdf.com/RadPdfDocumentation/?topic=html/75619e37-2a95-4803-b3e7-69fbe53d3cae.htm

If our above recommendations don't resolve this issue for you, please open a support ticket and provide the full error message from the Windows Event Viewer. We will then be able to much better assist you.
Søren Dalby
19 February 2014 08:28 AM
I have tried to integrate your RAD PDF in an existing MVC5 project - I am reusing the code from your MVC3 sample project.

When I try to instantiate the PdfWebControl using:

PdfWebControl pdfWebControl1 = new PdfWebControl();

I get following error:

An exception of type 'System.TypeInitializationException' occurred in RadPdf.dll but was not handled in user code

Additional information: The type initializer for 'RadPdf.RadPdfCommonWeb' threw an exception.

TIA

Best regards
Soeren Dalby
Red Software
20 February 2014 10:40 AM
Hi Soeren,

Thanks for your interest in RAD PDF.

We do have an MVC5 sample that we are working on, but isn't yet available on our website. Please contact us at support@redsoftware.com to open a ticket and request assistance using RAD PDF with MVC5.
Mala Alagh
02 June 2014 02:47 PM
I am using MVC3 code in MVC 4.0 and got the same error mentioned above

"The type initializer for 'RadPdf.RadPdfCommonWeb' threw an exception.".

Please help me to resolve this.
Red Software
03 June 2014 10:16 AM
Hi Mala,

Without the full error message / stack trace, it is hard to say for certain. Typically though, this error is raised when the PdfIntegrationProvider can not be loaded. Please check the value of the "RadPdfIntegrationProvider" entry in the "appSettings" section of your web.config file.
Dharmendra Jha
26 November 2014 11:43 PM
We had implemented RAD PDF with MVC 4.0 and it's working. But sometime we are getting an exception "System.OutOfMemoryException". Can you please help us?
Red Software
27 November 2014 08:16 AM
Hi Dharmendra,

Thanks for your interest in RAD PDF. It sounds like you ma be running out of system memory when running RAD PDF. But to help you officially diagnosis and fix the issue, please open a support ticket with us at http://support.redsoftware.com/
Tony
04 March 2015 01:21 PM
Does RadPDF not work with certain versions of Adobe Acrobat. When I attempt to load some PDFs that has been edited with Adobe Acrobat the PDF will not load. It just sits on the page with the Loading... in the PDF control.
Red Software
05 March 2015 11:07 PM
Hi Tony, this is likely a common misconfiguration. We'd love to help you further with this.

Please open a support ticket with us at http://support.redsoftware.com