Create one PDF

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Create one PDF

Post by fko » Mon Jun 09, 2014 8:40 pm

Hi,

I was looking at the lessons of LiveCode and i didn't find what i am looking for ( i only found fow to print and how to add bookmarks)...

So, is it possible to create one document PDF and customize it during the execution?

When i say 'Customize' i am thinking in put one logo in one precise place, add text and also create one table (n columns x m rows ) with information to display.

Thanks in advance!!!

Regards,
fko

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Create one PDF

Post by bangkok » Mon Jun 09, 2014 10:47 pm

You can customize your PDF document as long and as far you can customize.... a card in a stack.
:)

Code: Select all

   ask file "Where to save the document ?" with "mydoc.pdf"
   if the result is "cancel" then exit to top
   put it&".pdf" into tFile
   set the printMargins to 0,0,0,0
   open printing to pdf tFile
   print  this card from 0,0 to 590,940
   close printing
So, change fields content, images and whatever else on a card, and then simply "print" the PDF file.

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: Create one PDF

Post by fko » Tue Jun 10, 2014 8:13 am

Hi Bangkok,

Thanks for your answer...:-)

I will do it like this...In the beginning i didn't take this option in consideration because i imagine that doing like this was more using one template than create it and customize it from zero...
But yes, maybe the easiest way is to make some templates and customize them...:-)

The only way to print this card is to open it first, no? Becuase i tried and i had one error as the stack was not open...
Or there is one way to print it with no need to open the stack first?

I am trying to generate one PDF and send it by mail...So for me there is no a real necesity to open it before to send it by mail...

regards,
fko

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: Create one PDF

Post by fko » Tue Jun 10, 2014 1:52 pm

Hi,

Finally I customized some different stacks to fill them with the different info (depending on the case) i would like to put in the PDF i want to send by mail...
And this is working ok...

Now my problem is sending the mail...

I read in the lessons and in the forum and it seems difficult to do what i want ( create one pdf and send it directly by mail) ...:-(
I would like to send one mail, and attach the PDF document i just created before.

I followed the steps in these two lessons:

"How do I Create an HTML E-Mail?" and "How do I Attach a File to an E-Mail?"

I can send one e-mail as it is explaied in the first lesson.

But i can't attach the file...In fact i see that the file is attached but the size is 0 bytes...
I tried this with several files ( PDF, TXT, PNG, etc...) but always the size is 0 bytes...


This is the script of the button Launch:

local lvLaunchString
global gvAttachment


command populateLaunchString @pLaunchString avToken avArgument
if avArgument is empty then exit populateLaunchString
if pLaunchString is not empty then put pLaunchString & "," into pLaunchString
put pLaunchString & avToken & "'" & avArgument & "'" into pLaunchString
end populateLaunchString


on mouseUp

put empty into lvLaunchString
populateLaunchString lvLaunchString, "to=", the text of field "toField"
populateLaunchString lvLaunchString, "cc=", the text of field "ccField"
populateLaunchString lvLaunchString, "subject=", the text of field "subjectField"
populateLaunchString lvLaunchString, "body=", the text of field "bodyField"
populateLaunchString lvLaunchString, "attachment=", gvAttachment

if the platform is "MacOS" then # we are on a Mac
put "/Applications/Thunderbird.app/Contents/MacOS/thunderbird-bin -compose" && lvLaunchString into lvLaunchString
else if the platform is "Win32" then # we are on Windows
put "C:\Program Files\Mozilla Thunderbird\thunderbird.exe -compose" && lvLaunchString into lvLaunchString
else # we do not support this platform
exit to top
end if

set the hideConsoleWindows to true
open process lvLaunchString for update
close process lvLaunchString
put empty into gvAttachment
end mouseUp


And this for the button Attach:

global gvAttachment

on mouseUp
# open the file selection dialog
answer file "Select a File to Attach"
if it is empty then exit mouseUp

# add the selected attachment to other possible attachments
if gvAttachment is not empty then put gvAttachment & "," into gvAttachment
put gvAttachment & it into gvAttachment
end mouseUp

What am i doing worng for the attachment? Sending mails without attachment is working...

I am working in Windows platform, but i also would like it will work to OS, IOS, and Android...

It is a pity that we can't send the mail directly from LiveCode and need to do it from ThunderBird...:-(
Or maybe it is possible but it is me who understood bad?
The application would be more 'clean' and 'clear' if we could do this without pass from another one ( in this case Thunderbird)...

regards,
fko

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Create one PDF

Post by bangkok » Tue Jun 10, 2014 1:59 pm

fko wrote: It is a pity that we can't send the mail directly from LiveCode and need to do it from ThunderBird...:-(
Or maybe it is possible but it is me who understood bad?
It's possible.

-you can use a SMTP library :
http://forums.livecode.com/viewtopic.ph ... TP#p104961

-you can "outsource" the work... using a remote server with a special LiveCode script or a PHP script
http://lessons.runrev.com/m/4070/l/8184 ... er-scripts

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: Create one PDF

Post by fko » Tue Jun 10, 2014 2:55 pm

Hi,

I tried with Sarah's SMTP Demo but i had one error...i don't remember now exactly but was something like "error sending mail: badread"...

And the second link was for OSX and Unix...And i am doing it in Windows...:-(

And for attachment error, do you have an idea why it is not working? Thanks in advance...:-)

regards,
fko

AxWald
Posts: 578
Joined: Thu Mar 06, 2014 2:57 pm

Re: Create one PDF

Post by AxWald » Tue Jun 10, 2014 5:14 pm

Hi,
fko wrote:It is a pity that we can't send the mail directly from LiveCode and need to do it from ThunderBird...:-(
since you say:
fko wrote:And i am doing it in Windows...:-(
Have you ever tried Blat? I haven't tried yet (still using a prehistoric version of Pegasus Mail ...), but what I've seen looks quite good.

And since I just checked the Pegasus site for the URL, I found out that it's still alive, and supports even IMAP now! Whow!
It's not easy to configure, but very powerful, and once configured properly, very reliable.

Sending EMails (with any even so alien features) using it via Shell command + cmd line arguments isn't hard, I do it from Access all the time. And since all you need to do is to create the files, then pass them via cmd line arguments, I see no reason why it shouldn't work.

(Pegasus accepts a huge amount of cmd line arguments, basically anything that you can configure at all - and it has no problem to run as multi-user, too ...)

And since Pegasus has proven to be an extremely well behaving piece of software, you might even want to have it running as a windows service, using NSSM ;-))

Hope I was able to point you to some maybe helpful resources!

(I'm still blown away - I spent hours today to search for an IMAP solution that I can use from LC, and now I find out that good old Pegasus is still alive after all these years, and can do this meanwhile - must.try.out!)

Have fun!
All code published by me here was created with Community Editions of LC (thus is GPLv3).
If you use it in closed source projects, or for the Apple AppStore, or with XCode
you'll violate some license terms - read your relevant EULAs & Licenses!

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: Create one PDF

Post by fko » Tue Jun 10, 2014 7:07 pm

Hi,

Thanks for your answer...

So, i never used Blat...:-(
Even if i know Pegasus mail...:-)

I will look to see if it is easy to implement and if it will be useful for one next version to can use it in Windows, OSX, IOS, Android...

regards,
fko

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Create one PDF

Post by Simon » Tue Jun 10, 2014 8:54 pm

Hi fko,
Android and iOS already have attachments solved in liveCode.

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: Create one PDF

Post by fko » Tue Jun 10, 2014 9:04 pm

Hi Simon,

Yes i already saw that the option for IOS and Android exists...:-)

I was thinking in one solution all in one...:-)

May i have your mind why it is not working the example i copied from the lesson to can attach files in the mails? I made one copy and paste, and i respected also the name of fields and buttons...
To send mails is working fine, but not to attach them...:-(
As the size of the attached files is always 0 bytes...

Thanks in advance!!! :-)

regards,
fko

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Create one PDF

Post by Simon » Tue Jun 10, 2014 9:23 pm

Hi fko,
Download this stack:
"Updated stack using composeMail"
from here:
http://quality.runrev.com/show_bug.cgi?id=11895
it's fixed in liveCode 6.6.2

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Create one PDF

Post by bangkok » Tue Jun 10, 2014 9:51 pm

There is another way : a remote emailer.

Have a look at :
http://mandrill.com/

-you can open a free account

-then with LiveCode you can easily compose a JSON query (with email address, subject, attached files etc.), post it to Mandrill... and it will send your email.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Create one PDF

Post by Simon » Tue Jun 10, 2014 10:02 pm

Of course MailChimp!
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

fko
Posts: 61
Joined: Tue May 20, 2014 2:13 pm

Re: Create one PDF

Post by fko » Wed Jun 11, 2014 11:50 am

Hi,

Thanks for the answer...:-)

It seems a good solution...:-)

And it is cool to learn something new...Was a nice council

Now, after learning how it works, i managed to do the below code...
So, from Mandrill i could send one test mail, and then attach one file...Or quite!!! :-)
Because in the test mail i receive i have one attached file even if with one worng name...

This is my document "MyPDF.pdf"
and this where is is placed the file "C:/Users/fko/Downloads/Lc"

So, in the "name" ( of the attachment), i wrote : "C:/Users/fko/Downloads/Lc/MyPDF.pdf"

And this is the wrong attached file i have in the mail i received, as i recieved one "PDF" file with this name "C:/Users/fko/Downloads/Lc/MyPDF.pdf"...

So how i can correct this???

And once is corrected...How i should do from LiveCode to use this code i made??????

function log(obj) {
$('#response').text(JSON.stringify(obj));
}

// create a new instance of the Mandrill class with your API key
var m = new mandrill.Mandrill('MYAPIKEY');

// create a variable for the API call parameters
var params = {
"message": {
"text": "Example text content3",
"subject": "example subject3",
"from_email": "Mymail@gmail.com",
"to": [{"email": "TheOtherMail@hotmail.com"}],
"attachments": [
{
"type": "text/plain",
"name": "C:/Users/fko/Downloads/Lc/MyPDF.pdf",
"content": "ZXhhbXBsZSBmaWxl"
}
],
}
};

function sendTheMail() {


m.messages.send(params, function(res) {
log(res);
}, function(err) {
log(err);
});
}


regards,
fko

bangkok
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 937
Joined: Fri Aug 15, 2008 7:15 am

Re: Create one PDF

Post by bangkok » Wed Jun 11, 2014 12:56 pm

fko wrote: function log(obj) {
$('#response').text(JSON.stringify(obj));
}

// create a new instance of the Mandrill class with your API key
var m = new mandrill.Mandrill('MYAPIKEY');
This is not LiveCode code.

Use the stack in attachment :

-paste your mandrill key
-type your email address
-select a PDF file
-send

It will help you to understand what you have to do (the JSON query is just... text with a special format).

And then after with the Mandrill API documentation, you can customize to your needs.
Attachments
TEST_EMAIL mandril.zip
(1.59 KiB) Downloaded 322 times

Post Reply