Logic Machine Forum
LM and PDF? - Printable Version

+- Logic Machine Forum (https://forum.logicmachine.net)
+-- Forum: LogicMachine eco-system (https://forum.logicmachine.net/forumdisplay.php?fid=1)
+--- Forum: Scripting (https://forum.logicmachine.net/forumdisplay.php?fid=8)
+--- Thread: LM and PDF? (/showthread.php?tid=2341)



LM and PDF? - MarcusH - 13.11.2019

Hi

I've tried to search for this, but can't find anything.

Is it possible to somehow create a template with scripting that can import values from LM database and visualize it with graphs and all the imported values and send it to mail as an PDF without third party services?

The case is, im creating a energy monitoring system.
My initial tought was to just send a pre fabricated CSV file to the owner, but started to think it might be better to create a PDF document which was sent to the owner every month with graphs and values for each office area or industrial building which makes it easier to bill their different tenants.

Best regards
Marcus


RE: LM and PDF? - Erwin van der Zwart - 13.11.2019

Hi,

Why not build a html page and add it to the mail? This way you can make a great layout with any format you like and add it to the body of the mail.

I have some energy report samples with tables so it shows how to do that but you need to optimize them..

BR,

Erwin


RE: LM and PDF? - MarcusH - 14.11.2019

(13.11.2019, 15:50)Erwin van der Zwart Wrote: Hi,

Why not build a html page and add it to the mail? This way you can make a great layout with any format you like and add it to the body of the mail.

I have some energy report samples with tables so it shows how to do that but you need to optimize them..

BR,

Erwin

Great!

If you could share it with me, I would be very greatfull Big Grin  

I've not used html that much, but everytime is a first.

Best regards
Marcus


RE: LM and PDF? - Erwin van der Zwart - 14.11.2019

Hi,

Here is a sample how to build a HTML formatted energy report.
.lua   HTML Energy Report.lua (Size: 4.81 KB / Downloads: 122)


BR,

Erwin


RE: LM and PDF? - Geert - 15.03.2020

Hi,

How can I combine the HTML report with a csv attachment?


RE: LM and PDF? - admin - 16.03.2020

See this thread: https://forum.logicmachine.net/showthread.php?tid=394
3rd argument (message) should contain HTML that you want to send.


RE: LM and PDF? - Geert - 19.03.2020

Hi Admin,

It's not quite clear for me how I can implement HTML text with variable text into the Message


Code:
    -- adjustable information

AantalECG = 189                                              -- Aantal armaturen                             
MainEmail = 'example@example.be'                              -- mailadres voor main email
Subject = '72.01 resultaat functietest_'  ..os.date('%F , %X')            -- Onderwerp email
Message = '72.01 resultaat functietest op '  ..os.date('%F , %X')        -- Bericht in email
Filename = os.date("%y%m%d")..'_72.01_functietest.csv'                -- Naam voor csv-bestand
FINummer = 72.01                                                                                                        -- FI nummer van het gebouw

   -- get current data as table
now = os.date('*t')
   
current_hourandseconds = string.format("%02d", now.hour)  .. ":" .. string.format("%02d", now.min)
current_date = string.format("%02d", now.day) .. "-" .. string.format("%02d", now.month) .. "-" .. now.year



-- HTML text to implement in Message

htmldata = [[<html style="font-family:Arial">
<body>

  <h1>]] ..FINummer.. [[ Attest functietest </h1>

<p>Beste,</p>
  <p>Hierbij bevestigen wij u dat op ]] .. current_date .. [[ om ]] .. current_hourandseconds .. [[ uur een functietest van de veiligheidsverlichting voor het gebouw met FI-nummer ]] ..FINummer.. [[ werd uitgevoerd.</p>
  <p>De resultaten van deze functietest zijn opgenomen als bijlage: ]] ..Filename.. [[ van een mail verzonden vanaf example@example.be.</p>
 
  <table style="width:100%">
    <tr>
        <td><b>Aantal armaturen</b></td>
        <td><b>Resultaat</b></td>
    </tr>
    <tr>
  <td>]] .. AantalECG.. [[</td>
    <td>]] ..FINummer.. [[</td>
    </tr>
</table>


<p>Wanneer u vragen heeft over het testrapport kunt u contact opnemen met example@example.be.</p>
<p>Dit rapport is verzonden op ]] .. current_date .. [[ om ]] .. current_hourandseconds .. [[ uur.</p>
</body>
</html>]]

-- Sending main email

  res, err = mailattach(MainEmail, Subject, Message , Filename, csv, 'text/csv')
  log(res, err,'main email sent') 

    script.disable(_SCRIPTNAME) 
    end



RE: LM and PDF? - admin - 19.03.2020

What kind of variables do you want to add?


RE: LM and PDF? - Geert - 19.03.2020

Hi,

The variables I want to add  are implemented in the HTML text as shown in the testscript:

]] ..FINummer.. [[
]] ..current_date.. [[
]] ..current_hourandseconds.. [[
]] ..Filename.. [[
]] ..AantalECG.. [[

For every project variables are put on top ( --adjustable information--) to change depending the project.

Now the message in my mail is as shown at the top, but I want to replace it by the HTML text (--HTML text to implement in Message--)


RE: LM and PDF? - admin - 19.03.2020

Line 48 is incorrect, try this:
Code:
res, err = mailattach(MainEmail, Subject, htmldata, Filename, csv, 'text/csv')



RE: LM and PDF? - Geert - 19.03.2020

Thx again!


RE: LM and PDF? - Fahd - 05.05.2023

(14.11.2019, 08:56)Erwin van der Zwart Wrote: Hi,

Here is a sample how to build a HTML formatted energy report.


BR,

Erwin

Hi, 

While I'm trying to use the script from Erwin van der Zwart I got this error in the logs, 
Quote:* string: error:1408F10B:SSL routinesConfusedsl3_get_record:wrong version number



RE: LM and PDF? - admin - 05.05.2023

Change secure = 'sslv23', to secure = 'tlsv1_2',


RE: LM and PDF? - Fahd - 05.05.2023

(05.05.2023, 07:14)admin Wrote: Change secure = 'sslv23', to secure = 'tlsv1_2',
Forget to mention that I changed this part 
    headers = {
   
    from = "sed <xxx>",
    to = "Rcpt Name <xxx>",
    subject = "Report"
  },

    body = {
        [1] = {
            headers = { ['Content-type'] = 'text/html' },
      body = htmldata
    },
    }
}
r, e = smtp.send{
    rcpt = "<xxx>" ,
    from = '<xxx>',
    source = ltn12.source.chain(source, filter),
    user = 'xxx',
    password = 'xxx',
    server = 'smtp.office365.com',
    port = 587,
    secure = 'tlsv1_2',
}


RE: LM and PDF? - admin - 05.05.2023

For port 587 you need to change secure to starttls instead of tlsv1_2


RE: LM and PDF? - Fahd - 05.05.2023

(05.05.2023, 07:25)admin Wrote: For port 587 you need to change secure to starttls instead of tlsv1_2

Thanks a lot  Big Grin