Dienstag, 30. August 2016

info function sample and more system information

REM /**
REM  * infoFunction.bbj
REM  * @author VANDEN
REM  */
tc! = bbjapi().getThinClient()
tc!=BBjAPI().getThinClient()
        txt$=txt$+tc!.toString()
        txt$=txt$+""+
:       "+++BBx Betriebssystem (0,0):           "+info(0,0)+
:       "+++BBx Betriebssystem Version (0,1):   "+info(0,1)+
:       "+++Server Basis Port ID (0,2):         "+info(0,2)+
:       "+++Client Basis Port ID ( tc!.getClientPortID() ): "+tc!.getClientPortID()+
:       "+++CPU ID (1,0):                       "+info(1,0)+
:       "+++server JVM unque ID (1,5) :         "+hta(info(1,5))+
:       "+++client JVM unque ID (1,6) :         "+hta(info(1,6))+
:       "+++Current User Slot Number (2,4):     "+str(dec(info(2,4)))+
:       "+++license Version (2,7):              "+str(dec(info(2,7)))+
:       "+++unique Task ID 4byte (3,0):         "+str(dec(info(3,0)))+
:       "+++unique Task ID 8byte (3,1):         "+str(dec(info(3,1)))+
:       "+++Username (3,2):                     "+info(3,2)+
:       "+++Login Beschreibung (3,3):           "+info(3,3)+
:       "+++Hostname (3,4):                     "+info(3,4)+""+
:       "+++Aktivierungsschlüssel (3,5):        "+info(3,5)+
:       "+++GUI System (6,0):                   "+info(6,0)
        x=msgbox( cast(BBjString,txt$).replace("+++",$0d0a$) )
     
for i=0 to 99999
    if (i>0 and mod(i,20)=0) input "press enter to continue",a$
    ?"INFO(7,"+str(i)+") = "+info(7,i,err=*break)
next i
   
end

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Regular Expression in BBj / Java

replace line breaks with html line breaks :

declare BBjString test!
test!="HELLO\r\nWORLD\n\rAGAIN"
foo$=test!.replaceAll("\\r\\n|\\n|\\r|"+$0d0a$+"|"+$0d$+"|"+$0a$","<br>")
?foo$

test$="HELLO\r\nWORLD\n\rAGAIN"
test$=cast(BBjString,test$).replaceAll("\\r\\n|\\n|\\r|"+$0d0a$+"|"+$0d$+"|"+$0a$","<br>")
?test$

replace multiple chars by char :

src! = "ABC___(hellop)_myQuotesAreHere"+$2222$+"12345_ /&%"
ListOfDislikedChars$ ="[\/^\*\$\(\)\&\=\?\'\*\+\-\.\:\,\;\""\%]"; REM [^/....]*/$
firstMatchAtPos=mask(src!,ListOfDislikedChars$) ; ?"pattern matched first at position "+str(firstMatchAtPos)
?src!
des! = src!.replaceAll(ListOfDislikedChars$,java.util.regex.Matcher.quoteReplacement("X"))
?des!

remove path from filename : x! = programName!.replaceAll(".*(\\|/)","")
remove extension from filename : x! = programName!.replaceAll("\.\w+$","")
keep path only from filename : x! = programName!.replaceAll("(\\|/).*","")

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

Sonntag, 28. August 2016

append one PDF to another PDF

Based on the library http://itextpdf.com/.
Usecase: Add for instance common terms of condition to an invoice.

REM /**
REM  * pdf_append.bbj
REM  * @author VANDEN
REM  *
REM  */

use java.util.ArrayList
use java.io.FileOutputStream
use com.itextpdf.text.Document
use com.itextpdf.text.DocumentException
use com.itextpdf.text.pdf.PdfCopy
use com.itextpdf.text.pdf.PdfReader

declare Document document!
declare PdfCopy copy!
declare ArrayList files!
declare PdfReader reader!

outputFile$ = "c:/0/pdf3.pdf"
inputFile1$ = "c:/0/pdf1.pdf"
inputFile2$ = "c:/0/pdf2.pdf"

document! = new Document()
copy! = new PdfCopy(document!, new FileOutputStream(outputFile$))
document!.open()
files! = new ArrayList()
files!.add(inputFile1$)
files!.add(inputFile2$)
For i = 0 to files!.size() - 1
    reader! = new PdfReader(Str(files!.get(i)))
    n = reader!.getNumberOfPages()
    For page = 1 to n
        copy!.addPage(copy!.getImportedPage(reader!, page))
    Next page
    copy!.freeReader(reader!)
    reader!.close()
Next i
document!.close()

end

Benefit from the best Windows Desktop app in the world and use Strokey.Net!

merge/overlay 2x PDF and get mixed PDF

Based on the library http://itextpdf.com/.
Usecase: Merge a pdf-invoice with a pdf-background file. The pdf-invoice does not include a company header and footer, so you want to merge it with a pdf-background template including specific information.

REM /**
REM  * pdf_tpl_merge.bbj
REM  * @author VANDEN
REM  *
REM  */

use java.io.FileOutputStream
use com.itextpdf.text.Document
use com.itextpdf.text.pdf.PdfReader
use com.itextpdf.text.pdf.PdfWriter
use com.itextpdf.text.pdf.PdfContentByte
use com.itextpdf.text.pdf.PdfImportedPage

declare Document destDoc!
declare PdfWriter destWriter!
declare PdfReader mainDocReader!
declare PdfReader singlePageBackgroundReader!
declare PdfImportedPage mainDocPage!
declare PdfImportedPage backgroundPage!
declare PdfContentByte dcb!
declare PdfContentByte ucb!

tplFile$ = "c:/0/background.pdf"
srcFile$ = "c:/0/source1.pdf"
destFile$ = "c:/0/dest"+str(tim)+".pdf"

destDoc! = new Document()
destWriter! = PdfWriter.getInstance(destDoc!, new FileOutputStream(destFile$))
destDoc!.open()
dcb! = destWriter!.getDirectContent()
ucb! = destWriter!.getDirectContentUnder()
mainDocReader! = new PdfReader(srcFile$)
singlePageBackgroundReader! = new PdfReader(tplFile$)
backgroundPage! = destWriter!.getImportedPage(singlePageBackgroundReader!,1)
for i=1 to mainDocReader!.getNumberOfPages()
    destDoc!.newPage()
    mainDocPage! = destWriter!.getImportedPage(mainDocReader!,i)
    dcb!.addTemplate(mainDocPage!,0,0)
    ucb!.addTemplate(backgroundPage!,0,0)
next i
destDoc!.close()

end

Benefit from the best Windows Desktop app in the world and use Strokey.Net!