I use PDF creation using Blink in my application.
After a PDF is being created, the session is lost and I need to login again to proceed.
Any idea how to overcome this or change it so it keeps the session alive ?
MemoryStream ms = new MemoryStream();
BlinkConverterSettings blinkConverterSettings = new BlinkConverterSettings
{
EnableJavaScript = true,
AdditionalDelay = 1000,
MediaType = MediaType.Print,
PdfPageSize = new SizeF(PdfPageSize.A4.Width, PdfPageSize.A4.Height),
Orientation = PdfPageOrientation.Portrait,
};
if( PageSize != "A4")
{
}
if (PageOrient != "Portrait")
{
}
//Initialize the HTML to PDF converter with Blink rendering engine
HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter()
{
RenderingEngine = HtmlRenderingEngine.Blink,
ConverterSettings = blinkConverterSettings
};
//Convert URL to PDF
PdfDocument document = htmlConverter.Convert(path);
document.PageSettings.Size = PdfPageSize.A4;
document.PageSettings.SetMargins(0, 10, 0, 10);
document.PageSettings.Orientation = PdfPageOrientation.Portrait;
//Save and close the PDF document
document.Save(ms);
document.Close(true);
return File(ms.ToArray(), "application/pdf", SanitizeFileName(fileName));
Hi Joop,
We have tried to reproduce the reported issue with simple authentication
sample on our end, but it is working properly and session alive after the
document creation. We have attached the authenticated sample for your
reference, please try the sample on your end and let us know the result.
Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/HtmlPdfWebApplication314588965
Please refer to the below documentation link for more information,
https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/blink#form-authentication
Please let us know if you need any further assistance in this.
Regards,
Gowthamraj K
Thanks for the sample ... it's using ASP .NET Core.
I'm using .NET Framework, might be different (?)
I see you are using a cookie to get the .AspNetCore.Antiforgery setting.
So I will try to update that bit.
Which of these should I capture
How to use this if transforming html instead of a URL ?
Will that be the same, since I don't have a "request"
BTW: Request = null ... ??
Hi Joop,
This KB article is published for converting web page authentication page to PDF using HTML converter library in .NET framework. You can follow the below cookies details to login the session alive for multiple conversion.
|
//Set cookie name string cookieName = ".AspNet.ApplicationCookie"; //Get cookie value from HttpRequest object for the requested page string cookieValue = string.Empty; if (Request.Cookies[cookieName] != null) { cookieValue = Request.Cookies[cookieName].Value; } |
UG: https://help.syncfusion.com/file-formats/pdf/convert-html-to-pdf/blink#html-string-to-pdf
When converting HTML string to PDF, we have to specify the accessible base URL (path of the resources) to load the external images/scripts/styles used in the HTML string.
If still you are facing an issue, we request you to share the Complete
Input HTML file (with all resource such as scripts, image, styles etc), Platform,
HTML converter product version etc., to check the issue. So that it will
helpful for us.
Regards,
Gowthamraj K
I do understand that bit, but that's behind a button.
My code is in a function I use to generate PDFs from different parts of my program.
So I don't have Request available. I needed to pass the Context to the function to be able to access the cookies. Otherwise the Request just was null.
It still loses the session, I need to login after PDF is being created ...
Hi Joop,
We have tried to reproduce the reported issue in our side, it seems the reported issue occurs with your authentication process. Can you please share us the simple sample to reproduce the issue in our side. It will be helpful for us to analyse and assist your further on this issue.
If it is not possible to share the details, kindly create a support ticket in this link. We can have web meeting to look into the issue directly in your machine and provide the solution at the earliest.
Regards,
Prakash V