Create a PDF from app

The file does successfully generate. I was able to see and view it earlier because it is already published. The function doGet is called here: (and the exportSpreadsheet returns the sheet URL)
Function

and I get this string in return with the Published web app (:
URL
If I paste this link in the browser, it does bring me to the file.

Here are my publish settings:

When I paste the URL in Export PDF, it runs the script successfully and I get something like the link I posted earlier. With this info, what do I need to do to get it into something like a variable? The Thunkable Pull was the same project but as a API deployment. I didn’t know which one I needed.

1 Like

Are you using templateHTML in your app script?

If yes, go to the example and also create the HTML file that should go with the app script function.

I can’t really give much suggestion without seeing the script and the sheet itself.

Here is the sheet:

Here is the .txt file of the script for what I have. Is this enough info? Sorry for all of the questions. This is the first time I have done this, and the documentation was not making sense. It is safe to assume that I have no idea what I am doing, and what I have gotten done this far was mostly from the git repo I found with the source code, a YouTube video which told me about the doGet(), and a basic understanding of programing to rearrange a few things and guess and check.

Original source.

Code.txt (3.4 KB)

1 Like

Can you use this link and see if a file named export.pdf" is created under your google drive?

https://script.googleusercontent.com/macros/echo?user_content_key=GQCSgAQTAZv0ARAslEwHyKxs1DObk3qMx_RreW5OQYsLXOyoBnQCnkA2uMz5SsU4ifmDPmsAWoOfh8l3AG6bEQqw_4GRCZhOm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnJsskmBPdZX3F9jS7xiMmIoM2_K-HdCtuZM4PkKvEqvcM0CLSZr-ZAOsse6AgX0oGFi_8YPiHo40XtctqBb6iS0pm_arW1MzYdz9Jw9Md8uu&lib=MV2nX0A1eB76PUG68lRaC6hUooDZbrH6F

It does. The one I gave you initially did too (If that makes a difference)

1 Like

Now do it from a web viewer and make sure you get the file created. It is better to have the web viewer with default URL or no URL and have a button to assig this as the URL and see if it will create the file.

If it does (which it should) then your solution is already in production. You just need to tweak it for your requirements.

1 Like

It does indeed create it. Is there a way to grab the string URL which displays at the end and return that to the app? That is what my end goal is, to get that string. My other question, is there a way to pass a variable to the script from the app?

Example: There is a variable for the sheetID in the script, so is there a way to through new values through parameters to that script? Therefore generating a new PDF?

1 Like

Yes there is.

The best way is to have a specific row in one of the sheets that you fill it with the required info such as:

  • filename
  • print settings
  • paper size

This will require a few changes in the app script to read the values from this row and use them but these changes are very minor/

Have another specific row in this sheet for the app script to write the results in this row instead of the current “execution console”

Of course there always other ways but this will be the best as you can update the “parameter row” and get the info from the “results row” to your app.

2 Likes

Thank you for that. That would definitely work for me. I would also like to make something that is easy to use for everyone. I was looking into the WebViewer docs, and I found on the GitHub page this

<script type="text/javascript">
    // when the button is clicked, send a message to the app
    document.getElementById('messageButton').onclick = function() {
      ThunkableWebviewerExtension.postMessage('hello world');
    }

    // when we get a message from the app, display it on the page
    ThunkableWebviewerExtension.receiveMessage(function(message) {
      document.getElementById('messageDisplay').innerHTML = message;
    });
</script>

My thought process was to send a random message, and the received message would send back the URL. Am I able to use this in this way?

I also found this on a YouTube video. Thunkable Basics: Get and Set Web View String (with aia file) - YouTube. Does any of this apply? Thanks for helping me through this!

1 Like

That will not be easy with Google App Script but it would still be doable should you want to take that route.

[Edit]

This is an example of the HTML extension for the Web Viewer. As you might be aware there is no block in Thunkable to compute dates, You cannot get the date in 17 days from today, for example. So I made an extension to use JavaScript to compute the date using the Web Viewer Extension.

Check this
https://x.thunkable.com/projectPage/60d06b27eb9be10011749fcd

2 Likes

That looks like what I am wanting to do, but what does the HTML look like? I am not able to see it.

1 Like

:raised_hands: ive tried bringing this up before. Felt like staff tried to shut it down when they mentioned they were unaware (or something like that) of momentjs / Luxon

The crazy part to me is the need for a library like this when building apps. Parsing seconds since 1970 into juman readable time manually sucks. Especially when considering leap years and crossing timezones. Not impossible but takes a lot of work.

Thunkable is built on react native. There is a moment library for react native. The platform could be even more powerful by adding this in. Plus, it’s a tiny library so it wouldn’t be a lot of extra weight on the apk/ipa

2 Likes

I posted it previously under this title

It has all the info including the .html content.

I hear you @jared but at least we can do such workarounds even though I’m not fan of Web Viewer as it is heavy and too much for such a tiny piece of code.

1 Like

Yep. I feel the same. Glad it’s there but I’d prefer a nicer/more elegant solution. (Like creating our own blocks perhaps and tying in libraries. Ya know, bring back extensions)

I’m sure it’s a lot of work but probably not impossible. Even a “run JavaScript” block would be nice with the ability to output custom object lists. It be nicer if they could draw elements on the screen but I feel at this point it may be a lot to ask for just a run JavaScript function block.

@wei @Steven @domhnallohanlon @jane

Do any of you think that (or any part of the above) may be an option in the future? It would make what’s possible now turbocharged to be able to run custom JavaScript let alone paint elements on the screen or better yet, create our own blocks (in RN or JavaScript) and visual elements (already close on this one with figma imports)

2 Likes

There will be no extensions as Apple doesn’t allow them.

Well that is a bummer. It would still be nice to have a more organized way to run these kind of functions. And @jared, a custom block creator would be really cool. I think back to the LEGO MINDSTORMS my blocks.

That’s only 1 option.

I would be pumped to see a run custom JavaScript box allowing for imports.

Since I have no idea what that is I can’t comment on whether that could be possible or not.

Since we can Already execute custom JavaScript within the web viewer sending and receiving data back-and-forth. It would be nice to see S bypassed the problem of adding the web you are adding the HTML linking to that HTML and then sending data back-and-forth that way.

It would be nice if we could I have a block that would just run the JavaScript within the block editor somehow

2 Likes