首页 \ 问答 \ Aspose PDF从byte [] []合并PDF(Aspose PDF Merge PDF from byte[][])

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 using Aspose - PDF. The merged file is then converted to a Memory Stream and then a blob 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
更新时间:2024-02-24 17:02

最满意答案

原来这是在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. ...
  • 凯文, 在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 ...
  • 更改 this.OnPropertyChanged(); 至 this.OnPropertyChanged("Show_element"); 编辑:除此之外,你没有ViewModel(抱歉,在我检查你的代码时错过了),所以你需要创建一个并将其设置为DataContext: ViewModel.cs: public class ViewModel : INotifyPropertyChanged { private bool show_element; public bool Show_e ...
  • 在web.config上添加类的命名空间,以便它可以识别它... Add the namespace of class on the web.config so it can recognize it ... probably
  • 使用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 ...

相关文章

更多

最新问答

更多
  • 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
  • 如何通过引用返回对象?(How is returning an object by reference possible?)
  • 矩阵如何存储在内存中?(How are matrices stored in memory?)
  • 每个请求的Java新会话?(Java New Session For Each Request?)
  • css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
  • 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
  • xcode语法颜色编码解释?(xcode syntax color coding explained?)
  • 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
  • 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
  • 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
  • 西安哪有PLC可控制编程的培训
  • 在Entity Framework中选择基类(Select base class in Entity Framework)
  • 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
  • 电脑二级VF有什么用
  • Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
  • 金华英语角.
  • 手机软件如何制作
  • 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
  • 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
  • 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
  • Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
  • 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
  • python的访问器方法有哪些
  • DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
  • 在Ruby中对组合进行排序(Sorting a combination in Ruby)
  • 网站开发的流程?
  • 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
  • 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
  • 透明度错误IE11(Transparency bug IE11)
  • linux的基本操作命令。。。