Decoding PDF data from a web service

Greg Wilburn <gwilburn-kuYYJ3CQfvZxq3Q2jbZZw/[email protected]> Fri, 13 Mar 2026 16:18:56 +0000
Newsgroups gmane.comp.lang.as400.rpg
Message-ID <PH0PR17MB48631964CE6A27C10893D92FDA45A@PH0PR17MB4863.namprd17.prod.outlook.com>
I have done this quite a few times before, so I'm not sure why I'm struggling so much with this...

I'm getting a json document from a server that contains a base64 encoded string representing a packing slip... I'm able to copy the data from the webservice response file (JSON) on the IFS, and paste that into an online decoder.  That works.

But when I try to do he same in my program, I'm getting an error:
" Unable to decode character at position 1. (Char=x'4A') "

Using the online decoder, indicating UTF8, it will decode.  Using the same decoder, selecting autodetect, it decodes differently indicating windows 1252?

Just wondering if anyone can spot any glaring errors in my code.  I've been looking at it all morning.  UGH.

// definitions

  dcl-s  base64encoded  varchar(1000000) ccsid(*utf8) inz;
  dcl-s  base64decoded  char(1000000) inz;
  dcl-s  fd             int(10);

  dcl-s  pdfFile        varchar(128) inz;
  dcl-s  pdfData        varchar(1000000) ccsid(*utf8) inz;


// Decode Packslip Data
  base64Encoded = json.data.node.packingSlipPdfData;
  len = base64_decode( %addr(base64Encoded:*data)
                     : %len(%trim(base64Encoded))
                     : %addr(base64Decoded)
                     : %size(base64Decoded)
                     );
  pdfData = %subst(base64decoded:1:len);
  pdfFile = fldr + '/packslips/' + inCom + '_' + inOrd + '.pdf';

  flag = o_wronly + o_creat + o_ccsid + o_excl;
  mode = s_irusr + s_iwusr + s_iroth + s_iwoth;
  fd = open(pdfFile:flag:mode:1208:0);           // PDF is UTF8
  rc = write( fd
            : %addr(pdfData:*data)
            : %len(pdfData));

[Logo]<https://www.totalbizfulfillment.com/>    Greg Wilburn
Director of IT
301.895.3792 ext. 1231
301.895.3895 direct
gwilburn-kuYYJ3CQfvZxq3Q2jbZZw/[email protected]<mailto:gwilburn-kuYYJ3CQfvZxq3Q2jbZZw/[email protected]>
1 Corporate Dr
Grantsville, MD 21536
www.totalbizfulfillment.com<http://www.totalbizfulfillment.com>
-- 
This is the RPG programming on IBM i (RPG400-L) mailing list
To post a message email: [email protected]
To subscribe, unsubscribe, or change list options,
visit: https://lists.midrange.com/mailman/listinfo/rpg400-l
or email: RPG400-L-request-+hD5IHI5Xscn3HwCXmMcX9BPR1lH4CV8@public.gmane.org
Before posting, please take a moment to review the archives
at https://archive.midrange.com/rpg400-l.

Please contact support-FMtJrHiV//lnDLsaKlm4mFaTQe2KTcn/@public.gmane.org for any subscription related questions.