我尝试了多种解决方案,但每次我收到错误,pdf无法打开。这是带有实际数据流的编辑代码,需要在.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();
}
}
}
}
答案 0 :(得分:8)
给出了错误的字符串。这很简单。对于任何其他引用,我的代码是:
byte[] sPDFDecoded = Convert.FromBase64String(base64BinaryStr);
File.WriteAllBytes(@"c:\Users\u316383\Documents\pdf8.pdf", sPDFDecoded);
谢谢大家。