(警告:Stackoverflow上的第一次)我希望能够通过二进制文件读取pdf,但在将其写回隔离存储时遇到问题。当它被写回隔离存储并且我尝试打开文件但是我收到来自adobe reader的错误消息,说这不是有效的pdf。该文件是102 KB,但当我将其写入隔离存储时,它是108 KB。
我这样做的理由是我希望能够拆分pdf。我试过了PDFsharp(没有打开所有的pdf类型)。这是我的代码:
public void pdf_split()
{
string prefix = @"/PDFread;component/";
string fn = originalFile;
StreamResourceInfo sr = Application.GetResourceStream(new Uri(prefix + fn, UriKind.Relative));
IsolatedStorageFile iStorage = IsolatedStorageFile.GetUserStoreForApplication();
using (var outputStream = iStorage.OpenFile(sFile, FileMode.CreateNew))
{
Stream resourceStream = sr.Stream;
long length = resourceStream.Length;
byte[] buffer = new byte[32];
int readCount = 0;
while (readCount < length)
{
int read = sr.Stream.Read(buffer, 0, buffer.Length);
readCount += read;
outputStream.Write(buffer, 0, read);
}
}
}