Create PDF from raw HTML via automation

I am creating a PDF from a raw HTML file via automation.

It works perfectly when using a Google Doc template and perfectly with an HTML template before I add Appsheet variables enclosed with << and >>. See below.

<<[Inspection Date]>>

It errors with the message below

Template could not be loaded due to exception: Name cannot begin with the ‘<’ character, hexadecimal value 0x3C. Line 12, position 5. Error: The document body is empty"

If I escape the << >> as in <<[Inspection Date]>> it works. BUT and a big BUT….

Then the <<IF: <> and <<START: <> are not recognised (even with or without escaping the characters.

CATCH 22, there must be something wrong with the APPSHEET parser. It should be simple to just use the << >> in UTF-8 with no BOM?

4 Likes

You do not need to escape anything. The <<, and >> brackets are simply indicators to the template processor that Appsheet PRE processing is needed. You must use these brackets for any AppSheet columns unless they are inside of an already bracketed expression.

It seems the error message is coming from an HTML based template? You need to use the HTML version of bracketing which is like this:

<p>FirstName: &lt;&lt;[FirstName]&gt;&gt;</p>

Tap this link for more details on how to Use HTML templates

I hope this helps!

1 Like

Thanks for your reply.

I am escaping the << >> BUT then it gives AN ERROR an unmatched Start (presumably it can’t find the END

Here’s the most basic HTML

<<[Inspection Date]>>

<<Start: ORDERBY(SELECT(Report Options[ID], AND([Section]=“INTRODUCTION” , [Show]=“Y” )), [Item], FALSE )>>

<<[Description]>>

<<End>>

And here is the error the appsheet gives!

Found 1 unmatched ‘Start’.

I noticed deep in the AppSheet documentation that it says to use << yet others on here seem to have it working with just <<. Has anyone done an HTML template with IF and START on here?

Don’t use raw HTML in a Google doc!

Use the standard doc formatting along with the AppSheet variables.

If you want to use raw HTML, then save it in a text editor as an HTML file and use that template.

But then you will run into all the problems I am having when using HTML templates.

So, I’m confused! You are showing Google Docs templates but keep mentioning HTML templates. You are are trying to get this to work with Google Docs….right?

As for the error, is this the only place you have a START/END block? I don’t see anything wrong with this part of the template.

If you have other blocks that require <>, keep in mind that improper syntax within those could lead to an error being identified elsewhere.

It might be helpful to show the entire template, if you can!!

I am using HTML template (Google Doc template is working absolutely fine and Ive being doing it for years.

The template is huge so I have extracted the basic part that does not allow START to be used when escaping the << and >>

Clearly its Appsheet parsing badly. Perhaps it’s changed? Has any one go an HTML template that works with START and END loops?

Not sure what’s going on but your previous post where you provided an example is all blurred out. You last post didn’t include anything.

Can you post just the example of the START/END portion so @CaptainEon can see a working example? (I’m curious myself)

2 Likes

@WillowMobileSys It is all blurred out for me too but If I click/tap on blurred block, it shows everything, very strange to me as well..

2 Likes
&lt;&lt;START: ORDERBY(SELECT(Report Options[ID], AND([Section]=“INTRODUCTION” , [Show]=“Y” )), [Item], FALSE)&gt;&gt;

&lt;&lt;[Item]&gt;&gt;

&lt;&lt;END&gt;&gt;

[spoiler]
This text was blurred.
[/spoiler]

This text was blurred.

4 Likes

Are you indicating that this worked?

No, this is a sample snippet of the code that works in a google doc template but not in a HTML template.

But it’s HTML encoded - at least partially?? This is where I’m getting confused.

In Google, ignoring Excel conversions, we only have a single document type we can use for automation generation templates - Google Docs. We specify which type of template is formatted in that document. For example, “PDF” will expect the “usual” 3rd party PDF generator template formatting. Selecting “HTML” will expect formatting that uses HTML tag based formatting.

Which format selector are you choosing for the template?

NOTE: Maybe the “<<“ brackets and “&lt &lt” HTML formatting are interchangeable in a “PDF” formatted template?? I have no clue!

1 Like

Yes you DO need to use << in HTML templates.

This comes directly from APPSHEET support.

Looks like there’s not actually an example of using an HTML template anywhere in the examples or anywhere on this forum if there was it would prove whether the start and end directives actually work

I noticed also another user reported exactly the same problem about six months ago

@SkrOYC, have you any sage advice here?

2 Likes

Do you know under what circumstances the “<<“ brackets are required instead of the “&lt &lt” formatting?

I ask, because while I don’t have template documents, I do use HTML formatting in many email bodies. I use the “&lt &lt” formatting for AppSheet columns embedded in the HTML code. I have yet to try implementing any expressions.

1 Like

The << angle brackets are OK when doing a PDF output from a Google Doc template

The < are required when using an HTML template

How about using the <p> tag?

1 Like

Have you tried that?

AppSheet Directives need >>

A single > is and HTML tag

I assume NOBODY has ever done a real PDF file report from an HTML template using START: or IF: Appsheet directives on here? ( I mean HTML template not a Google Doc Template)

Or is there a sample somewhere proving it works as documented by AppSheet?