Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subsequent PdfTools instances yield wrong PDF output #44

Open
kierenj opened this issue Aug 1, 2018 · 7 comments
Open

Subsequent PdfTools instances yield wrong PDF output #44

kierenj opened this issue Aug 1, 2018 · 7 comments

Comments

@kierenj
Copy link

kierenj commented Aug 1, 2018

Hi! I'm trying to write some automated tests.

If I:

using (var tools = new PdfTools())
{
 var converter = new SynchronizedConverter(tools);
 // do the stuff, many times over
}

..then everything works fine.

However, if I:

using (var tools = new PdfTools())
{
 var converter = new SynchronizedConverter(tools);
 // do the stuff
}
using (var tools = new PdfTools())
{
 var converter = new SynchronizedConverter(tools);
 // do the stuff
}

The "stuff" being done is a randomly-named temp folder being set up, a HTML file and CSS file being copied in and the HTML being converted. I've put breakpoints and verified that for each conversion, the HTML and CSS are all valid. It's the PDF conversion bit which has the issue, for some reason!

..then only the first PDF is correct. Strangely, all of the subsequent PDFs simply have text in the source document dumped out.

The tests don't run in parallel, it seems that using a second (or rather, non-first) PdfTools instance is the issue.

Anything I can do to help diagnose?

@carlos-eduardo-silva
Copy link

I have this problem too!

@mlynam
Copy link

mlynam commented Aug 24, 2018

The PdfTools and Converter need to behave as singletons in your AppDomain.

@kierenj
Copy link
Author

kierenj commented Aug 24, 2018

Yes, it certainly seems so. But I'd have hoped that there would be an exception, rather than randomly-corrupted PDF output. If this is indeed a design restriction, could I suggest a static flag somewhere, such that subsequent calls to the constructors throw a helpful error message?

@mlynam
Copy link

mlynam commented Aug 24, 2018

Yeah I'm not a fan of opinionated service lifetimes. I haven't dug into the code here to find out why this limitation exists, but rather I've just discovered this is the case via my own usage.

@MagnusJohansson
Copy link

Sadly, when trying to use singleton instances of a converter, and subsequent calls to Convert, DinkToPdf hangs: #62

@mbenahssene
Copy link

Same problem for me even with singleton. Is there any solution or update? Thank you.

@serenata-alexander
Copy link

Same for me in october 2022

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants