https://stackoverflow.com/questions/475421/base64-encode-a-pdf-in-c
Use
File.ReadAllBytes
to load the PDF file, and then encode the byte array as normal using
Convert.ToBase64String(bytes)
.
https://stackoverflow.com/questions/24808014/convert-base64-encoding-to-pdf
byte[] sPDFDecoded = Convert.FromBase64String(base64BinaryStr); File.WriteAllBytes(@"c:\Users\u316383\Documents\pdf8.pdf", sPDFDecoded);
Example
string filePath = @"D:\ChuckLu\Material\Project\Chile\Never frown.pdf"; var bytes = File.ReadAllBytes(filePath); var str = Convert.ToBase64String(bytes); Console.WriteLine(str); #region base64string var str2 = @"JVBERi0xLjcNCiWhs8XXDQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIgL091dGxpbmVzIDE4IDAgUiAvUGFnZUxhYmVsczw8L0tpZHNbIDE5IDAgUiBdPj4vTGFuZyh6aC1DTikvTWFya0luZm88PC9NYXJrZWQgdHJ1ZT4+L1N0cnVjdFRyZWVSb290IDIwIDAgUiAvQWNyb0Zvcm08PC9GaWVsZHNbXT4+L01ldGFkYXRhIDM3IDAgUiA+Pg0KZW5kb2JqDQo1IDAgb2JqDQo8PC9UeXBlL1BhZ2UvUGFyZW50IDYgMCBSIC9SZXNvdXJjZXM8PC9FeHRHU3RhdGU8PC9HUzUgNyAwIFIgL0dTOCA4IDAgUiA+Pi9Gb250PDwvRjEgOSAwIFIgL0YyIDEzIDAgUiA+Pi9Qcm9jU2V0Wy9QREYvVGV4dC9JbWFnZUIvSW1hZ2VDL0ltYWdlSV0+Pi9NZWRpYUJveFsgMCAwIDU5NS4zMiA4NDEuOTJdL0NvbnRlbnRzIDE3IDAgUiAvR3JvdXA8PC9UeXBlL0dyb3VwL1MvVHJhbnNwYXJlbmN5L0NTL0RldmljZVJHQj4+L1RhYnMvUy9TdHJ1Y3RQYXJlbnRzIDA+Pg0KZW5kb2JqDQoxMSAwIG9iag0KPDwvTGVuZ3RoIDkwNTUvTGVuZ3RoMSAxMzM3MjQvRmlsdGVyL0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