PDFsharp-从System.Byte []变量中打开PDF

问题描述

我正在使用PDFsharp,并且正在尝试打开一个表示为Byte []变量的PDF。这是一个简化的示例:

public Byte[] myFunc(Byte[] PDF)
{
    PdfDocument document = PdfReader.Open(PDF_Path); // <-- My problem is here
    // do some modification on the document
    return document;
}

我可以从路径中读取PDF,但是我宁愿使用PDF作为字节数组。 更好的选择是将Byte数组另存为PDF,然后读取它,然后删除我创建的文件吗?这种方法对我来说不合适。

解决方法

您可以将字节数组写入print(f'{word1} {word2} {word3} {word4} {word5} {word6} {word7}') 或为该字节数组创建MemoryStream,然后使用PDFsharp从该流中打开PDF。

无需弄乱临时文件。

更新:OP找到的解决方案(同时从问题中删除):

MemoryStream