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

PDF renders before template assets have finished loading #56

Open
camfowler opened this issue Jul 19, 2022 · 1 comment
Open

PDF renders before template assets have finished loading #56

camfowler opened this issue Jul 19, 2022 · 1 comment

Comments

@camfowler
Copy link

I'm using some javascript to search for code blocks with a class "plantuml", then calling a web server and swapping the content with an SVG.

This works great when rendering as "Web". Works flawlessly.

When rendering as "PDF" it works most of the time. It works well enough that I can get a PDF out of it with multiple attempts. Much of the time, however it will render before the SVG has had time to be fetched, so the diagram displays the code block instead of the SVG. When the document has multiple diagrams, it is even more problematic to get a complete PDF.

Is there a way I could delay the rendering of the PDF until the SVG has had time to be retrieved? Perhaps a setting in Info.plist like IATemplatePDFRenderDelay? That way I could set it to a reasonable value to allow time for a template with slightly longer load times (say 500ms?) to fully render.

window.addEventListener('load', function() {
  document.body.addEventListener('ia-writer-change', function() {
    renderPlantUML();
  });
});

The fetch code is something like this:

function renderPlantUML(){
  var plantumls = document.querySelectorAll('.plantuml');
  plantumls.forEach(function (plantuml, index) {
    svg = compress(plantuml.innerText);
    plantuml.innerHTML = "loading...";

    fetch(svg)
      .then(r => r.text())
      .then(text => {
        plantuml.innerHTML = text;
      })
      .catch(console.error.bind(console));
  });
}

Some times it renders just the "loading..." text, and others it renders the SVG.

@jonaskuske
Copy link

You could use a synchronous XMLHttpRequest instead of fetch (which is always async)

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

No branches or pull requests

3 participants