Easy to Create, Easy to Change - Easy to use!


PDFplay in DE8.5 using MemoExecDQL and HTML.


Started by DataEase
You will need to Sign In to be able to comment on the Blog!

PDFplay in DE8.5 using MemoExecDQL and HTML.

Download Sample!
PS! You will need the latest version of DE8.5 BETA to run this sample, you will find that in our download area.

We are getting closer to De8.5 release where the focus will move from developing DE8.5 to help you benefit from all the news.

The documentation and "how to" use the new stuff is suffering so far, but here is a little play/hint on how you can use it.

The attached application will show you how you can use HTML to format your "report" and how the built in PDF feature will present it 100% as you design it with background images and all other HTML/CSS features. 

In DataEase these days we try not to re-invent the wheel, so we choose to expand and enhance existing programming languages rather than inventing new ones (like we did with OML....bad choice). 

We expand BRL/OML/DQL by adding new functions, and in DG3 we do the same with adding corresponding AJAX/JavaScript/JQuery functions that can be used directly in HTML.

With WebFields and ExecDQL we have introduced HTML, CSS and Javascript into DataEase which have "scared" some of our users.

DataEase has not forgotten easy, and our main project at the moment is "WebEasy" which is a 100% web/online Web Form Builder for PRISM8/9, and YES! It is WYSIWYG, drag and drop and "no programming".

BUT!

You can only drag and drop so much before you need to get under the bonnet to do the final adjustment. NO! Not if you are happy to run standard functionality but HTML/CSS/Ajax/JQuery/JavaScripet etc. is so powerful so if you "speak" the lingo you both understand better how things are done in our tools.

In the attached sample we haven't used the built in HTML Wysiwyg editor simply because we want you to see how you can integrate DQL Layout and HTML/CSS to achieve "brilliant" stuff ;-)

The way things are done here is basically how things are done in DG3 and how things will be done under the bonnet in "WebEasy".

The DQL


define "path" text 250 .

for SimpleAddressbook;

path := concat("file:///",StringReplace(StringReplace(GetCurrent("AppPath"),"\","/")," ","%20") ).

list records

Name in order ;

current date ;

Path ;

Address ;

Place ;

PostCode .

As you can tell, this is just a simple DQL like any other DataEase DQL and that is the point. ExecDQL is just DQL but it is 1000 times faster and 10.000 more flexible than traditional DQL (DFW DQL that is...).

You see here that we use a temp variable to list out the path to the app, We could have listed the derivation directly but then the name of the tag would have been the entire Derivation and that is a little cumbersome when you are going to work with it in the body...

We list out the path as we need to use the full path to the app in the "webpage" which is the report or the WebObject won't be able to load the image from the correct place, as the app is situation in different locations on different computers it is best to do stuff like this dynamically.

You see that we also list current date. The DQL body doesn't have "derivation" so you need to list the derivations you want to use in List Records to pick them up as LiveText in the Body. Here we don't bother to use a temp variable as the "derrivation" is simple enough and rather informativ ;-)

The Body

<html>

<style>

#mybody {

font-size:16pt;

font-family: Arial, Helvetica, sans-serif;

background-image: url("[{Path}]/invoice.png");

background-size:100%;

background-repeat:no-repeat;

width:90%;

height:90%;

padding:50px;

}

p {width:100%;}

</style>

<body>

.items

<div id="mybody">

<p style="margin-left:1000px;margin-top:84px;color:red;">[{current date}]</p>

<p style="margin-top:100px"><b>[{Name}]</b></p>

<p>[{Address}]</p>

<p>[{Place}]</p>

<p>[{PostCode}]</p>

</div>

.page

.end

</body>

</html>

We have higlighted the DataEase LiveText and DQL formatting code here. Not much ?!

And as the people that are familliar with DFD will see, it is quite familiar. We can of course make much more advanced nestings with groups, header and footters etc, but for thiis example the idea was to show simplicity and how the LiveText work seamlessly with the HTML/CSS.

Strictly speaking you don't need to format your HTML dist structured but why not start with good habits?

Our fiirst section is the STYLING. Here we style the main container (<DIV>) so we get the background image, padding, background color, font etc.

This is straight forward stuff, but see how we use a LiveText (column) from the DQL to format the background image.

background-image: url("[{Path}]/invoice.png");


YOu see how we but the HTML <body> tag on the outside of the .items / .end nesting and  the .page inside so we get one new page for each record.

Now it is simply to make your document combining simple and advanced HTML and the livetext tags to manipulate/fill it in.

The MemoExecDQL Function.

MemoExecDQL(DQL,"","","","",concat("PDF:", DQLNr,".pdf"),Body)

This is all it takes to generate a "fresh" pdf in this app. In this sample we don't use any data-entry values, but you have 4 which are named field1 through field4 when you retrieve them inside the DQL. If you need more values transfered to your DQL you can use SetVar()/GetVar() or simply pick them out of the active form with GetValue().

To create a PDF is very simple, you just use the keyword PDF: in the beginning of the output argument (number 5) and then the output file name and path after. THis name can of course be dynamically generated as in our sample.

In our sample we preview the finished PDF in the Example in a WebField. This was partly so we could adjust the position of the out ;-) and mostly so you can see the result immediately and not have to find the file in the explorer.

There is a couple of things to remember when one works with PDF and that is that you can't overwrite one when you view it, so we have to "browse" away from it, re-generate it, reload it.

This we do with this cool button action.

Scared now? ;-)

the easiest way to "program" in DataEase is to add functions together on a button or in a derivation and that is what we have done here.

SetValue("Preview",concat("file:///",StringReplace(StringReplace(GetCurrent("AppPath"),"\","/")," ","%20") ,"/Wait.html")) + 
Here we "browse" away from the PDF that was temporarily viewed in the virtual WebField so we are sure we can overwrite it. We do this by forcing the WebField (Preview) to change its content (this is new in 8, push rather than pull). We load a HTML page stored in our app catalogue to keep you entertained.

MemoExecDQL(DQL,"","","","",concat("PDF:", DQLNr,".pdf"),Body) 

Here we simply execute our little DQL and produce the new PDF. nothing much to say about this one at this point ;-) 
PS! Make sure that you don't use images etc that is remote, download them and load them local. The thing that take time when producing the PDF is to download images etc from remote sites, if everything is local it will produce the PDF in much less than a second...

wait(1) 

which is the delay we give it to produce the PDF and store it on the drive. Increase this one if the production takes more than a second, as you will load the old one if you are too quick.

SetValue("Preview",concat("file:///",StringReplace(StringReplace(GetCurrent("AppPath"),"\","/")," ","%20") ,"/",DQLNr,".pdf"))
Now we have produced the new/updated PDF so we force the Preview Memo to load it by changing its value to point at the PDF. FULL PATH!

That was it. 

Now use your imagination!

Written by DataEase 07/07/15 at 11:49:54 Dataease [{8}]FIVE
/static/images/blank.png

Re:PDFplay in DE8.5 using MemoExecDQL and HTML.

WOW!

This is very good. My next project will be in 8.5......no question about it.

BTW: since you are building "SR-71 Blackbird"....I thought no harm in asking :-)

Written by Jeyarajah Arulrajah 07/07/15 at 14:36:56 Dataease [{8}]FIVE
/static/images/blank.png

Re:Re:PDFplay in DE8.5 using MemoExecDQL and HTML.

He,he! 

Never harm in asking. It is your best "skill" that you are never afraid of asking the question. If one don't ask one won't get an answer.

Written by DataEase 07/07/15 at 15:41:00 Dataease [{8}]FIVE
/static/images/blank.png