The environment where the application is running:
- Operating System: Windows
- .NET Version: .NET 6
Package version:
Occasionally we faced a blank line while building PDF files with this usage:
private void ConfigureUnmanagedAssemblies()
{
const string HtmlToPdfLibraryName = "libwkhtmltox.dll";
#if DEBUG
const string HtmlToPdfLibraryDirectoryName = "HtmlToPdfConverter_x64";
#else
const string HtmlToPdfLibraryDirectoryName = "HtmlToPdfConverter_x86";
#endif
var customAssemblyLoadContext = new CustomAssemblyLoadContext();
var customAssemblyDirectoryInfo = new DirectoryInfo(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + $"\\{HtmlToPdfLibraryDirectoryName}");
var customAssemblyFile = customAssemblyDirectoryInfo.GetFiles(HtmlToPdfLibraryName, SearchOption.AllDirectories).FirstOrDefault();
if (!string.IsNullOrWhiteSpace(customAssemblyFile?.DirectoryName))
{
customAssemblyLoadContext.LoadUnmanagedLibrary(Path.Combine(customAssemblyFile.DirectoryName, customAssemblyFile.Name));
}
}
public async Task<FileModel> GenerateAsync(Invoice invoice, string fileName)
{
FileModel fileModel = null;
var invoiceExportPdfModel = await this.GetInvoiceExportPdfModelAsync(invoice.Id, invoice.IssuedDate).ConfigureAwait(false);
var htmlToPdfDocument = await this.GetHtmlToPdfDocument(invoiceExportPdfModel).ConfigureAwait(false);
if (htmlToPdfDocument != null)
{
fileModel = new FileModel { Content = this.htmlToPdfConverter.Convert(htmlToPdfDocument), Name = fileName, ContentType = ContentTypeConstants.ContentTypePdf };
}
return fileModel;
}
private async Task<HtmlToPdfDocument> GetHtmlToPdfDocument(InvoiceExportPdfModel invoiceExportPdfModel)
{
HtmlToPdfDocument htmlToPdfDocument = null;
if (invoiceExportPdfModel != null)
{
htmlToPdfDocument = new HtmlToPdfDocument
{
GlobalSettings = new GlobalSettings
{
ColorMode = ColorMode.Color,
Orientation = Orientation.Portrait,
PaperSize = PaperKind.A4,
Margins = new MarginSettings(0, 0, 0, 0),
DocumentTitle = invoiceExportPdfModel.InvoiceNumber
}
};
var htmlPages = await this.invoiceHtmlPageBuilder.BuildAsync(invoiceExportPdfModel).ConfigureAwait(false);
htmlToPdfDocument.Objects.AddRange(
htmlPages.Select(
htmlPage => new ObjectSettings
{
PagesCount = true,
HtmlContent = htmlPage,
WebSettings = { DefaultEncoding = "utf-8", UserStyleSheet = this.filePathProvider.GetFilePath(StyleSheetConstants.FolderName, StyleSheetConstants.FileName, FileType.Css) }
}));
}
return htmlToPdfDocument;
}
NOTE:
When I start generating it locally on my local machine which uses Windows as well it generates files without the blank page so, it looks like there's something related to the environment where the app is running but at the same time, it looks like there's no difference. Does anyone have any idea of the reason or probably someone has already faced a similar issue and figured out how it can be solved? Thanks in advance for any help @gldraphael @rdvojmoc
The environment where the application is running:
Package version:
Occasionally we faced a blank line while building PDF files with this usage:
NOTE:
When I start generating it locally on my local machine which uses Windows as well it generates files without the blank page so, it looks like there's something related to the environment where the app is running but at the same time, it looks like there's no difference. Does anyone have any idea of the reason or probably someone has already faced a similar issue and figured out how it can be solved? Thanks in advance for any help @gldraphael @rdvojmoc