« MBS Xojo Plugins, ver… | Home | Xojo reports with bac… »

Swiss QR-Codes for invoices as vector graphics

As you may know the MBS FileMaker Plugin can create Swiss QR-Codes for invoices (ISO 20022) with our Barcode functions. We have an older example which generates QR Codes for Invoices in Switzerland as picture and place them in a container field to print them. But there is another way by doing vector graphics like the new example here to put the barcode on top of an existing PDF:



You like to know how we did it?
Here is the script:

# Clear current PDF document
Set Variable [ $pdf ; Value: MBS("DynaPDF.New") ]
#
If [ not IsEmpty ( Swiss QRCode::Input ) ]
# Load PDF from container
Set Variable [ $r ; Value: MBS("DynaPDF.OpenPDFFromContainer"; $pdf; Swiss QRCode::Input) ]
# import a page
Set Variable [ $r ; Value: MBS("DynaPDF.ImportPDFPage"; $pdf; 1) ]
End If
#
# Edit first page
Set Variable [ $r ; Value: MBS("DynaPDF.EditPage"; $pdf; 1) ]
Set Variable [ $r ; Value: MBS("DynaPDF.SetPageCoords"; $pdf; "topdown") ]
#
# black
Set Variable [ $r ; Value: MBS("DynaPDF.SetFillColor"; $pdf; 0; 0; 0) ]
#
# Where and what size? Make sure for PDF paper size the final printed size is right.
Set Variable [ $x ; Value: 400 ]
Set Variable [ $y ; Value: 600 ]
Set Variable [ $w ; Value: 130 ]
Set Variable [ $h ; Value: 130 ]
Set Variable [ $cw ; Value: $w/6,5 // should be 7mm on print ]
#
# draw barcode
Set Variable [ $text ; Value: Swiss QRCode::QRCode Content ]
Set Variable [ $text ; Value: MBS( "Text.ReplaceNewline"; $text; 3 ) ]
Set Variable [ $o ; Value: MBS("Barcode.SetOptions"; 4) // ECC Level with values from 1 = low, 2 = middle, 3 = better, 4 high. ]
Set Variable [ $r ; Value: MBS("Barcode.DrawBarcode"; $pdf; "QRCode"; $text; $x; $y; $w; $h; "UTF-8") ]
#
# draw a white rectangle
Set Variable [ $r ; Value: MBS("DynaPDF.SetFillColor"; $pdf; 1; 1; 1) ]
Set Variable [ $px ; Value: $x + ($w-$cw)/2 ]
Set Variable [ $py ; Value: $y + ($h-$cw)/2 ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px; $py; $cw; $cw; "fill") ]
#
# draw black cross
Set Variable [ $p ; Value: $cw/15 ]
Set Variable [ $r ; Value: MBS("DynaPDF.SetFillColor"; $pdf; 0; 0; 0) ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p; $py + $p; $p * 13; $p*2; "fill") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p * 12; $py + $p; $p * 2; $p * 13; "fill") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p; $py + $p; $p * 2; $p * 13; "fill") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p; $py + $p * 12; $p * 13; $p * 2; "fill") ]
#
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p; $py + $p; $p * 5; $p * 5; "fill") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p * 9; $py + $p; $p * 5; $p * 5; "fill") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p; $py + $p * 9; $p * 5; $p * 5; "fill") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Rectangle"; $pdf; $px + $p * 9; $py + $p * 9; $p * 5; $p * 5; "fill") ]
#
Set Variable [ $r ; Value: MBS("DynaPDF.EndPage"; $pdf) ]
#
# Render one page as Picture
Set Variable [ $PDFData ; Value: MBS("DynaPDF.Save"; $pdf; "hello.pdf") ]
Set Variable [ $r ; Value: MBS("DynaPDF.Release"; $pdf) ]
# Put in Container
Set Field [ Swiss QRCode::PDF ; $PDFData ]

Please do not hesitate to contact us with your questions. The example will be included in next prerelease.
12 06 20 - 16:36