I currently have an action button for Print which on click generates the PDF exporter which within chrome auto downloads to the browser. Currently I need to click to open the pdf and than use computer browser print to print which once again adds the step to click print on the print preview
Is there a way to auto print the PDF generated from PDF exporter
I don't believe there is a way to directly print from within Retool. Since all JS in Retool is run in a sandbox, so a lot of window functions (like window.print() )won't work here. You can however use window.print() in a custom component if you toggle on "allow modals" in the component inspector and pass your PDF to the component through the model but this would print the full custom component iframe, you may be able to use a JS library from here, but I haven't had any luck yet with my current setup using printJS
Hey @seandawes — I see full transparency here, at the moment, mobile development has not been a primary focus. We do have a team now dedicated to mobile development so hopefully, this will be even better soon! In the meantime, I believe the best approach for building out an easily customizable packing slip would either be the window.print() in a custom component or possibly an external API. Do you think either of these could work for your use case here?
If you are looking to download a PDF of a portion of your app, you can use utils.downloadPage() and pass this function two params, the first would be a string representing your desired file name and the second is an object of additional optional params. Here's a link to our docs on this that could be helpful here. Let me know if you have any questions!
I think I can just achieve this using the pdf exporter as on mobile like ipad its not that bad to click to print. I tried doing the utils.downloadPage() but not a fan
Had a question. So my goal is printing packing slips for orders. So I have basically a SQL query which shows all order contents. If the order contains 1 item, its nice and clean in the pdf exporter, but if the order contains more than 1 row of data in my sql query it is combining them by column.
So to get the format you want, you can use a transformer to format the data the way you need it. Based on what you are returning now, it looks like you'd need to iterate through the packing_slip data and utilize i to group the name, SKU, and quantity as desired.
Here's an example of what it could look like when you're keying into that array:
SQL which is taking the order number and pulling all data for that order number. So an order can contain more than 1 item. SQL is triggered on click of PRINT button which success of SQL triggers pdf exporter
Hey seandawes, I'll be stepping in for Jay here and I apologize for the very long delay. If I'm understanding your problem correctly, then you can use a JS query to create a long string that you can pass to your PDF Exporter. This query will allow you to programmatically separate out multiple items if multiple items are present. Here is an example of what that could look like:
In my JS query, I first make sure that my data is formatted as an array of objects (using formatDataAsArray) if it isn't already in that format. Then I loop over each object in the array and concat the values with their headers to a string with newline characters as needed. Finally I trigger my PDF export query with query.trigger() passing the string to the exportPDF query using additionalScope. In my exportPDF query I can reference the str variable defined in additionalScope. It will show up as undefined in the query input but when I trigger that query using query.trigger() and pass str as a key, value pair in additionalScope, the value will be defined.