Welcome Guest Search | Active Topics | Sign In | Register

HtmlToPdf sometimes uses an old stylesheet Options
Joren
Posted: Wednesday, December 5, 2012 6:05:47 PM
Rank: Newbie
Groups: Member

Joined: 9/4/2012
Posts: 9
Hi,

We're having issues when generating a PDF from an aspx page (using HtmlToPdf). The PDF returned sometimes uses an old version of the css file used for styling the source page.
This only happens when generation is done from the timerv4 process. When generated from the w3wp process (on demand) it will always use the most recent version.
The weird thing is that it is an intermittent problem. Sometimes it wil use the correct version, other times an older one.

I've tried the following in an attempt to resolve this issue:
- Delete all old versions of the css file (it is stored in SharePoint)
- Added "NoCache = true" to the HtmlToPdfOptions
- Added following headers to my source page
Code: HTML/ASPX
<meta http-equiv="Cache-Control" content="no-cache, mustrevalidate" />
<meta http-equiv="Expires" content="0"/>

- Reboot the server
- Clear the browser cache for the timerv4 service account

We are currently using EO.Pdf version 4.0.41.2. If more info is needed, please don't hesitate to ask.

Regards,

Joren

eo_support
Posted: Wednesday, December 5, 2012 8:32:24 PM
Rank: Administration
Groups: Administration

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

You may want to look into SharePoint for this. EO.Pdf should honor your cache settings, but SharePoint may still serve you the old files. I do not know what's special about your timerv4 process either, but the difference most likely has to do with the permission of the user account your web server is running and the permission of the user account your timerv4 process. Your browser's cache has nothing to do with us because we have a built-in browser engine embedded inside our DLL.

One thing you do want to do is to update to the latest EO.Pdf.dll (check our download page). Your DLL is a few builds behind and we have recently fixed an issue related to windows authentication, which may or may not have an impact on which file is being served.

Thanks!
Andrew Scott
Posted: Thursday, December 6, 2012 6:20:22 AM
Rank: Newbie
Groups: Member

Joined: 12/6/2012
Posts: 2
@Joren - Just use a standard cache buster, as you would on any other HTML page. For the most part CSS shouldn't change once you've got the application developed, but this can be a real pain both when developing and when you push a new revision of CSS.

Cache busting is a simple solution, just use a unique name for each revision of the CSS file. I use an MD5 sum of it's content, this way if I'm developing or pushing a change I can be 100% sure that EVERY[ONE/THING] will rx the latest revision.

Here's my GenerateMD5Hash, it recives a string containing the content to be hashed (in this case it would be your CSS) and returns the Hash of the passed buffer.


/// <summary>
/// Generates an MD5 hash for a buffers content
/// </summary>
/// <param name="cBuffer">A buffer containing the string to be Hashed</param>
/// <returns>The MD5 Hash</returns>
internal static string GenerateMD5Hash(string cBuffer)
{
string cHash = "";
MD5 md5 = System.Security.Cryptography.MD5.Create();
byte[] buffer = System.Text.Encoding.ASCII.GetBytes(cBuffer);
byte[] hash = md5.ComputeHash(buffer);

// Convert the slice of bytes to a Hex string
foreach (byte b in hash) { cHash += b.ToString("x2"); }
return cHash;
}

Hope that helps
Andy
Joren
Posted: Thursday, December 6, 2012 10:18:35 AM
Rank: Newbie
Groups: Member

Joined: 9/4/2012
Posts: 9
Hi,

Thanks for the replies. I'll try updating the dll's and implementing a cache busting mechanism.
I'll let you know if this solves my problem.

Regards,

Joren


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.