Rank: Newbie Groups: Member
Joined: 6/21/2011 Posts: 3
|
Here's my situation. I have a web text editor that users can create a mail merge template. On that editor there is a pdf preview button that when clicked does a mailmerge process that replaces the database fields with data and creates an html string.
I want to convert this string into a pdf file that the user can save to their machine or open in adobe.
My constraints are: I don't want to write any files on the server. The conversion to pdf must not be browser based or browser dependant. Security is session based. The user should not leave the editor page after clicking the pdf preview button. The html string has image urls with a querystring that point back to the editor page to pull images from a database. Using querystrings to pass login credentials is not a practical solution in this case.
I have successfully used EO.Pdf.HtmlToPdf.ConvertHtml to create a pdf and stream it to the browser but the images are blocked due to session based security. I am looking at ASPXToPDF but I just want to use the html I've generated from the merge process and not any of the extra stuff that is part of the application.
Any suggestions would be appreciated.
Thanks
|
Rank: Administration Groups: Administration
Joined: 5/27/2007 Posts: 24,194
|
Hi,
This is very much of an ASP.NET programming question rather than an EO.Pdf question. So most likely more or less you will need to change your server side code a bit in order to achieve your goal.
EO.Pdf works by sending an HTTP GET/POST request to your server (ASPXToPDF works slightly differently, more on that later) and takes whatever it gets back from your server, then convert it. So whatever you do, your server must first give the right data to EO.Pdf. For example, if your server gives out a 404, then there is nothing EO.Pdf can do. Thus the center of the problem is to ensure your server give out the correct data.
Session data is usually established based on cookies. So if you can send the correct authentication cookies to your server then everything will be fine. You can use HtmlToPdf.Options.AdditionalHeaders to send cookies to your server.
Most people would want to duplicate .NET authentication cookies if choosing this approach. As elegant as it sounds, duplicating .NET authentication cookies is usually more difficult than other mechanism (such as using query strings) because authentication cookies are usually encrypted, thus is more difficult to debug. An easier way would be handle your server side’s Application_AuthenticateRequest/PostAuthenticateRequest to implement some special logics based on cookies. That way it is possible for you to establish an user identify based on your own special cookies. You can encrypt that cookie with certain unique values that is only known to your server so that it is not possible for other parties to fake it. Because the whole encryption/decryption/verification process is in your own code, it will be easier for you to debug.
ASPXToPDF works by intercepting your current page output and then use that page output as EO.Pdf’s input. The interception occurs while the page is rendered so it already has the correct user identity/session data. However that only applies to the current page output ---- it will still do an HTTP GET for any child Urls inside the current output, for example, images. Usually this is not a problem because most images allow anonymous access. However if those images are dynamically generated based on session data then you will have to establish the session data first.
Hope this helps. Please feel free to let us know if you still have any questions.
Thanks
|