We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Display PDF in browser

In my Visual Studio 2010 MVC 3 app I am trying to use Syncfusion to take a Word document on disk, convert it to a Pdf and display the Pdf in the browser. I'm following the online sample at http://mvc.syncfusion.com/sfreportingmvcsamplebrowser/MVC/9.3.0.61/DocIO_MVC/Samples/4.0/ImportandExport/DOCtoPDF, which returns a PdfResult from the controller. Here is my simplified controller code, with my message continuing below it:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.Pdf;
using Syncfusion.DocToPDFConverter;

namespace DGPGMWeb.Controllers
{
public class ViewPdfController : Controller
{
public ActionResult ShowPdf()
{
FileStream stream = new FileStream("myfile.doc", FileMode.Open);
WordDocument doc = new WordDocument(stream);

DocToPDFConverter pdfconverter = new DocToPDFConverter();
PdfDocument pdfDoc = new PdfDocument();
pdfDoc = pdfconverter.ConvertToPDF(doc);

return new PdfResult(pdfDoc, "purchreq.pdf", HttpContext.ApplicationInstance.Response, Syncfusion.Pdf.HttpReadType.Open);
}
}
}

----------------

My project uses Syncfusion.Pdf.Mvc since Syncfusion.Pdf.Base does not include PdfResult. VS throws a compiler error on the line
pdfDoc = pdfconverter.ConvertToPDF(doc);

"Cannot implicitly convert type 'Syncfusion.Pdf.PdfDocument' to 'Syncfusion.Pdf.PdfDocument [c:\Program Files (x86)\Syncfusion\Essential Studio\9.3.0.61\Assemblies\3.5\Syncfusion.Pdf.Mvc.dll]'"

I think DocToPDFConverter wants a PDFDocument class from the .Base assembly. If I also reference .Base in the project, I get the error

"The type 'Syncfusion.Pdf.PdfDocument' exists in both 'C:\Program Files (x86)\Syncfusion\Essential Studio\9.3.0.61\assemblies\3.5\Syncfusion.Pdf.Mvc.dll' and 'C:\Program Files (x86)\Syncfusion\Essential Studio\9.3.0.61\assemblies\3.5\Syncfusion.Pdf.Base.dll'"

Any ideas on how to get this to work?


1 Reply

GM Geetha M Syncfusion Team September 8, 2011 12:13 PM UTC

Hi Jim,

Thank you for your interest in Syncfusion products.

DocToPDFConverter depends on Pdf.Base assembly. Could you please have Pdf.Base as reference instead of Pdf.MVC and make use of the PdfResult Extension classes in the sample application attached here to stream the output document to client?

F100817-1954218721.zip

Please let me know if you have any questions.

Regards,
Geetha


Loader.
Live Chat Icon For mobile
Up arrow icon