DinkToPdf icon indicating copy to clipboard operation
DinkToPdf copied to clipboard

I can't generate on a second request

Open eliseumade opened this issue 1 year ago • 4 comments

Hello, I'm using the lib in a project, but I can generate the normal pdf in the first request, but if I make a second request, it doesn't call, it just waits, so I can get another request, I have to rebuild the api, does anyone know how to solve this?

eliseumade avatar May 15 '23 14:05 eliseumade

how about this https://github.com/rdvojmoc/DinkToPdf/issues/119

foxlovei avatar Jun 07 '23 04:06 foxlovei

public void ConfigureServices(IServiceCollection services) { // Add converter to DI services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools())); } i think, this is your issues

thanhy123zzz avatar Jul 09 '23 16:07 thanhy123zzz

I'm having the same issue, has anyone solved this problem?

I already add this code

builder.Services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));

and also I already add load library manually

string libraryPath = "";
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
    // Load .dll for Windows
    libraryPath = "libwkhtmltox.dll";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
    // Load .so for Linux
    libraryPath = "libwkhtmltox.so";
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
    // Load .dylib for macOS
    libraryPath = "libwkhtmltox.sylib";
}

var loadContext = new CustomAssemblyLoadContext();
var fullpath = Path.Combine(Directory.GetCurrentDirectory(), libraryPath);
IntPtr libraryHandle = loadContext.LoadUnmanagedLibrary(Path.Combine(Directory.GetCurrentDirectory(), libraryPath));
// Pastikan library berhasil dimuat
if (libraryHandle == IntPtr.Zero)
{
    Console.WriteLine("Failed to load the library.");
    return;
}

Console.WriteLine("Library loaded successfully.");


var builder = WebApplication.CreateBuilder(args);

but the problem still same, the second request response properly, I suspect libwkhtmltox is still stuck in the process, as we know we use external library here, and it do not managed properly by dotnet core.

So is there anyone already solve this problem?

btw I user docker linux here

yozawiratama avatar Feb 28 '24 04:02 yozawiratama