1

(警告:第一次使用 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);
        }
    }


}
4

0 回答 0