|
Rank: Newbie Groups: Member
Joined: 8/2/2014 Posts: 6
|
Hi, I'm creating an ASPX page that directly loads as a pdf in the browser. when I test locally within Visual Studio 2012, my Header and Footer options show correctly. However, when I deploy it on our servers the headers and footers don't show. Here's a sample of the code I use:
Code: Visual Basic.NET
EO.Pdf.HtmlToPdf.Options.OutputArea = New System.Drawing.RectangleF(1.0F, 1.5F, 6.5F, 8.25F)
EO.Pdf.HtmlToPdf.Options.HeaderHtmlPosition = 0.5
EO.Pdf.HtmlToPdf.Options.HeaderHtmlFormat = "<b><span style=""float:left;text-align:left;"">Hospital Name</span>
<span style=""float:right;text-align:right;"">Patient Name</span><br /><p align=""center""><font size=""3"">Pre-Admission Screening Form</b> </font></p><br />"
EO.Pdf.HtmlToPdf.Options.FooterHtmlFormat = "Page {page_number}"
aspxpdf.RenderAsPDF(False)
Code: Visual Basic.NET
Protected Sub display_pdf() Handles aspxpdf.AfterRender
Dim result As HtmlToPdfResult = CType(aspxpdf.Result, HtmlToPdfResult)
Dim pdf As PdfDocument = result.PdfDocument
Dim stream As MemoryStream = New MemoryStream()
pdf.Save(stream)
HttpContext.Current.Response.ContentType = "application/pdf"
HttpContext.Current.Response.AddHeader("content-disposition", "inline;")
'HttpContext.Current.Response.AddHeader("content-length", stream.Length.ToString())
HttpContext.Current.Response.BinaryWrite(stream.ToArray())
HttpContext.Current.Response.End()
End Sub
Please let me know if you have any leads. Thanks!
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
Please try to set all options in BeforeRender event instead of directly before calling RenderAsPDF.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 8/2/2014 Posts: 6
|
Hi,
I tried that and it didn't work. Any more suggestions?
|
|
Rank: Newbie Groups: Member
Joined: 8/2/2014 Posts: 6
|
How are the options set? Is it through another server? Could it perhaps be a security issue?
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Hi,
No. It shouldn't be a security issue but it might be a threading issue since each thread has its own copy of HtmlToPdf.Options. We have posted a new build that would automatically transfer the options values you set in BeforeRender event to the converter regardless in which thread it is called. Please see your private message for the download location and give it a try and let us know if it resolves the problem for you.
Thanks!
|
|
Rank: Newbie Groups: Member
Joined: 8/2/2014 Posts: 6
|
For anyone else having a similar issue, putting this in the AfterRender event did the trick:
Code: Visual Basic.NET
Dim result As HtmlToPdfResult = CType(aspxpdf.Result, HtmlToPdfResult)
Dim pdf As PdfDocument = result.PdfDocument
Try
Dim page As PdfPage
For Each page In pdf.Pages
'Set the output area as the top of the page
HtmlToPdf.Options.OutputArea = New System.Drawing.RectangleF(1.0F, 1.5F, 6.5F, 8.25F)
EO.Pdf.HtmlToPdf.Options.HeaderHtmlPosition = 0.5
EO.Pdf.HtmlToPdf.Options.HeaderHtmlFormat = lblHD.Text
EO.Pdf.HtmlToPdf.Options.FooterHtmlFormat = lblFT.Text
Next page
Catch
End Try
|
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,196
|
Thanks for sharing. That's very interesting. Glad to hear that you got it working though!
|
|