0

I'm new to PDF Clown and, taking a look at the samples included in its distribution, I noticed they use file = new org.pdfclown.files.File(path) to create new PDF files, then file.Save(anotherPath) to save them to the file system, but I couldn't find any example that would allow me to generate PDF documents and save them into byte array to be stored in RAM memory.

Basically what we're doing is to pass our customer's input data to the PDF document, generate it in memory, then attach it to emails or save it to database, without needing intermediate disk storage.

4

1 回答 1

1

这是将文件保存到内存流 (C#) 的正确方法:

org.pdfclown.files.file = . . .;
. . .
var targetStream = new System.IO.MemoryStream();
file.Save(new org.pdfclown.bytes.Stream(targetStream), SerializationModeEnum.Standard);

在接下来的几天里,我将向项目的存储库(版本 0.1.2.1 或更高版本)提交一个简化的重载,所以你可以这样做:

var targetStream = new System.IO.MemoryStream();
file.Save(targetStream, SerializationModeEnum.Standard);

为什么我们org.pdfclown.bytes.Stream在前Save一种方法中使用了包装器?因为,由于 PDF Clown 在多个平台(Java、.NET)中实现,它需要一个抽象的通用接口来一致地处理 I/O 并简化跨平台的代码开发和维护。

PS:如果您对PDF Clown的最新消息感兴趣,请不要错过订阅它的推特流

于 2015-03-20T11:36:15.297 回答