LANSA Integrator - PDFDocumentService - QR Code

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
Joerg Hamacher
Posts: 95
Joined: Thu Feb 11, 2016 12:01 am

LANSA Integrator - PDFDocumentService - QR Code

Post by Joerg Hamacher » Fri Jul 22, 2022 10:28 pm

Hello to all,

does anyone have experience with generating QR codes using the LANSA Integrator PDFDocumentService?
In my opinion, this service is flawed, because the positioning of the QR code is not based on the x1 / y1 parameters in the XML definiitonb, but arbitrarily based on the length of the text contained there. Also the size assignment in the XML file is completely ignored.
Does anyone know of a workaround?

My current programming requirement is to output a QR code with a length and width of 46 millimeters at a specific location in a document. The start position is ignored completely, length and width do not fit either.

This is the definition in the XML:
<barcode x1="174" y1="265" width="130" height="130" align="top, left" border="false" margin-left="0" margin-top="0" type="QRCODE" value="{W_QRTEXT}"/>

W_QRTEXT is defined as NVarChar.

I tried with a short text '1234567890123'
and a long text (#w_QRText := "QRType Version Coding Type Konto (IBAN ZE) Adresstyp (ZE) Name (ZE) Strasse oder Adresszeile 1 (ZE) Hausnr. oder Adresszeile 2 (ZE) PLZ (ZE) Ort (ZE) Land (ZE) Adresstyp (EZE) Name (EZE) Strasse oder Adresszeile 1 (EZE) Hausnr. oder Adresszeile 2 (EZE) PLZ (EZE) Ort (EZE) Land (EZE) Betrag Währung Adresstyp (EZP) Name (EZP) Strasse oder Adresszeile 1 (EZP) Hausnr. oder Adresszeile 2 (EZP) PLZ (EZP) Ort (EZP) Land (EZP) Referenztyp Referenz Unstrukturierte Mitteilungen Trailer Rechnungsinformationen AV1 – Parameter AV2 – Parameter")

On the application side it is very realistic that the length of the value changes again and again, because the field is filled depending on various variables. However, the QR code must necessarily always be in the same position and always have the same fixed size.

I have attached the PDF files with the result. None of the codes has 46 millimeters - conversion according to LANSA documentation: 4,6 cm / 2,54 * 72 = 130.39 (width/ height)

It also makes no difference whether the QR code is printed alone or embedded in text.

Does anyone see where my error lies?
Has anyone of you had something like this and what was the solution to the problem?

Many greetings,
Jörg
Attachments
SwissQR_Test_ShortText.pdf
(5.8 KiB) Downloaded 405 times
SwissQR_Test_LongText.pdf
(7.85 KiB) Downloaded 401 times

User avatar
Dino
Posts: 298
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Dino » Thu Jul 28, 2022 11:26 pm

Hi

Did a quick test using this xml:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<document page-size="A4">

<content name="ONEPAGE">
   <!--- about 13 characters -->
   <barcode x1="20" y1="620" type="QRCODE" width="200" height="200" align="left"
   value="1234567890123"/> 
   <!--- about 200 characters -->
   <barcode x1="240" y1="620" type="QRCODE" width="200" height="200" align="left"
   value="1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- "/>
   <!--- about 400 characters -->
   <barcode x1="20" y1="400" type="QRCODE" width="200" height="200" align="left"
   value="1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- "/>
   <!--- about 500 characters -->
   <barcode x1="240" y1="400" type="QRCODE" width="200" height="200" align="left"
   value="QRType Version Coding Type Konto (IBAN ZE) Adresstyp (ZE) Name (ZE) Strasse oder Adresszeile 1 (ZE) Hausnr. oder Adresszeile 2 (ZE) PLZ (ZE) Ort (ZE) Land (ZE) Adresstyp (EZE) Name (EZE) Strasse oder Adresszeile 1 (EZE) Hausnr. oder Adresszeile 2 (EZE) PLZ (EZE) Ort (EZE) Land (EZE) Betrag Währung Adresstyp (EZP) Name (EZP) Strasse oder Adresszeile 1 (EZP) Hausnr. oder Adresszeile 2 (EZP) PLZ (EZP) Ort (EZP) Land (EZP) Referenztyp Referenz Unstrukturierte Mitteilungen Trailer Rechnungsinformationen AV1 – Parameter AV2 – Parameter"/>
   
   <line x1="20" y1="100" x2="20" y2="800" stroke-color="blue"/>
   <line x1="220" y1="100" x2="220" y2="800" stroke-color="blue"/>
   <line x1="240" y1="100" x2="240" y2="800" stroke-color="blue"/>
   <line x1="440" y1="100" x2="440" y2="800" stroke-color="blue"/>

   <line x1="20" y1="200" x2="550" y2="200" stroke-color="red"/>
   <line x1="20" y1="400" x2="550" y2="400" stroke-color="red"/>
   <line x1="20" y1="420" x2="550" y2="420" stroke-color="red"/>
   <line x1="20" y1="620" x2="550" y2="620" stroke-color="red"/>

   <line x1="20" y1="620" x2="220" y2="420" stroke-color="green"/>
   <line x1="240" y1="620" x2="440" y2="420" stroke-color="pink"/>
   <line x1="20" y1="400" x2="220" y2="200" stroke-color="green"/>
   <line x1="240" y1="400" x2="440" y2="200" stroke-color="pink"/>

</content>

</document>
to generate a pdf like the one here (attached)
qrcode728.png
qrcode728.png (96.43 KiB) Viewed 9186 times
and I can see that while the qrcode still fits in the space assigned for it, the size of it grows to accommodate a larger value (500+ characters).
I think that is likely needed to fit all that information... by the way, at 200 size, the qrcode with over 500 characters get hard to be recognized by my phone.

if I change it to width 130 instead of 200:

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<document page-size="A4">

<content name="ONEPAGE">
   <!--- about 13 characters -->
   <barcode x1="20" y1="550" type="QRCODE" width="130" height="130" align="left"
   value="1234567890123"/> 
   <!--- about 200 characters -->
   <barcode x1="150" y1="550" type="QRCODE" width="130" height="130" align="left"
   value="1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- "/>
   <!--- about 400 characters -->
   <barcode x1="20" y1="270" type="QRCODE" width="130" height="130" align="left"
   value="1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- 1---5---- "/>
   <!--- about 500 characters -->
   <barcode x1="150" y1="270" type="QRCODE" width="130" height="130" align="left"
   value="QRType Version Coding Type Konto (IBAN ZE) Adresstyp (ZE) Name (ZE) Strasse oder Adresszeile 1 (ZE) Hausnr. oder Adresszeile 2 (ZE) PLZ (ZE) Ort (ZE) Land (ZE) Adresstyp (EZE) Name (EZE) Strasse oder Adresszeile 1 (EZE) Hausnr. oder Adresszeile 2 (EZE) PLZ (EZE) Ort (EZE) Land (EZE) Betrag Währung Adresstyp (EZP) Name (EZP) Strasse oder Adresszeile 1 (EZP) Hausnr. oder Adresszeile 2 (EZP) PLZ (EZP) Ort (EZP) Land (EZP) Referenztyp Referenz Unstrukturierte Mitteilungen Trailer Rechnungsinformationen AV1 – Parameter AV2 – Parameter"/>
   
   <line x1="20" y1="100" x2="20" y2="800" stroke-color="blue"/>
   <line x1="150" y1="100" x2="150" y2="800" stroke-color="blue"/>
   <line x1="150" y1="100" x2="150" y2="800" stroke-color="blue"/>
   <line x1="280" y1="100" x2="280" y2="800" stroke-color="blue"/>

   <line x1="20" y1="130" x2="550" y2="130" stroke-color="red"/>
   <line x1="20" y1="270" x2="550" y2="270" stroke-color="red"/>
   <line x1="20" y1="420" x2="550" y2="420" stroke-color="red"/>
   <line x1="20" y1="550" x2="550" y2="550" stroke-color="red"/>

   <line x1="20" y1="550" x2="150" y2="420" stroke-color="green"/>
   <line x1="150" y1="550" x2="280" y2="420" stroke-color="pink"/>
   <line x1="20" y1="270" x2="150" y2="130" stroke-color="green"/>
   <line x1="150" y1="270" x2="280" y2="130" stroke-color="pink"/>

</content>

</document>
qrcode728b.png
qrcode728b.png (68.45 KiB) Viewed 9183 times
the last 2 qrcodes (over 400 characters) get hard to read by my phone. at least, trying to capture them from the screen.
Attachments
test0223092242.pdf
(16.89 KiB) Downloaded 401 times

Joerg Hamacher
Posts: 95
Joined: Thu Feb 11, 2016 12:01 am

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Joerg Hamacher » Fri Jul 29, 2022 11:44 pm

Hi Dino,

thank you for testing!

The problem is that the Swiss government has issued a style guide that defines exactly how large the QR code should be and at what position in the payment slip it must be placed. Deviations from this are not permitted.

The long text "QRType Version Coding Type Konto (IBAN ZE) Adresstyp (ZE) Name (ZE) Strasse oder Adresszeile 1 (ZE) Hausnr. oder Adresszeile 2 (ZE) PLZ (ZE) Ort (ZE) Land (ZE) Adresstyp (EZE) Name (EZE) Strasse oder Adresszeile 1 (EZE) Hausnr. oder Adresszeile 2 (EZE) PLZ (EZE) Ort (EZE) Land (EZE) Betrag Währung Adresstyp (EZP) Name (EZP) Strasse oder Adresszeile 1 (EZP) Hausnr. oder Adresszeile 2 (EZP) PLZ (EZP) Ort (EZP) Land (EZP) Referenztyp Referenz Unstrukturierte Mitteilungen Trailer Rechnungsinformationen AV1 – Parameter AV2 – Parameter" is the sample text used by the QR codes in the style guide.

We have already forwarded this to the LPC, but we are under a lot of time pressure, because the whole thing will be legally binding in Switzerland by October 1st at the latest.

Have a nice weekend,
Jörg

User avatar
Dino
Posts: 298
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Dino » Fri Jul 29, 2022 11:52 pm

I hope it can be fixed quickly and in the way you need it.

Remember that other popular options today, as QRcode can be wildly enhanced today with colors, logos, etc., is to call an API and receive an image with the QRcode.
Then you can then use that image in your pdf document instead of generating a QRcode.
qrcode728c.png
qrcode728c.png (208.26 KiB) Viewed 9163 times

Joerg Hamacher
Posts: 95
Joined: Thu Feb 11, 2016 12:01 am

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Joerg Hamacher » Sat Jul 30, 2022 12:57 am

Hi Dino,

that's a great idea, I hadn't actually thought of that at all. Are there any APIs that you can recommend?

Best regards,
Jörg

User avatar
Dino
Posts: 298
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Dino » Sat Jul 30, 2022 1:49 am

nothing I can recommend as I have not used them in a real situation, but sites like this:
https://www.programmableweb.com/category/qr-codes/api

shows several apis available... for example this page:
https://www.qrcoder.co.uk/api/v3/docs/

(bonus! they already show an api key there)

so an example to get a qrcode will be a call to an URL like this that returns a PNG file with a QRCODE:

https://www.qrcoder.co.uk/api/v3/?key=F ... &padding=4

which in LANSA means:

Code: Select all

Define_Com Class(#XPRIM_HttpRequest) Name(#Request) Scope(*Application)

#VF_ELTXTX := 'https://www.qrcoder.co.uk/api/v3/?key=FaVGbVHLhDRUw27MQn4BjmEsD2wZyDD2&text=Hello+World&type=png&background=FFFFFF&foreground=880000&eo=F10000&ei=AA0000&size=4&padding=4'
#Request.DoPost Url(#VF_ELTXTX)
* The response is an image file, lets move it to a file
#STD_BLOB := #Request.Response.AsFile
#STD_STRNG := #STD_BLOB.FileName
then in my previous example of XML I added:

Code: Select all

   <text value="{STD_STRNG}" x1="10" y1="700" width="500" height="100" align="left" />
   <image file="{STD_STRNG}" x1="20" y1="800"  border="false"/>
the actual (complete) code of my test form is:

Code: Select all

Function Options(*Direct)
Begin_Com Role(*EXTENDS #PRIM_FORM) ClientWidth(484) ClientHeight(301) ComponentVersion(2) Left(833) Top(198)
Define_Com Class(#XPRIM_HttpRequest) Name(#Request) Scope(*Application)

Define_Com Class(#PRIM_STBR) Name(#StatusBar1) DisplayPosition(1) Height(24) Left(0) MessagePosition(1) Parent(#COM_OWNER) TabPosition(1) TabStop(False) Top(277) Width(484)
Define_Com Class(#PRIM_PHBN) Name(#Button1) Caption('Button1') DisplayPosition(2) Left(54) Parent(#COM_OWNER) TabPosition(2) Top(37)

Evtroutine Handling(#com_owner.CreateInstance)
Set Com(#com_owner) Caption(*component_desc)
Endroutine

Subroutine Name(ARMAPDF)
Def_List Name(#Data) Fields(#STD_STRNG) Type(*Working)

#VF_ELTXTX := 'https://www.qrcoder.co.uk/api/v3/?key=FaVGbVHLhDRUw27MQn4BjmEsD2wZyDD2&text=Hello+World&type=png&background=FFFFFF&foreground=880000&eo=F10000&ei=AA0000&size=4&padding=4'
#Request.DoPost Url(#VF_ELTXTX)
* The response is an image file, lets move it to a file
#STD_BLOB := #Request.Response.AsFile
#STD_STRNG := #STD_BLOB.FileName

Inz_List Named(#Data)

Use Builtin(JSMX_OPEN) To_Get(#JSMXSTS #JSMXMSG #jsmxhdle1)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

* Load Service
#jsmxcmd := 'SERVICE_LOAD SERVICE(PDFDOCUMENTSERVICE)'
Use Builtin(JSMX_COMMAND) With_Args(#jsmxhdle1 #jsmxcmd) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

#jsmxcmd := 'CREATE DOCUMENT(c:\temp\test0223' + #timex.Now.AsDisplayString( HHMMSS ) + '.pdf) CONTENT(xml/test0223.xml)'
Use Builtin(JSMX_COMMAND) With_Args(#jsmxhdle1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

#jsmxcmd := 'ADD CONTENT(ONEPAGE)'
Use Builtin(JSMx_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD #Data) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

* Close document
#jsmxcmd := "CLOSE"
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

* Unload PDF Service
#jsmxcmd := "SERVICE_UNLOAD"
Use Builtin(JSMX_COMMAND) With_Args(#JSMXHDLE1 #JSMXCMD) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)

* Close the JSM
Use Builtin(JSMX_CLOSE) With_Args(#jsmxhdle1) To_Get(#JSMXSTS #JSMXMSG)
Execute Subroutine(CHECK_STS) With_Parms(#JSMXHDLE1)
Endroutine

*  Check the status of the JSM command issued
Subroutine Name(CHECK_STS) Parms(#W_HDLE)
* Define Field(#MSGDTA) Type(*CHAR) Length(132)
Define Field(#W_HDLE) Type(*Char) Length(4)
If Cond('#JSMXSTS *NE OK')
#MSGDTA := 'Error Status Code: ' + #JSMXSTS
Message Msgid(DCM9899) Msgf(DC@M01) Msgdta(#MSGDTA)
#MSGDTA := 'Error Message: ' + #JSMXMSG
Message Msgid(DCM9899) Msgf(DC@M01) Msgdta(#MSGDTA)
Endif
Endroutine

Evtroutine Handling(#Button1.Click)
Execute Subroutine(ARMAPDF)
Endroutine
End_Com
and I got this (at the first try! woohoo):
pdf729.png
pdf729.png (36.54 KiB) Viewed 9158 times

Joerg Hamacher
Posts: 95
Joined: Thu Feb 11, 2016 12:01 am

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Joerg Hamacher » Thu Aug 04, 2022 5:41 pm

Hi Dino,

thank you very much once again. It looks so easy when someone knows what to do :D

I heard that LPC is looking into the problem, too. Hope they will find a solution soon.
Otherwise I now have a good workaround!

Kind regards,
Jörg

Joerg Hamacher
Posts: 95
Joined: Thu Feb 11, 2016 12:01 am

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Joerg Hamacher » Thu Aug 25, 2022 12:35 am

Hi Dino,

here I am again.

I get your example working fine when having everything in Windows environment.

But I have to embed this into a IBMi ERP-system rountine and call it via RPG.
I made a RDMLX function for this that I can call succesfully - but calling the QRcode Web API is not succesfully or better: seems not to be executed at all.
Only message I found was in /LANSA_l15pgmlib/tmp/log.txt saying "Runtime error: Request has not executed or failed to execute".
My logging only produced a request.general.log containing the correct URL (if I copy this and use it in a browser the correct QR code is shown) and an empty request.headers.log. No response...log files.

What do I have to do to get this running completely on IBMi?

Kind regards,
Joerg

User avatar
Dino
Posts: 298
Joined: Fri Jul 19, 2019 7:49 am
Location: Robbinsville, NC
Contact:

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Dino » Thu Aug 25, 2022 11:56 pm

Hi

It would seem that your IBM don't have access to the exterior like mine...
a simple test like this can give you the answer and the need to talk with your network administrator:

Code: Select all

Function Options(*DIRECT)
Define_Com Class(#XPRIM_HttpRequest) Name(#Request) Scope(*Application)
#Request.DoPost Url('https://www.google.com')
If (#Request.Response.IsSuccessfulRequest)
Message Msgtxt(allgood)
Else
Message Msgtxt(notgood)
Endif

Joerg Hamacher
Posts: 95
Joined: Thu Feb 11, 2016 12:01 am

Re: LANSA Integrator - PDFDocumentService - QR Code

Post by Joerg Hamacher » Fri Aug 26, 2022 1:29 am

Hi Dino,

function says "allgood".
Maybe it has something to do with HTTP headers or other config settings?

Kind regards,
Joerg

Post Reply