« MBS Plugin Advent cal… | Home | Xojo Web signal handl… »

MBS Plugin Advent calendar: 18 - Preview

Door 18 - Preview

Fact of the day
Did you know that you can also embed an XML file in PDF documents? This is also done with the ZUGFeRD format, for example. With the help of DynaPDF and the plugin, you can create and read such files yourself

Did you know that MBS offers a PDF preview for Windows and Mac, with which you can view the document and even copy content with the mouse?

We have included this control in our plugins since version 13.3 of this year. You can use this function on Windows 10 and MacOS. You can easily test whether your system fulfills the requirements with the Preview.Available function.

If [ MBS( "Preview.Available" ) ] 

If this fits, you can create the preview control. We have two options for this. First, we can create a PDF control with a fixed size and a specific position. To do this, we use the Preview.Create function. We first enter the window reference in the parameters. If it is the window that is furthest forward, enter a 0 or find out the reference with Window.FindByTitle or Window.FindByIndex. Then comes the position, which we specify with x and y for the top left corner. Finally, enter the width and height of the control.

Set Variable [ $$Preview ; Value: MBS( "Preview.Create"; 0; 177; 64 ; 320; 420 ) ] 

The other option is to position the preview with a control. To do this, we use the Preview.CreateWithControl function. For example, a rectangle that has been positioned on the layout can be used as such a control. In the parameters, we again specify the window reference and also the name of the placeholder. In this case it is now Placeholder. If required, we can now specify an offset. In other words, values that move the preview from the placeholder object by a certain value, but we are don't use this here.

Set Variable [ $$Preview ; Value: MBS( "Preview.CreateWithControl"; 0; "Placeholder"  ) ] 

Before we can see the PDF, we must first load it. Again, we have two options. It can be from a container, in which case we use the "Preview.LoadContainer" function.

Set Variable [ $r ; Value: MBS( "Preview.LoadContainer"; $$Preview; DoorEightTeen::Container ) ]

The other option is to load the PDF file from a file that is stored in a path. Then we use the "Preview.LoadFile" function.

Set Variable [ $r ; Value: MBS( "Preview.LoadFile"; $$Preview; DoorEightTeen::File ) ]

The PDF file should now be displayed and we can view the pages and select and copy content using the mouse menu.

If you want to remove the file from the PDF view again, but the preview may be needed again. The function Preview.Unload unloads the current PDF document.

If you no longer need the preview, release the preview again. You can use Preview.Release to release a single preview by specifying the preview reference, or you can use Preview.ReleaseAll to release all currently existing previews at the same time.

I hope the new preview can help you in your work with PDF documents.


Monkeybread Software Logo with Monkey with Santa hat
17 👈 18 of 24 👉 19
18 12 23 - 07:02