(Tcl) PDF File Encoding to Base64
Demonstrates how to encode a PDF file to base64, and then decode.
load ./chilkat.dll
set pdfData [new_CkBinData]
set success [CkBinData_LoadFile $pdfData "qa_data/helloWorld.pdf"]
if {$success != 1} then {
puts "failed to load PDF file."
delete_CkBinData $pdfData
exit
}
# Encode the PDF to base64
# Note: to produce base64 on multiple lines (as it would appear in the MIME of an email),
# pass the string "base64_mime" instead of "base64".
set b64 [CkBinData_getEncoded $pdfData "base64"]
puts "$b64"
# Decode from base64 PDF.
set pdfData2 [new_CkBinData]
CkBinData_AppendEncoded $pdfData2 $b64 "base64"
set success [CkBinData_WriteFile $pdfData2 "qa_output/helloWorld2.pdf"]
if {$success != 1} then {
puts "failed to write PDF file."
delete_CkBinData $pdfData
delete_CkBinData $pdfData2
exit
}
delete_CkBinData $pdfData
delete_CkBinData $pdfData2
|