infor.com
concierge
infor u
developer portal
documentation central
customer center
Posts
Categories
Groups
ERPs
CSD
FSM/HRT
LN
M3
Syteline/ CSI
Hubs
Developer
Healthcare
Hospitality
Public Sector
Onboarding
Release Center
CloudSuites
Aerospace & Defense (LN)
Automotive (LN)
Chemicals (M3)
Corporate (FSM/HRT)
Distribution (Sx.e/CSD)
Distribution Enterprise (M3)
Engineering & Construction (LN)
Fashion (M3)
Food & Beverage (M3)
Healthcare (FSM/HRT)
Industrial (Syteline/CSI)
Industrial Enterprise (LN)
Manufacturing (M3)
Public Sector (FSM/HRT)
Solutions
Supply Chain Management (SCM)
Human Capital Management (HCM)
Events
Groups
User Groups
Your Groups
About
Email Community Support
Infor News
Migrated Forums
Home
Clovertech
Clovertech Archive
Read Only Archives
Cloverleaf
General
decode the base 64 pdf file
System
Originally posted by Wilson Wat
Does anyone have any experiences to decode base 64 pdf file in the window environment? My goal is to decode the pdf file and write it to a designated folder across the network and build a link to it...Thx
Find more posts tagged with
Clovertech
Comments
Charlie Bursell
Wilso:
I think I araedy mentioned this but you can decode it with the Tcl decode command. It should be a simple matter to build a script that accepts the base-64 data, decodes it and writes it to a .*pdf file.
Make sure your file reads and writes are done in binary mode
James Mestack
Something appears to be lost in the decode process from base-64 to pdf, can someone determine if I am doing this correctly?
Win 2003 Server SP2
CL 5.7 R2
See attachment for inbound message in .msg file.
See attachments for what pdf should look like and what it does look like?
proc code:
package require base64
foreach segment $segments {
if {[cequal [crange $segment 0 2] "OBX"]} {
set obx_fields [split $segment $field_delim]
set list_size [llength $obx_fields]
while { $list_size < 6 } {
lappend obx_fields ""
set list_size [llength $obx_fields]
}
set obx_5_fields [split [lindex $obx_fields 5] $comp_delim]
set list_size [llength $obx_5_fields]
while { $list_size < 5 } {
lappend obx_5_fields ""
set list_size [llength $obx_5_fields]
}
set pdf_data [base64::decode [lindex $obx_5_fields 4]]
break
}
}
set PDFFileName [cconcat $HciProcessesDir "/" $myprocessName "/que_pdf_data/CentralLogic_Test.pdf"]
if { [catch {set outfile [open $PDFFileName w]} cerr] } {
puts [cconcat "--> WARNING: Error Creating " $PDFFileName " File - " $cerr "r"]
} else {
puts $outfile $pdf_data
close $outfile
}
Jim Kosloskey
James,
First are you positive the inbound message has that fiel base-64 encoded?
If this is done following the HL/7 standard OBX-2 should have the proper data type (I think that is ED) and then OBX-5 should have the proper structure which includes a component that tells you the encoding technique deployed.
But even if the standard is not literally followed (not surprising), you need to make sure the data is actually base-64 encoded. Otherwise it most certainly could contain one or moer of the characters specified in MSH-1 and MSH-2 causing your parsing to fail and possibly not giving you all of the data you want.
The Base64 package will attempt to decode whatever you give it even if it is not Base64 encoded.
James Mestack
I included the smat files with the test records received from vendor, you'll have to take off the ".txt" extension to utilize as I had to rename so I could upload.
The vendor states it is base-64 from pdf.
Charlie Bursell
I have a hard time with the code but if you are writing it to a file and it is indeed a PDF document you have to change translation type to binary
set PDFFileName [cconcat $HciProcessesDir "/" $myprocessName "/que_pdf_data/CentralLogic_Test.pdf"]
Better stated as [file join $HciProcessesDir
que_pdf_data CentralLogic_Test.pdf]
# w+ will reate file if it does not exist
if { [catch {open $PDFFileName w+} outfile]} {
echo --> WARNING: Error Creating $PDFFileNamenFile - $outfilen
---- May need an error return here
} else {
fconfigure $outfile -translation binary
puts $outfile $pdf_data
close $outfile
}
The looping to get segment data is not very ergonomic. Take a look at the lsearch command
James Mestack
Right on! I added the "w+" and "fconfigure" and now receive readable output. Also, thank you for the code tidbits.
Being my first time doing this, on the PDF view, I see there is an "X" in the top box, supposedly our logo. Is that not supposed to be embedded or do we need a seperate file? Probably need to discuss with vendor?
See attached new output...
Christopher Wells
Charlie,
I know this is an old post, but the file writing snippet really helped me out. Just starting to work with decoded PDF files myself.
Thanks,