I am using the MID Server to generate a PDF using the itext API. I am building the PDF in memory using a ByteArrayOutputStream and then using the StringUtil.base64Encode(baos) to encode it to base64 so I can attach it to a ServiceNow record via the AttachmentCreator.
For sanity sake, I wrote the baos to an actual PDF file and used an online encoder to encode the PDF to base64, and it created a valid string I was able to use in the AttachmentCreator and generate the PDF I was expecting.