How to use EasyPDFMaker in NetTalk server app

<< Click to Display Table of Contents >>

Navigation:  EasyPDFMaker documentation > Getting started > Step by Step > Working with PDF file > Conceptual examples >

How to use EasyPDFMaker in NetTalk server app

Previous pageReturn to chapter overviewNext page

The example app is web2.app from %Clarion%\accessory\Capesoft\NetTalk\Web Server\BasicWithMenu (2) folder.

 

1. Add global extensions EasyHtml, then EasyPDFMaker.

 

2. Create new procedure PDFGenerator with a prototype (STRING pReportType). On Data/Tables Pad add all files used to generate PDF reports:

MailBoxes and Alias.

 

3. Add procedure extension EasyPDFMaker

 

4. In Data section embed point declare a window with 2 buttons Run and Close:

 

Window                 WINDOW('PDF generator'),AT(,,260,100),CENTER,GRAY,FONT('Segoe UI',9)

                        BUTTON('Run'),AT(151,77,39),USE(?bRun)

                        BUTTON('Close'),AT(209,77,36),USE(?bClose)

                      END

 

5. In Other declarations embed point declare 2 local procedures for 2 PDF reports - MailBoxes and Alias:

 

MAP

  Build::Mailboxes(*TDocDefinition dd)

  Build::Alias(*TDocDefinition dd)

END

 

6. In Processed code embed point load html script and open hidden window.

On EVENT:OpenWindow call pdfMaker.Run() method to generate PDF:

 

OPEN(Window)

0{PROP:Hide} = 1

pdfMaker.Load('.\PdfMake\EasyPDFMaker.html')

 

ACCEPT

   CASE EVENT()

  OF EVENT:OpenWindow

    POST(EVENT:Accepted, ?bRun)

  END

 

   CASE ACCEPTED()

  OF ?bRun

     pdfMaker.Run()

  OF ?bClose

    POST(EVENT:CloseWindow)

  END

 END

pdfMaker.Kill()

 

 

7. In EasyPDFMaker->pdfMaker->Run->Doc Definition embed point call appropriate procedure regarding passed pReportType parameter:

 

CASE UPPER(pReportType)

OF 'MAILBOXES'

SELF.pdfFile = '.\PdfMake\MailBoxes.pdf'

Build::Mailboxes(dd)

OF 'ALIAS'

SELF.pdfFile = '.\PdfMake\Alias.pdf'

Build::Alias(dd)

END

 

8. In EasyPDFMaker->pdfMaker->Run->After Parent embed point execute a code which closes this procedure:

 

POST(EVENT:Accepted, ?bClose)

 

9. In Local procedures->After EasyPDFMaker methods embed point implement local procedures Build::Mailboxes and Build::Alias:

 

Build::Mailboxes             PROCEDURE(*TDocDefinition dd)

rowStyle                       CSTRING(65)

CODE

dd.AddDocInfo('title', 'Mailboxes report')

dd.AddDocInfo('author', 'Mike Duglas')

dd.AddDocInfo('subject ', 'Mailboxes report')

dd.PageSettings('A4', 'portrait')

!- styles

dd.AddStyle('header', '"fontSize": 18, "bold": true, "margin": [0, 0, 0, 10]')

dd.AddStyle('subheader', '"fontSize": 16, "bold": true, "margin": [0, 10, 0, 5]')

dd.AddStyle('tableExample', '"margin": [0, 5, 0, 15]')

dd.AddStyle('tableHeader', '"fontSize": 13, "bold": true, "color": "black"')

dd.AddStyle('pageFooter', '"margin": [0, 5, 0, 15]')

!-- rows

dd.AddDefaultStyle('"fontSize": 10')

 

dd.BeginContent()

!- columns:

 !Number|Name|StartDate

 !Name column occupies all available space (width = "*")

dd.BeginTable('"style": "tableExample", "widths": ["auto", "*", "auto"]')

!- header row

dd.BeginRow()

dd.AddText('Number', '"style": "tableHeader"')

dd.AddText('Name', '"style": "tableHeader"')

dd.AddText('StartDate', '"style": "tableHeader"')

dd.EndRow()

 

rowStyle = ''

Access:MailBoxes.UseFile()

SET(MAI:PrimaryKey)

LOOP WHILE Access:MailBoxes.Next() = Level:Benign

   dd.BeginRow()

 

  dd.AddText(MAI:MailBoxNumber, rowStyle)

  dd.AddText(CLIP(MAI:MailBoxName), rowStyle)

  dd.AddText(FORMAT(MAI:StartDate, @d17b), rowStyle)

 

  dd.EndRow()

END

dd.EndTable()

 

dd.EndContent()

 

Build::Alias                 PROCEDURE(*TDocDefinition dd)

rowStyle                       CSTRING(65)

CODE

dd.AddDocInfo('title', 'Alias report')

dd.AddDocInfo('author', 'Mike Duglas')

dd.AddDocInfo('subject ', 'Alias report')

dd.PageSettings('A4', 'portrait')

!- styles

dd.AddStyle('header', '"fontSize": 18, "bold": true, "margin": [0, 0, 0, 10]')

dd.AddStyle('subheader', '"fontSize": 16, "bold": true, "margin": [0, 10, 0, 5]')

dd.AddStyle('tableExample', '"margin": [0, 5, 0, 15]')

dd.AddStyle('tableHeader', '"fontSize": 13, "bold": true, "color": "black"')

dd.AddStyle('pageFooter', '"margin": [0, 5, 0, 15]')

!-- rows

dd.AddDefaultStyle('"fontSize": 10')

 

dd.BeginContent()

!- columns:

 !Number|Name|Mailbox

 !Name column occupies all available space (width = "*")

dd.BeginTable('"style": "tableExample", "widths": ["auto", "*", "auto"]')

!- header row

dd.BeginRow()

dd.AddText('Number', '"style": "tableHeader"')

dd.AddText('Name', '"style": "tableHeader"')

dd.AddText('Mailbox', '"style": "tableHeader"')

dd.EndRow()

 

rowStyle = ''

Access:Alias.UseFile()

SET(ALI:key)

LOOP WHILE Access:Alias.Next() = Level:Benign

   dd.BeginRow()

 

  dd.AddText(ALI:Number, rowStyle)

  dd.AddText(CLIP(ALI:Name), rowStyle)

  dd.AddText(ALI:MailBoxNumber, rowStyle)

 

  dd.EndRow()

END

dd.EndTable()

 

dd.EndContent()

 

 

10. Add a code to call this PDFGenerator procedure.

a.Go to MailboxesBrowseControl procedure, in Calls dialog select PDFGenerator.
b.In GenerateTableRows routine->3 End of Generate TableRows routine embed point call PDFGenerator in separate thread, with a parameter:

 

START(PDFGenerator, , 'Mailboxes')

 

Repeat same steps for AliasBrowseControl procedure, the only difference is parameter's value:

 

START(PDFGenerator, , 'Alias')

 

 

11. Run the program and in webbrowser navigate to 127.0.0.1:88. Mailboxes or Alias item selection will generate PDF report in PdfMake folder.