Welcome to the nuBuilder Forums!
Register and log in to access exclusive forums and content available only to registered users.
Register and log in to access exclusive forums and content available only to registered users.
Generate a pdf file and send it by email Topic is solved
-
- Posts: 315
- Joined: Sun Mar 14, 2021 8:48 am
- Location: Geneva
- Has thanked: 87 times
- Been thanked: 11 times
Generate a pdf file and send it by email
Hello,
I have created an application that is able to generate invoices based on youtube nubuilder videos. Very detailled. I would like to improve the solution by sending the ticket by email. To retrieve the ticket into pdf file, you have only to download it from the navigator.
Anyone has an idea about :
- how to generate the ticket in pdf format from an action button
- how to attach this pdf into an email template and send it via an action button.
I have read some litterature about xml generation - related to the DOM - nothing about pdf generation in nubuilder. Is it something possible ?
Many thanks for your answer.
Yves
I have created an application that is able to generate invoices based on youtube nubuilder videos. Very detailled. I would like to improve the solution by sending the ticket by email. To retrieve the ticket into pdf file, you have only to download it from the navigator.
Anyone has an idea about :
- how to generate the ticket in pdf format from an action button
- how to attach this pdf into an email template and send it via an action button.
I have read some litterature about xml generation - related to the DOM - nothing about pdf generation in nubuilder. Is it something possible ?
Many thanks for your answer.
Yves
-
- Posts: 315
- Joined: Sun Mar 14, 2021 8:48 am
- Location: Geneva
- Has thanked: 87 times
- Been thanked: 11 times
Re: Generate a pdf file and send it by email
I have found how to generate the pdf on the server. You have to use the function nuRunReportSave() which generate the report in the Temp file on the server.
In the Custom Code tab of the form behind Edit
I don't know yet how you could know the name of the pdf file in order to attach it in an email.
In the Custom Code tab of the form behind Edit
Code: Select all
nuAddActionButton('pdfButton', 'GeneratePdf', 'nuRunReportSave("FAC")');
-
- Posts: 315
- Joined: Sun Mar 14, 2021 8:48 am
- Location: Geneva
- Has thanked: 87 times
- Been thanked: 11 times
Re: Generate a pdf file and send it by email
Hello Kev1n,
Thanks for this explanation. The logic is that I have to generate the report with nuRunReportSave() and then send it with nuSendEmail().
1.- How do I know the name of the generated report ?
I don't know how to know the name of the file. I changes overtime for the same report, I suspect that the moment of the generation is used for generating the name. How can I retrieve that ?
2.- The way you use nuRunReportSave() function is different with what is explained in the doc.
I have also another issue : it seems that the nuRunReportSave() doesn't work as explained in your last post if I compare the arguments and what I have in the documentation.(link to the doc). If I look in the doc, I have got the following information : nuRunReportSave(string1)<-- I use it in that way and it works perfectly.
I don't have the ability to have 3 parameters as in your explanation, only one, the report.
There is also written that the attachment sent is not deleted, which is not your explanation in the thread. Has this function been reviewed since your post ?
What is the correct syntax, where is the ref of those function without disturbing you ? What is the way to retrieving the name of the generated report ?
3.- Pb with the attachment via nuSendMail() --> attachment is corrupted during the send.
I have also used the nuSendMail() in the PHP After Save. I use the syntax mentionned in the documentation. (link to the doc)
nuSendEmail('to@test.com','from@test.com','From','Content','Subject', ['$attachmentname'=>'$filepathtoattachment'], true, 'cc_email@test.com', 'bcc_email@test.com').
It sends the email and the pdf attachment but the attachment is for some reasons is corrupted : you cannot download it or open it in any webmail. I don't know how to fix that.
Many thx for your help. Very helpful anyway, it points me to the right direction.
Yves
Thanks for this explanation. The logic is that I have to generate the report with nuRunReportSave() and then send it with nuSendEmail().
1.- How do I know the name of the generated report ?
I don't know how to know the name of the file. I changes overtime for the same report, I suspect that the moment of the generation is used for generating the name. How can I retrieve that ?
2.- The way you use nuRunReportSave() function is different with what is explained in the doc.
I have also another issue : it seems that the nuRunReportSave() doesn't work as explained in your last post if I compare the arguments and what I have in the documentation.(link to the doc). If I look in the doc, I have got the following information : nuRunReportSave(string1)<-- I use it in that way and it works perfectly.
I don't have the ability to have 3 parameters as in your explanation, only one, the report.
There is also written that the attachment sent is not deleted, which is not your explanation in the thread. Has this function been reviewed since your post ?
What is the correct syntax, where is the ref of those function without disturbing you ? What is the way to retrieving the name of the generated report ?
3.- Pb with the attachment via nuSendMail() --> attachment is corrupted during the send.
I have also used the nuSendMail() in the PHP After Save. I use the syntax mentionned in the documentation. (link to the doc)
nuSendEmail('to@test.com','from@test.com','From','Content','Subject', ['$attachmentname'=>'$filepathtoattachment'], true, 'cc_email@test.com', 'bcc_email@test.com').
It sends the email and the pdf attachment but the attachment is for some reasons is corrupted : you cannot download it or open it in any webmail. I don't know how to fix that.
Many thx for your help. Very helpful anyway, it points me to the right direction.
Yves
-
- Posts: 315
- Joined: Sun Mar 14, 2021 8:48 am
- Location: Geneva
- Has thanked: 87 times
- Been thanked: 11 times
Re: Generate a pdf file and send it by email
just looked into the code, I see that 3 parameters are possible for nuRunReportSave(). Where is documented without going in deep into the code ?
In your example, tag=null and ReportCreated hasn't got any parameter. It maybe the callback mechanism, I don't know. Very difficult without more explanation. It seems that you call reportCreated without parameter and retrieve in that way the name of the file. Is it true ?
Many thanks for helping me, maybe we have to switch in PM and take you as teacher for sometimes 
In your example, tag=null and ReportCreated hasn't got any parameter. It maybe the callback mechanism, I don't know. Very difficult without more explanation. It seems that you call reportCreated without parameter and retrieve in that way the name of the file. Is it true ?
Code: Select all
nuRunReportSave('FR0', null, reportCreated);
function reportCreated(filename, id) {
nuSetProperty('filename', filename);
nuRunPHPHidden('sendemail',0);
}

-
- nuBuilder Team
- Posts: 4291
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Generate a pdf file and send it by email
1. The filename can be retrieved in the callback function.
It contains a "nupdf_" prefix followed by a unique id and the extension ".pdf"
2. The two additional parameters are not yet documented. You'll see the declaration in nuajax.js
3. I'll have to test that.
It contains a "nupdf_" prefix followed by a unique id and the extension ".pdf"
2. The two additional parameters are not yet documented. You'll see the declaration in nuajax.js
3. I'll have to test that.
-
- nuBuilder Team
- Posts: 4291
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Generate a pdf file and send it by email
yvesf wrote: ↑Thu Dec 29, 2022 10:53 am It seems that you call reportCreated without parameter and retrieve in that way the name of the file. Is it true ?Code: Select all
[/quote] In nuRunReportSave you just pass the name of the callback function without its parameters.
-
- nuBuilder Team
- Posts: 4291
- Joined: Sun Oct 14, 2018 6:43 pm
- Has thanked: 71 times
- Been thanked: 444 times
- Contact:
Re: Generate a pdf file and send it by email
Use the code from the topic above (last post) to send emails. It works fine for me and the file/attachment is correctly transferred.
To interpolate a string in PHP, you need to enclose the string literals in double quotes
Code: Select all
["$attachmentname"=>"$filepathtoattachment"]
-
- Posts: 315
- Joined: Sun Mar 14, 2021 8:48 am
- Location: Geneva
- Has thanked: 87 times
- Been thanked: 11 times
Re: Generate a pdf file and send it by email
Hello Kev1n,
I can send the attachment but when I download it impossible to open it (decode). Prior to having sent no pb for opening the file. It maybe due to its size. When I try to attach it to message, I have the messazge in status ; upload rejected as possible attack vector. I will remove image and see if it fix the issue. Another issue is that email sent goes systematically into spam.
Any idea ?
Yves
I can send the attachment but when I download it impossible to open it (decode). Prior to having sent no pb for opening the file. It maybe due to its size. When I try to attach it to message, I have the messazge in status ; upload rejected as possible attack vector. I will remove image and see if it fix the issue. Another issue is that email sent goes systematically into spam.
Any idea ?
Yves
-
- Posts: 315
- Joined: Sun Mar 14, 2021 8:48 am
- Location: Geneva
- Has thanked: 87 times
- Been thanked: 11 times
Re: Generate a pdf file and send it by email
Here is the code of the sendemail procedure
Removing the image hasn't solved the issue I am facing with attachment.
The project is quite simple and accessible on
nufacture
id : ga
pwd : nu
Any idea would be welcome.
Yves
PS : you can modify the project to fix it, I have a backup copy
Code: Select all
$file = "#filename#";
nuSendEmail('yves.feigneux@yopmail.com','yves.feigneux@alpilogic.fr','Yves Feigneux','test','envoi facture', [$file=>"/home/clients/7563ee0badfa11c515e43b50a7e37899/web/nufacture/temp"], true);
The project is quite simple and accessible on
nufacture
id : ga
pwd : nu
Any idea would be welcome.
Yves
PS : you can modify the project to fix it, I have a backup copy