-1
我嘗試了多種解決方案,但每次遇到錯誤時,pdf都無法打開。這是需要在.pdf中轉換的實際數據流的編輯代碼。將base64編碼轉換爲pdf
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Globalization;
using System.Threading;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
try
{
string base64BinaryStr = "Q29tcGFueSBTZXJ2aWNpbmcNCjEuCVRvb2xiYXIgQ29tcGFueSBTZXJ2aWNpbmcgU2VsZWN0IEFuIEFjY291bnQNCjIuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmcgRG91YmxlIENsaWNrIG9uIGFuIEFjY291bnQNCjMuCVRvb2xiYXIgQ29tcGFueSBTZXJ2aWNpbmdfRW50ZXIgYWNjb3VudCBudW1iZXIgaW4gdGhlIE51bWJlciBmaWVsZCBvZiB0aGUgQWNvdW50IFNlYXJjaCBTZWN0aW9uDQo0LglUb29sYmFyIENvbXBhbnkgU2VydmljaW5nX1JldHVybg0KNS4JVG9vbGJhciBDb21wYW55IFNlcnZpY2luZ19DbG9zZQ0KNi4JVG9vbGJhciBDb21wYW55IFNlcnZpY2luZ19NZW1vc19DbGVhciBCdXR0b24NCjcuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmdfTWVtb3NfQWRkIEJ1dHRvbg0KOC4JVG9vbGJhcl9Db21wYW55IFNlcnZpY2luZ19NZW1vc19BbHQtQSBUbyBBZGQgQSBNZW1vDQo5LglUb29sYmFyX0NvbXBhbnkgU2VydmljaW5nX01lbW9zX0NoYW5nZQ0KMTAuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmdfTWVtb3NfRGVsZXRlIEJ1dHRvbg0KMTEuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmdfTWVtb3NfUmVmcmVzaA0KMTIuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmdfTWVtb3NfQ2xvc2UgQnV0dG9uDQoxMy4JVG9vbGJhcl9Db21wYW55IFNlcnZpY2luZ19TcGVuZGluZyBDb250cm9sX0VsaXRlDQoxNC4JVG9vbGJhcl9Db21wYW55IFNlcnZpY2luZ19TcGVuZGluZyBDb250cm9sX0Rlc2NyaXB0aW9uIGJ1dHRvbg0KMTUuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmdfU3BlbmRpbmcgQ29udHJvbF9EZXNjcmlwdGlvbiBidXR0b25fU2VsZWN0IFNwZW5kaW5nIENvbnRyb2wNCjE2LglUb29sYmFyX0NvbXBhbnkgU2VydmljaW5nX1NwZW5kaW5nIENvbnRyb2xfRGVzY3JpcHRpb24gYnV0dG9uX1NwZW5kaW5nIENvbnRyb2wgTGluayB0byBWTA0KMTcuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmdfU3BlbmRpbmcgQ29udHJvbF9EZXNjcmlwdGlvbl9DbG9zZSBidXR0b24NCjE4LglUb29sYmFyX0NvbXBhbnkgU2VydmljaW5nX1NwZW5kaW5nIENvbnRyb2xfU2VsZWN0IEFsbF9WaWV3IFRyYW5zYWN0aW9ucw0KMTkuCVRvb2xiYXJfQ29tcGFueSBTZXJ2aWNpbmdfU3BlbmRpbmcgQ29udHJvbF9TcGVuZGluZyBDb250cm9sIExpbmsgdG8gVkwNCjIwLglUb29sYmFyX0NvbXBhbnkgU2VydmljaW5nX1NwZW5kaW5nIENvbnRyb2xfQ2FuY2VsIGJ1dHRvbg0K";
byte[] sPDFDecoded = Convert.FromBase64String(base64BinaryStr);
BinaryWriter writer = new BinaryWriter(File.Open(@"c:\Users\u316383\Documents\pdf9.pdf", FileMode.CreateNew));
writer.Write(sPDFDecoded);
string s = Encoding.UTF8.GetString(sPDFDecoded);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
Console.ReadLine();
}
}
}
}
這是相當短的base64字符串一個有效的PDF文件?即使頭部看起來很短。 – xxbbcc
實際的一個真的很大,但這個也是一個有效的文件,因爲我已經檢查過了。字符串「s」給出了正確的。如果你想我可以給整個字符串。我通過「http://www.motobit .com/util/base64-decoder-encoder.asp「 – Vicky
您的輸入字符串長度爲12個字符,表示8個字節爲輸入PDF。這不太可能是正確的。 – xxbbcc