Welcome Guest Search | Active Topics | Sign In | Register

ao.PDF.HtmlToPdf returns a corrupted pdf Options
Alfredo
Posted: Friday, June 6, 2014 12:09:33 PM
Rank: Newbie
Groups: Member

Joined: 6/6/2014
Posts: 4
Hello folks.
I'm runnig out of options and need some direction. We have a large application that produces a health record on PDF format. Sometimes the Medical Note will have upwards of 50 pages. For the most part it works great, but I have 2 different clients where the PDF returned seems to be corrupted. By corrupted means waky and partial display of the HTML; However the 1st page display perfectly, footers display ok.
A bit more info, we brought the DB in house and have been unable to recreate it. We checked the DNS resolution and it looks good (app is always used inside the firewall). My feeling is that somehow IIS may be killing the rendering of the image. We get no errors anywhere (we have a pretty robust error loging). The environment is IIS MVC 3.0 and we have full license to the eo.PDF product. What I need is some direction on troubleshooting this issue. Below is the controller making the call. Thanks in advanced !


Code: C#
public FileStreamResult Index(int AdmSys, int PatSys, int CtnDocSys, int AmnSys)
{
	IDictionary constructorParms = new Dictionary<string, object> { { "principal", base.Principal } };
	PrintVisitNoteData visitnote = new PrintVisitNoteData();

	HtmlToPdfResult pdf = null;
	IDocVstCtnStsDA stsDa = ObjectLocator.Instance.Get<IDocVstCtnStsDA>(constructorParms);
	IVisitAO vststs = ObjectLocator.Instance.Get<IVisitAO>(constructorParms);
	DocVstCtnSts docvststs = stsDa.GetLatest(CtnDocSys);
	String status = vststs.GetVisitStatusDisplay(docvststs.Sts);
	BuildVisitNoteData(ref visitnote, AdmSys, PatSys, CtnDocSys, AmnSys);
	HtmlToPdfOptions options = BuildOptions(constructorParms, CtnDocSys, AdmSys, status, visitnote);
	//Get Url for BaseUrl
	options.BaseUrl = BuildPrintServerURL(constructorParms);
	
	string result = RenderFullViewToString("Index", "_PrintLayout", visitnote);
	try
	{
		using (MemoryStream ms = new MemoryStream())
		{
			pdf = HtmlToPdf.ConvertHtml(result, ms, options);
			//overwrite the exisiting Last page footer if visit status is complete
			if (status.ToString() == @Resources.Properties.Resources.Complete)
			{
				int lastPage = pdf.PdfDocument.Pages.Count;
				options = BuildOptionsLastPage(constructorParms, CtnDocSys, AdmSys, status, visitnote, lastPage);
				HtmlToPdf.ConvertHtml("", pdf.PdfDocument.Pages[pdf.PdfDocument.Pages.Count - 1], options);
			}
		}
	}
	catch (Exception e)
	{
		using (MemoryStream ms = new MemoryStream())
		{
			pdf = HtmlToPdf.ConvertHtml("&lt;div&gt;Error creating document for visit #" + CtnDocSys + "&lt;/div&gt;", ms, options);
		}
		Logger.HandleException(e, base.Principal, String.Empty);
	}

here are the options:

Code: C#
private HtmlToPdfOptions BuildOptions(
    IDictionary constructorParms, int CtnDocSys, int AdmSys, string status, PrintVisitNoteData visitnote)
{
	HtmlToPdfOptions options = new HtmlToPdfOptions();
	options.PageSize = new System.Drawing.SizeF(8.5f, 11f);
	options.OutputArea = new System.Drawing.RectangleF(0.0f, 0.1f, 8.5f, 10.35f);
	options.FooterHtmlFormat = BuildPdfFooter(constructorParms, CtnDocSys, AdmSys, status, visitnote);

	options.MaxLoadWaitTime = 30000;

	return options;
}

and here is the call to action on the controller from the view

Code: HTML/ASPX
<html>
<body marginwidth="0" marginheight="0" style="background-color: rgb(38,38,38)">
<embed width="100%" height="100%" name="plugin" 
    src="http://spgvtse217dev:90/HomecareAlfredo/PrintVisitNote?AdmSys=277&amp;PatSys=937&amp;CtnDocSys=2011200368&amp;AmnSys=-1" type="application/pdf">
</body>
</html>


eo_support
Posted: Friday, June 6, 2014 2:03:18 PM
Rank: Administration
Groups: Administration

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

Your code looks fine. The first thing you want to do is to find out which step returned the wrong content ----- for example, you can try to save the content of the FileStreamResult you returned from the server to a file, then check whether that file is a valid PDF file. And also save the file in the browser to see if that is OK. That will eventually help you to identify which step generated the wrong contents.

If you use MVC to PDF feature (from your code it appears that you are not using MVC to PDF since you call ConvertHtml directly), then you will want to update to the latest EO.Pdf first. We have recently fixed an issue related to MVC to PDF that can cause HTML contents proceeding the real PDF file.

Hope this helps. Please let us know how it goes.

Thanks!


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.