Writing and emailng a pdf document from within wappler

Any good new way to do this without just using the windows print command. I’d like to save a table or form as pdf with a specified name, then email it to a client. Currently, I have to do this manually and would love to automate the process using wappler. any update on whether this functionality will be possible in Wappler soon?

Thanks,
Rick

Hi Rick,

I would imagine there would be some Adobe licensing hurdles to overcome to be able to add that to Wappler? It’s not Open Source so it may not be able to be done.

With Wappler not having a module to translate an HTML to PDF, here are a couple of suggestions.

I have used TCPDF which is based on FPDF. This will need a bit of manoeuvring, but it can be done.

I have not tried Api2Pdf, but this seems a more doable solution for Wappler.

1 Like

thanks, very intrigued with APi2Pdf as it does seem to be a cost effective answer to what I want. Can’t get it work at the moment so asking their support people for help. I do think there is something here worth looking at. Just can’t understand their documentation.

Rick

cant get api2pdf to work. Any one tried this?

Yep, this is what I use. Where are you having trouble?

great. I’m just trying to get started and installing it. I copied the files to my server and then tried a very simple case to test it out using their documentation but I don’t see anything happening. The support people weren’t much help. Perhaps you can steer me in the right direction. I’m just trying to get a url to be saved and displayed as a pdf. Here is the code I’m trying to use:

<!doctype html>
<html>

<head>
	<meta charset="UTF-8">
	<?php
require_once 'api2pdfcode/Api2Pdf.php';
require_once 'api2pdfcode/ApiResult.php';

Use Api2Pdf\Api2Pdf; 

    

  $apiClient = new Api2Pdf('07f7186d-32cb-4d0b-b816-8adf2d6fa687');

 
  $pdfLink = $result->getPdf();
 ?>

</head>

<body>
	<?php
	
	$apiClient->setInline(true);
  	
	

$apiClient->setInline(true);
$apiClient->setFilename('testing.pdf');
$result = $apiClient->wkHtmlToPdfFromHtml('<p>Hello, World</p>');
  header('Location: '.$result->getPdf());
  exit; 


 ?>


</body>

</html>

Okay, here ya go.

In a nutshell, I open a modal on the front end that triggers a server action that performs the api call to create the pdf. The modal shows a “your report is being prepared” message during creation, and then displays a link the pdf once finished.

Server Action:

Use your own Authorization key in the header.

URL:

https://v2018.api2pdf.com/chrome/url

JSON Data (my specific data removed to simplify):

{
  "fileName": "Report filename",
  "url": "https://{{$_SERVER['HTTP_HOST']}}/sample.php?parameter1=abc",
  "options": ""
}

Make sure you use the Define API Schema option when building your server action, so the results of the api are exposed to the front end.


Front end Modal:

The server connect is triggered to load when the modal opens (User clicks “Download report” button and the modal opens to start the process.) The link element is hidden while the server connect is executing, and dynamically sets the link value based on the results of the server connect:

Screen Shot 2020-01-16 at 7.38.33 AM

I use a border spinner to let the user know something is happening during the server connect execution:

Screen Shot 2020-01-16 at 7.38.48 AM

2 Likes

thank you so much. I’m trying to follow this to test. I created the server action as you stated. For my JSON data, I put
{
“url”: “https://www.marsalstudios.com/admin/edit-proposal-sheet.php”,
“inlinePdf”: true,
“fileName”: “testing.pdf”,
“options”: “”
}

would that create a pdf file named testing.pdf located in my root folder from the url shown at the top?

For the modal I was confused by the link data. you had the link value as create_rpt.data.pdf.data.pdf
Is that the correct syntax, seems weird. It didn’t work so wondering if that’s the issue.

I’m so happy that you are willing to work with me here. I really need this to work. It will be so useful.
thanks again,
Rick

Hey Rick,

I didn’t go with inlinepdf. I just have the api produce a link, and I present that to the user. The pdf never comes to my server. I’m neck deep trying to start a couple mobile apps, so I’m sorry I can mock up the inline scenario for you!

And yes, that is the correct syntax – just seems odd given the names I used match the api names.

–Ken