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.
Unfortunately, activation email could not send to your email. Please try again.

Display PDF in browser

Thread ID:

Created:

Updated:

Platform:

Replies:

100818 Sep 7,2011 02:42 PM Sep 9,2011 12:24 AM ASP.NET Web Forms (Classic) 5
loading
Tags: PDF
Administrator [Syncfusion]
Asked On September 7, 2011 02:42 PM

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?


Geetha M [Syncfusion]
Replied On September 8, 2011 08:14 AM

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


Administrator [Syncfusion]
Replied On September 8, 2011 12:55 PM

Thanks! That worked perfectly.


Administrator [Syncfusion]
Replied On September 8, 2011 03:23 PM

One more question - Do you know any way to get the pdf to open in a new window rather than replacing the current view?


Administrator [Syncfusion]
Replied On September 8, 2011 05:49 PM

Never mind, I was being stupid. Just needed to set the submit target to "_blank".

Thanks for your help, I love your product!


Geetha M [Syncfusion]
Replied On September 9, 2011 12:24 AM

Hi Jim,

Thank you for the update.

Please let us know if you have any further questions.

Regards,
Geetha


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;