Welcome Guest Search | Active Topics | Sign In | Register

MVC Multiple PDF's and merging Options
Stephen
Posted: Wednesday, October 8, 2014 11:02:14 AM
Rank: Newbie
Groups: Member

Joined: 10/8/2014
Posts: 2
Hiya

I am evaluating EO.pdf prior to purchasing a company license. I need to produce an MVC that produces a single pdf from different views.

I am using converturl to merge into the same PDF Document. I looked at the RenderAsPDF and the post function but I could see no way of using that to get pdf output from different views and then merge them in the one post.

I am having an issue with the second convert it says "The given remote host was not resolved". The first convert works fine into the PdfDocument but any subsequent converturl fails with this error, even if the second url is a repeat of the first one (I did that as a test even though the second url exists if I copy and paste into through browser). I am running on a dev machine at the moment so web server and development code is running on same box so can be no actual host problems.

Here is the code..

public ActionResult Print(Guid id)
{
var model = PdsfServiceManager.LoadSubmitted(id);

PdfGen.SetRenderAsPdfOptions(Request);

var ms = new MemoryStream();
var submissionUrl = String.Format("http://urll/{0}/Home/PrintSubmission", id);

var doc = new PdfDocument();
HtmlToPdf.ConvertUrl(submissionUrl, doc);

//merge in any data centres
foreach (var dc in model.DataCentres)
{
var dcUrl =
String.Format("http://url{0}/Home/PrintSubmissionDataCentre?dataCentreId={1}", id, dc.DataCentreId);
HtmlToPdf.ConvertUrl(dcUrl, doc);
}

doc.Save(ms);
ms.Position = 0;

return new FileStreamResult(ms, "application/pdf")
{
FileDownloadName = "submission.pdf"
};
}


Any ideas
Many Thanks

eo_support
Posted: Wednesday, October 8, 2014 1:56:31 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Hi,

That does not make sense --- even though it is not unusual to run into strange problems when you try to request a Url back to your own website. You can try to use the .NET's own WebRequest class to request the same Url multiple times and see if you get the same problem.

Alternatively, it might be easier for you to render multiple views into a string and then combine them together as a ContentResult. You action method would be something like this:

Code: C#
[RenderAsPDF()]
public ActionResult Print(Guid id)
{
    //Render both view as string
    string s1 = RenderViewAsString<View1>(view1_path, view1_model);
    string s2 = RenderViewAsString<View2>(view2_path, view2_model);

    //Combine them as a single ContentResult
    ContentResult result = new ContentResult();
    result.Content = s1 + s2;
    result.ContentType = "text/html";
}

This way the final result from the ContentResult will be intercepted by MVCToPDF and convert to PDF for you.

Note that RenderViewAsString is not a system function. It's a function to be implemented by you. How to convert a MVC view into a string is a very frequently asked question online so you might be able to find many different implementations for this function. Here is one of them:

http://stackoverflow.com/questions/483091/render-a-view-as-a-string

Hope this helps. Please feel free to let us know if you still have any more questions.

Thanks!



Stephen
Posted: Thursday, October 9, 2014 4:40:06 AM
Rank: Newbie
Groups: Member

Joined: 10/8/2014
Posts: 2
Thank you. The content result option works.

It is definately something to do with requesting back to same url as when I used a different url on another server we have as a test the multiple converts worked. When I get time I will investigate the multiple WebRequests with .NET. Maybe something to do with using Hosts file locally but this doesn't answer why it works first time. Anyway this can wait for now.

Thanks Again
Stephen
eo_support
Posted: Thursday, October 9, 2014 3:36:23 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,196
Thanks for the update. Glad to hear at least content result works for you. Please feel free to let us know if there is anything else.


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.