If you don't want to use the xmlrpclib's Binary class, you can just use the .encode() method of strings:

a = open("pdf_reference.pdf", "rb").read().encode("base64")
Answer from Tony Meyer on Stack Overflow
๐ŸŒ
Wondershare
pdf.wondershare.com โ€บ convert-pdf โ€บ convert-pdf-to-base64.html
The Complete Guide To Convert PDF to Base64
Step 1 Go to the Aspose website and select "Upload or Drop your files." Step 2 Navigate to the "Save as" tab and select Base64 as the output format. Step 3 Click the green "Convert" button to initiate the process.
Published: December 28, 2022
๐ŸŒ
Base64.Guru
base64.guru โ€บ home โ€บ base64 converter โ€บ base64 encode
PDF to Base64 | Base64 Encode | Base64 Converter | Base64
Convert PDF to Base64 online and use the result string as data URI, HTML object, and others. Sometimes you have to send or output a PDF file within a text document (for example, HTML, JSON, XML), but you cannot do this because binary characters will damage the syntax of the text document.
Discussions

encoding - How to base64 encode a PDF file in Python - Stack Overflow
How should I base64 encode a PDF file for transport over XML-RPC in Python? More on stackoverflow.com
๐ŸŒ stackoverflow.com
Python API to convert a pdf to Base64 String and POST to an S3 bucket
8.4K subscribers in the pythonhelp community. A subreddit for helping Python programmers More on reddit.com
๐ŸŒ r/pythonhelp
1
1
March 4, 2025
Python - How to write a PDF from a BINARY STRING
Do you get an error with base64.b64decode(img, validate=True)? More on reddit.com
๐ŸŒ r/pythonhelp
3
1
March 12, 2022
Convert Base64 Encoded PDF to Base64 Encoded PNG
Is this for a paid project (i.e for your work?) if so, then I'd recommend using a paid library like iText or Aspose. iText is also licensed under the AGPL, so if you're project is compatible with that then go ahead and use that. Otherwise, you can render a PDF to an image using ImageMagick and there exists a .NET wrapper for it, I've used it before. There is more information and other ways to do it here More on reddit.com
๐ŸŒ r/csharp
9
3
February 9, 2024
People also ask

Q2. How To Use C# To Convert PDF to Base64?
The first step to using C# to convert a PDF to Base64 is loading the file to File.ReadAllBytes. This first step breaks the file into an array of bytes. You can then encode the byte array as you normally would using Convert.ToBase64String(bytes). The second step converts the bytes into a Base64 string, transforming the file into a Base64 file format.
๐ŸŒ
pdf.wondershare.com
pdf.wondershare.com โ€บ convert-pdf โ€บ convert-pdf-to-base64.html
The Complete Guide To Convert PDF to Base64
How do I convert a Base64 string back to a PDF?
You can decode the string back to bytes in any language (atob in JavaScript, base64.b64decode in Python, Convert.FromBase64String in C#) and write the result to a .pdf file. You can also paste a Data URI directly into a browser address bar to view the PDF.
๐ŸŒ
testmuai.com
testmuai.com โ€บ home โ€บ free tools โ€บ pdf to base64
PDF to Base64 Converter | Encode PDF Files Online Free | TestMu ...
What is a PDF to Base64 converter?
A PDF to Base64 converter encodes a binary PDF file into a Base64 text string so it can be safely embedded inside text-only contexts such as JSON payloads, HTML, CSS, XML, or email bodies. The output represents the exact same PDF as ASCII characters instead of raw bytes.
๐ŸŒ
testmuai.com
testmuai.com โ€บ home โ€บ free tools โ€บ pdf to base64
PDF to Base64 Converter | Encode PDF Files Online Free | TestMu ...
๐ŸŒ
ItSolutionstuff
itsolutionstuff.com โ€บ post โ€บ how-to-convert-pdf-to-base64-string-in-pythonexample.html
How to Convert PDF to Base64 String in Python? - ItSolutionstuff.com
October 30, 2023 - # Import base64 Module import base64 # Python Convert PDF to Base64 String with open("sample.pdf", "rb") as imageFile: encodedString = base64.b64encode(imageFile.read()) print(encodedString);
๐ŸŒ
Base64 Encode
base64encode.net โ€บ pdf-to-base64
PDF to Base64 Encode - Online Tool
PDF to Base64 ยท Base32 Encode ยท PHP base64_encode() Python base64.b64encode() Perl encode_base64() VB System.Convert.ToBase64String() C# System.Convert.ToBase64String() Java encode() Golang EncodeToString() Ruby Base64.encode64() MySQL to_base64() Dojo dojox.encoding.base64.encode() PostgreSQL encode() Linux base64 encode ยท
Find elsewhere
๐ŸŒ
Pythondex
pythondex.com โ€บ convert-pdf-to-base64-python
Convert PDF To Base64 In Python - Pythondex
January 31, 2024 - In this article I will show you how to convert pdf file to base64 using python, so inorder to convert a pdf file to base64 we will use the python library Base64 it allows us to encode and decode base64 code.
๐ŸŒ
Testmuai
testmuai.com โ€บ home โ€บ free tools โ€บ pdf to base64
PDF to Base64 Converter | Encode PDF Files Online Free | TestMu AI (Formerly LambdaTest)
Pick the Plain Base64 output, then ...plication/pdf","data":"JVBERi0xLjQKโ€ฆ"}. Most e-sign, payment, and document APIs (DocuSign, Stripe Files, SendGrid attachments, etc.) accept this shape. You can decode the string back to bytes in any language (atob in JavaScript, base64.b64decode in Python, Convert.FromBase64String ...
๐ŸŒ
Aspose
blog.aspose.com โ€บ aspose.blogs โ€บ convert pdf to base64 in python โ€” step-by-step guide with aspose.pdf
Convert PDF to Base64 in Python โ€” Step-by-Step Guide with Aspose.PDF
September 5, 2025 - Visit the temporary license page to obtain one and unlock the full potential of the API. If you want to quickly convert a PDF file to Base64 without writing any code, you can use the free online PDF to Base64 converter.
๐ŸŒ
ToolFK
toolfk.com โ€บ home โ€บ base64 โ€บ pdf to base64
Free Online PDF to Base64 Converter - Toolfk Online Tools
June 16, 2026 - The process of conversion of PDF to Base64 is 100% reversible thus with no loss in quality whatsoever. You can decode the Base64 string using built-in functions in languages such as JavaScript (atob()), or Python (base64.b64decode()), or through online Base64 to PDF converters that restore ...
๐ŸŒ
PDFNano
pdfnano.com โ€บ home โ€บ pdf to base64
PDF to Base64 Encoder - Free Online Converter
Cross-Language Support: Use Base64 strings across JavaScript, PHP, Python, Java, or C#. Mobile Ready: Works on all devices without installing any additional software. No Limits: Convert small or large PDFs instantly without restrictions.
๐ŸŒ
Reddit
reddit.com โ€บ r/pythonhelp โ€บ python api to convert a pdf to base64 string and post to an s3 bucket
r/pythonhelp on Reddit: Python API to convert a pdf to Base64 String and POST to an S3 bucket
March 4, 2025 - How to convert JSON file into readable file format such as PDF, TXT, CSV, and more? ... Working on my own file system! ... In the process of making a file system... ... I hacked together a basic Python GUI for CAN MitM routing and signal decoding.
๐ŸŒ
GitHub
gist.github.com โ€บ aspose-com-gists โ€บ a4379c7ea21564762af508d743a3336e
Convert PDF to Base64 in Python โ€” Step-by-Step Guide with Aspose.PDF
convert-pdf-to-base64-in-python_encode.py ยท This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters ยท
๐ŸŒ
Pi7 Base64 Tool
base64.pi7.org โ€บ pi7 base64 tool โ€บ pdf to base64
PDF to Base64 Converter Online - No Upload, Free | Pi7
Pick a PDF above and this tool turns it into a Base64 string right away. You get three things back: a data URI you can paste straight into an iframe, an embed code block, and the raw Base64 string on its own.
๐ŸŒ
Aspose
products.aspose.app โ€บ pdf apps โ€บ convert โ€บ pdf to base64
PDF to BASE64 online โ€” PDF to base 64
1 day ago - PDF to Base64 Converter is a service for online file conversion from one type to another. We support many popular formats for work, all possible image formats, multimedia file formats, etc.
๐ŸŒ
Ocaso3D
b64encode.com โ€บ tools โ€บ pdf-to-base64
Convert PDF to Base64 Online - B64Encode
January 2, 2024 - Base64 encoding is a widely used method for converting binary data into human-readable ASCII text, making it a valuable tool for embedding binary data into text-based environments. Adobe Systems created the Portable Document Format (PDF) as a cross-platform file format.
๐ŸŒ
Convertchief
convertchief.com โ€บ tools โ€บ pdf-to-base64
PDF to Base64 Encoder - Convert PDF to Base64 Data
Convert PDF to Base64 instantly โ€” upload your PDF and get a Base64 encoded string to embed anywhere. Free online encoder, no sign-up needed.
Author: ShubhamBansal1997
๐ŸŒ
APIVoid
apivoid.com โ€บ tools โ€บ pdf-to-base64
PDF to Base64 Converter - PDF to Base64 Encoder | APIVoid
Convert PDF files to Base64 online for free. Upload a PDF and instantly get a Base64 string for HTML, embeds, and web applications.
๐ŸŒ
Base64Encode.org
base64encode.org โ€บ enc โ€บ pdf
Base64 Encoding of "pdf" - Online
Encode pdf to Base64 format with various advanced options. Our site has an easy to use online tool to convert your data.