I'm rendering a PDF using `N/render` and an XML fi...
# suitescript
e
I'm rendering a PDF using
N/render
and an XML file - as opposed to using an actual Advanced Template. It's a sizable report of varying datasets. No matter how large the dataset is, the resulting PDF is always truncated at exactly two pages. Anyone seen behaviour like this?
Nothing too crazy in the template, just a couple repeating tables.
Can't see a pattern in where it cuts off in terms of the data - i.e. I don't think it's a bad rendering of an element or data point or something - it's just always cut off right at the end of the second page.
a
@erictgrubaugh I don't see the problem in the Template but I faced weird errors before with
N/render
and many errors were fixed when using
N/xml
This is a very old function but it works for me when I have weird issues with XML and render
Untitled
t
Eric, I usually do context.response.renderPdf(xmlstring) morning instead of using the N/render module. So maybe you can try that as an option if nothing else stands out.
e
Unfortunately I'm not rendering the PDF to a page response, but rather attaching to an email
t
Ok, so you’re doing render.xmlToPdf ? I’ve got a handful of scripts creating PDFs like that to send with an email. I’m skimming through them to see if anything in stands out between mine and yours. I noticed that I don’t specify a size in the body tag. Not sure if that has anything to do with it. In all my scripts that render the pdf to a page response, I have the body size specified but for some reason I removed it for email attachments PDFs.
b
i like @alien4u’s idea. Render it as a string and then check to see if its valid xml
e
Here's the rendering portion. I create a plain Object with
toView()
, where anything potentially invalid or XML-breaking (e.g. the URLs) is passed through
xml.escape()
.
t
@erictgrubaugh Have you tried saving the file to the file cabinet? I wonder if doing so would make a difference.
m
Can you share the ouptut of
renderer.renderAsString()
?
e
For troubleshooting purposes, I've added a log dump of the
renderAsString
output as well as saved the PDF file to the File Cabinet before emailing. In both cases, the content simply cuts off right in the middle of markup, e.g.
<a href="blah">This is a link to somew
There's no tag or potentially invalid character there. I'm wondering if I'm running into some sort of size limit or something. The generated file is only 4kb, and I don't see any documented limit near that size.
It is always right at the end of the second full page.
I've got plenty of code elsewhere doing very similar things and generating much larger PDFs correctly.
No clue yet what's different about this one
t
If you were to add something to the XML - something extraneous - and then run the script, it would be interesting to see if the "renderAsString" result gets cutoff at the exact same spot ("<a href="blah">This is a link to somew") or somewhere prior to that. If it's at that same spot, it would seem to me to point to an issue with the XML. If not, then it might indicate that it is some sort of memory-related issue.
Also, I'm sure you've tried this... But maybe wrap the call to renderAsString in a try / catch block and log any exception. I doubt there is one, but you never know.
e
Ah sure, add a larger header or something else static to see if it really is size dependent
^ Using this approach, can confirm it still cuts off at exactly 2 pages
at a different point in the markup
Going to try replacing
renderAsString > xmlToPdf
with just
renderAsPdf
to see if that makes a difference
Same resuit
🤔 1
🤨 1
My largest suspicion now is that this has something to do with how BFO handles page breaks amid tables, and I have no clue how to correct it. I've tried the BFO
page-break-inside
attribute at every allowed level of the table with the same result. I've found several stackoverflow questions regarding the same issue, but none of the dozens of solutions provided to any of those questions have worked for me.
t
Have you tried making a very simple XML template that just has text and a number of page breaks? And then see if it ever gets beyond the second page? If that works, then slowly add the real XML elements back in and see when and where it breaks.
e
This works fine. The problem is when a <table> wraps over pages
Ran a slightly different test and it is not just
<table>
wrapping. Second page was cut off just after a
<p>...</p>
Now running a test with 10 paragraphs of static text at the front 🙂
^ This does indeed move on to a third page. The mass of text spans 1.5 pages, then the report starts in again and gets cut off after the third page. Perhaps there is a block which is wrapping the report itself which needs changed.
Copy code
<p class="center"><a href="${p.smaUrl}">View in SMA</a> | <a href="${p.nsUrl}">View in NetSuite</a></p>
<!-- cuts off here -->
        <p><strong>Records Processed:</strong></p>
Trying yet another new test with
page-break-inside="auto"
set on all my wrapping block elements (divs, etc)
t
Is it possible that there's something in the XML (a hidden character) that you're not seeing? If you're on a Mac, you could take the XML into a text editor (something like bbEdit), and "Show Invisibles" to see them or "Zap Gremlins" to get rid of them.
e
Nah I've traced it back to the pure-table styles
Removing all of the pure-table classes fixes the problem
so now I get to spend the day doing table css