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

3 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

A few weeks ago you tried to help me but you were in the middle of some mobile projects and couldn’t help. Just checking to see if your workload is better and you could provide some guidance. I put api2pdf on hold as I couldn’t get the api to work in serverconnect. If you have a chance, I’d still like to conquer this. Basically, I would like to have a server connect which allows me to send a url and have it saved as pdf and emailed to someone. Ideally, I’d like to store it as well on my server but I could also have it download to my computer. Any help would be greatly appreciated.

Thanks,
Rick

Hi Rick… sorry but this hasn’t bubbled to the top of my list yet.

Loads of experience here in the forum though… surely somebody has done this… they’ll chime in soon. :slight_smile:

Hi @marsalstudios, You’ll need to use PHP to download the PDF from the api url. Something like this will download the file from the URL, save to your directory and return a success message. You can always change the directory if needed.

<?php 
  
// Initialise a file URL 
$url = 'https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf'; 
  
// Use basename() function to return the name of file  
$file_name = basename($url); 
   
// Use file_get_contents() function to get the file from URL and
// use file_put_contents() function to save the file by using the name 
if(file_put_contents( $file_name,file_get_contents($url))) { 
    echo "File downloaded successfully"; 
} 
else { 
    echo "File downloading failed."; 
} 
  
?>

I should also add that the download will override any existing file. So if your file is called invoice.pdf and there is already a file called the same in your directory it will override that one.