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

fix issues #608 / #405 (too many temporary files) by avoiding to call Font.createFont with inputstream #612

Closed
wants to merge 1 commit into from
Closed

Conversation

syjer
Copy link
Contributor

@syjer syjer commented Nov 29, 2020

Hi @danfickle , I was finally able to understand the issue described in #608, #405 .

This is triggered when using the SVG backend and using custom fonts.

In my case, the sample html is:

<html>
<head>
<style>

@font-face {
  font-family: 'noto';
  src: url(NotoSans-Regular.ttf);
  font-weight: normal;
  font-style: normal;
}

.noto {
  font-family: 'noto', serif;
}

</style>
</head>
<body>
<p>not noto</p>
<p class="noto">noto</p>
</body>
</html>

Then by simply iterating:

for (int i = 0; i<100; i++) {
            String input = FileUtils.readFileToString(new File("in.htm"), "UTF-8");

            try (OutputStream os = new FileOutputStream("out.pdf")) {
                PdfRendererBuilder builder = new PdfRendererBuilder();
                builder.useFastMode();
                builder.useSVGDrawer(new BatikSVGDrawer());
                builder.withW3cDocument(W3CDom.convert(Jsoup.parse(input)), "");
                builder.toStream(os);
                builder.run();
            }
            Thread.sleep(1000);
        }

You can see the temporary directory slowly fill with a new temporary file during each iteration.

This PR try to ensure that at most only one temporary file is created for a given font (by hashing the byte array), instead of one for each iteration.

Putting as a draft, as I'm not sure it's the best fix.

…to call Font.createFont with inputstream
@syjer syjer marked this pull request as draft November 29, 2020 20:07
@syjer syjer changed the title try to fix issues #608 / #405 (too many temporary files) by avoiding to call Font.createFont with inputstream fix issues #608 / #405 (too many temporary files) by avoiding to call Font.createFont with inputstream Nov 30, 2020
@danfickle
Copy link
Owner

Hi @syjer,

Unfortunately, I'm not brave enough to work with temporary files, so I've created an alternative PR #613 that allows the user to add fonts for SVG as files instead of input streams. More details in that PR.

Thanks anyway for looking at this.

@syjer
Copy link
Contributor Author

syjer commented Nov 30, 2020

hi @danfickle , make sense. I've added a comment in your PR (#613 (comment)) :)

@syjer syjer closed this Nov 30, 2020
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

Successfully merging this pull request may close these issues.

2 participants