I'm working in a website with PDF generation, but the result changes between the local execution and the final deployed site (the site effectively generates the PDF and the same binaries were checked with dotnet run -c Release
and the result is the same in localhost Release and localhost Debug).
I looked for some information or specific instructions for deployment, these are the official docs from https://selectpdf.com/html-to-pdf/docs/html/Deployment.htm but it doesn't have something special, I already made bigger modifications and I don't know if this is something like a config problem.
This is the function for Pdf Rendering
private Byte[] GetPdf(DocumentViewModel model)
{
var url = "a simple URL";
var converter = new HtmlToPdf();
converter.Options.CssMediaType = HtmlToPdfCssMediaType.Screen;
converter.Options.JavaScriptEnabled = true;
converter.Options.MarginBottom = 0;
converter.Options.MarginRight = 0;
converter.Options.MarginLeft = 0;
converter.Options.MarginTop = 0;
converter.Options.PdfPageSize = PdfPageSize.Letter;
converter.Options.AutoFitWidth = HtmlToPdfPageFitMode.AutoFit;
converter.Options.AutoFitHeight = HtmlToPdfPageFitMode.AutoFit;
converter.Options.PdfPageOrientation = PdfPageOrientation.Landscape;
converter.Options.MinPageLoadTime = 2;
converter.Options.MaxPageLoadTime = 30;
var doc = converter.ConvertUrl(url);
using (var stream = new MemoryStream())
{
doc.Save(stream);
return stream.ToArray();
}
}
My web.config doesn't have anything particularly special, but here it is
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="dotnet" arguments=".\WebSite.dll" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
<staticContent>
<remove fileExtension=".pdf" />
<mimeMap fileExtension=".pdf" mimeType="application/pdf" />
</staticContent>
</system.webServer>
</location>
<system.web>
<sessionState timeout="60" />
</system.web>
<system.webServer>
<caching>
<profiles>
<add extension=".pdf" policy="DisableCache" kernelCachePolicy="DisableCache" />
</profiles>
</caching>
</system.webServer>
</configuration>
With the current method, my results are different from local to server. I need to set the placement of elements in the website but I can't if I don't know which viewport is selected.