Script tags and PDF don’t mix

I am using the Mac desktop version of Manager version 19.11.16.

Since the Liquid templating language is too primitive for my uses, I use HTML script tags with document.write() in my template.

It works perfectly well when displaying an invoice or printing it, but when I click the PDF button, the source code of the script shows up on the form.

Example:

“Print” option gives me: 131.40
“PDF” option gives me: <!–function commify(n) { while (n != (n = n.replace…

(and the text is cut off because it reaches the edge of the page.)

With some experimentation I have found that the JavaScript code is running; the results of document.write show up after the JavaScript source code, which I have not found a way to hide.

I believe that this is a problem with server-side PDF generation (I see it is going to a URL like localhost:12345/pdf?FileID=32c0e424-ae80-49c6-b370-7e099cdc16a5), whereas “Print” is using window.print(), and, hence, WebKit.

Furthermore, I see that the PDF is generated by Apitron PDF Kit.

So, that leads to the following three questions:

  1. is this something I should report Apitron, or is it specific to Manager?
  2. Is there a newer version of Apitron that Manager could upgrade to?
  3. Is there a workaround I can use now (other than Print -> Save as PDF, which is cumbersome)?

I would not use print - save as because the formatting and layout for print is not accurate in terms of borders etc. The same for PDF Printers such as Nitro. This is because Manager has no control over your Operating System Printer drivers. Always use the Internal Manager Pdf option to ensure that the output is exactly as you designed it in the custom themes.

I suspect that you need to report the issue to Apitron, but only the Manager developer can advise on this point as it’s outside the scope of most forum users (myself included) to support programming issues like this. Again only developer could advise on what version of Apitron they are using and any workarounds.

I would also recommend seeing if you cannot get Liquid to do what you require as Manager is designed to work with Liquid coding and does not support all HTML tags. There should not be anything you can’t do in Liquid that you can do in HTML. My recommendation would be first to see if you cannot get Liquid to do what you require (as Manager supports it) as you will most likely end up having problems with Manager using unspported HTML tags.

@datacor, thank you for your reply.

The problem with Liquid is that I have not found out how to do substitution and pattern matching easily. It would take a whole page to do what I can write in one line in JavaScript (if it is even possible). And I don’t have that much time to spend on it.

However, I did find a perfect workaround just now, after some experimentation:

<script>
while (document.scripts.length) {
    document.scripts[0].parentNode.removeChild(document.scripts[0])
}
</script>

Putting this at the end of the document solves the problem. There are no longer any scripts for the engine mistakenly to print.

(Also, Noto Sans is ugly. I had to set font-family to Helvetica to make the form presentable. :)

I am not a programmer, so I can’t comment on that, but I appreciate your point about one line of code versus a whole page of coding between the different languages. So I get why you want to change the language.

The reason that Noto Sans is used was to ensure compatibility with all languages that Manager supports and apparently there were a number of issues with using system fonts and the PDF generator in terms of output. So bear this in mind when changing the font - you may find the output is not what you expected when using the pdf generator.

I agree with you - I don’t like the default font either! However, since creating a custom theme and changing the font colours and background colours, the font’s clunky look is not as noticeable anymore.

@sprout, I do not believe you are going to get much support on this. The developer intends all themes to be written in Liquid and is unlikely to even answer questions about other approaches.

As for substituting font families other than Noto Sans, see the Guide: https://www.manager.io/guides/18025.