Aspose PDF从byte [] []合并PDF(Aspose PDF Merge PDF from byte[][])
我正在开发一种服务,将多个PDF文件作为
varbinary
存储在数据库中,并使用Aspose - PDF
将它们合并到一个文件中。 然后将合并的文件转换为Memory Stream
,然后转换为blob
,然后发送到网页。这是我的服务:
public MemoryStream GetPrintContent(List<ConfirmationRequestNoticeViewModel> models) { // Instantiate Pdf instance by calling its empty constructor Document pdf1 = new Document(); byte[][] bytes = new byte[models.Count][]; for (int i = 0; i < models.Count; i++) { ConfirmationRequestNoticeViewModel model = models[i]; byte[] fileContent = _dataService.GetPrintContent(model.ConfirmationRequestId); bytes[i] = fileContent; } MemoryStream stream = new MemoryStream(); List<Document> documents = GeneratePdfs(bytes, stream); stream = ConcatenatePdf(documents); return stream; } private MemoryStream ConcatenatePdf(List<Document> documents) { MemoryStream stream = new MemoryStream(); Document mergedPdf = documents[0]; for(int index = 1; index < documents.Count; index++) { for (int i = 0; i < documents[index].Pages.Count; i++) { mergedPdf.Pages.Add(documents[index].Pages[i + 1]); } } mergedPdf.Save(stream); return stream; } private List<Document> GeneratePdfs(byte[][] content, MemoryStream stream) { List<Document> documents = new List<Document>(); Document pdf = new Document(); foreach (byte[] fileContent in content) { using (MemoryStream fileStream = new MemoryStream(fileContent)) { pdf = new Document(fileStream); pdf.Save(stream); documents.Add(pdf); } } return documents; }
除了
mergedPdf.Save(stream);
行之外,一切都很好mergedPdf.Save(stream);
它返回错误无法访问封闭的流 。我一直在研究这一点,似乎无法理解为什么记忆流已关闭。 有其他人遇到过这个问题吗?
编辑:
我发现这里列出的问题
I'm working on a service that pulls multiple PDF files stored in a database as
varbinary
and merges them into a single file usingAspose - PDF
. The merged file is then converted to aMemory Stream
and then ablob
and then sent to the webpage.Here's my service:
public MemoryStream GetPrintContent(List<ConfirmationRequestNoticeViewModel> models) { // Instantiate Pdf instance by calling its empty constructor Document pdf1 = new Document(); byte[][] bytes = new byte[models.Count][]; for (int i = 0; i < models.Count; i++) { ConfirmationRequestNoticeViewModel model = models[i]; byte[] fileContent = _dataService.GetPrintContent(model.ConfirmationRequestId); bytes[i] = fileContent; } MemoryStream stream = new MemoryStream(); List<Document> documents = GeneratePdfs(bytes, stream); stream = ConcatenatePdf(documents); return stream; } private MemoryStream ConcatenatePdf(List<Document> documents) { MemoryStream stream = new MemoryStream(); Document mergedPdf = documents[0]; for(int index = 1; index < documents.Count; index++) { for (int i = 0; i < documents[index].Pages.Count; i++) { mergedPdf.Pages.Add(documents[index].Pages[i + 1]); } } mergedPdf.Save(stream); return stream; } private List<Document> GeneratePdfs(byte[][] content, MemoryStream stream) { List<Document> documents = new List<Document>(); Document pdf = new Document(); foreach (byte[] fileContent in content) { using (MemoryStream fileStream = new MemoryStream(fileContent)) { pdf = new Document(fileStream); pdf.Save(stream); documents.Add(pdf); } } return documents; }
Everything is working great except for the line
mergedPdf.Save(stream);
which returns the error Cannot access a closed stream.I've been working on this and can't seem to understand why the Memory Stream has been closed. Has anyone else encountered this issue?
Edit:
I've found the issue listed here
原文:https://stackoverflow.com/questions/41554951
最满意答案
原来这是在javascript中设置image.src = null的错误。 它仍然会将'null'识别为src值并尝试加载它。
在null.aspx的情况下,我有一个重写规则添加'.aspx'位。
更多参考: http : //mindfultechnology.wordpress.com/2008/02/03/javascript-imgsrc-null-to-load-or-not-to-load/
Turns out this is a bug with setting image.src=null in javascript. It will still recognise 'null' as a src value and attempt to load it.
In the case of null.aspx I have a rewrite rule adding the '.aspx' bit.
More reference: http://mindfultechnology.wordpress.com/2008/02/03/javascript-imgsrc-null-to-load-or-not-to-load/
相关问答
更多-
我没有这个错误,但经过一些谷歌搜索后,我发现这个链接,我不确定你是否看到过它: http : //forums.asp.net/t/956297.aspx 编辑(添加关键文字): 如果在web.config中指定引用并且部署文件夹/站点不包含安装在系统中的这些dll或bin文件夹中不包含这些dll(如果它们是私有程序集),则会出现此错误。 例如:如果你的web.config包含像这样的任何程序集并且部署的服务器不包含bin或GAC中的这些集合,则添加assembly =“Namespace1.NameSpa ...
-
原来这是在javascript中设置image.src = null的错误。 它仍然会将'null'识别为src值并尝试加载它。 在null.aspx的情况下,我有一个重写规则添加'.aspx'位。 更多参考: http : //mindfultechnology.wordpress.com/2008/02/03/javascript-imgsrc-null-to-load-or-not-to-load/ Turns out this is a bug with setting image.src=null ...
-
我怀疑你需要创建自己的错误日志实现来记录标准属性以外的任何东西。 这不应该太困难。 使用SqlErrorLog作为示例,您只需要覆盖日志方法并放入自己的逻辑来修改Error类包含的内容,然后再调用基本实现。 使用@Matthew所说的将阻止你两次记录异常。 所有的源代码都在这里 I suspect you'll need to create your own errorlog implementation to log anything other than the standard properties. ...
-
.aspx页面的IIS限制错误,但.aspx不受限制(IIS restriction error for .aspx page, but .aspx is not restricted)[2022-06-17]
凯文, 在IIS管理控制台中,请为您的托管服务器打开ISAPI和CGI限制功能。 ASP.NET v2.0和v4.0限制是单独设置的。 TargetProcess应用程序自2.22.9版本开始使用.NET v4.0,因此请检查是否已安装MS .NET framework v4.0并允许使用ASP.NET v4.0。 另外在TP网站的Handler Mappings部分也应该启用PageHandlerFactory-ISAPI-4.0。 如果您需要任何帮助,请通过http://messenger.provid ... -
尝试这个 if(document.getElementById('<%= yourtextboxid.ClientID%>').value != "") { alert("has value!") } else { alert("please enter some thing"); document.getElementById('<%= yourtextboxid.ClientID%>').focus(); } Try this ...
-
无法绑定XAML uwp(Trouble binding XAML uwp)[2023-01-11]
更改 this.OnPropertyChanged(); 至 this.OnPropertyChanged("Show_element"); 编辑:除此之外,你没有ViewModel(抱歉,在我检查你的代码时错过了),所以你需要创建一个并将其设置为DataContext: ViewModel.cs: public class ViewModel : INotifyPropertyChanged { private bool show_element; public bool Show_e ... -
常量和aspx(Constants and aspx)[2022-04-17]
在web.config上添加类的命名空间,以便它可以识别它... Add the namespace of class on the web.config so it can recognize it ... probably -
从aspx.cs页面的jquery帖子中获取Null响应而不是json(Getting Null response instead of json in jquery post from aspx.cs page)[2023-01-03]
使用Restful Webservices或Web方法从AJAX调用是个好主意。 但是你仍然可以做到以下几点。 使用Response.Write()而不是返回字符串。 使用此代码。 private void test() { var response = new ResponseResult(); var javaScriptSerializer = new JavaScriptSerializer(); response.Status = -1; response.Err ... -
我还没有设法找出为什么会出现这个问题。 VS似乎只是在打结。 但是我找到了另一个解决方案,当我的问题中提到的解决方案没有时,它可以工作 只需将aspx和代码复制到记事本中,从项目中删除文件,重新创建它们并将代码复制回来。为什么这样做? 我不知道 I've still not managed to find out why this problem is occurring. VS just seems to be tying itself in knots. However I have found ano ...
-
您是否在任何控制器上使用HandleError属性? 如果存在此属性,则在发生未处理的异常时,ASP.NET MVC将在控制器的视图文件夹中查找名为Error.aspx的视图。 如果找不到,则查找共享视图文件夹。 如果您的项目中有默认控制器(即HomeController,AccountController),那么您会注意到它们具有该属性。 Are you using a HandleError attribute on any of your controllers? If this attribute ...