iTextSharp dll 4.1.2.0问题导致合并的pdf中出现空白页 [英] iTextSharp dll 4.1.2.0 issue causing blank pages in a merged pdf

查看:480
本文介绍了iTextSharp dll 4.1.2.0问题导致合并的pdf中出现空白页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用iTextSharp dll版本4.1.2.0进行pdf合并。但它导致最终合并的pdf中的某些页面空白。但是这个问题在最新的dll中没有出现。
我使用.net框架1.1,所以我不能使用最新的dll因为它不支持。
所以,请给出建议我该怎么做。

I am using iTextSharp dll version 4.1.2.0 for pdf merging.But it is causing some pages blank in the final merged pdf. but this issue is not present in its latest dll. I am using .net framework 1.1 , so i can't use latest dll cause it doesn't support. So,Please give suggestion what should i do for this.

谢谢

推荐答案

是的,我有一些解决方案,如果我们将使用最新的dll那么它没问题,但是如果我们使用支持.net框架1.1的dll可能在最新的dll之前怎么办? 。

Yes, I have got the solutions like "if we will use latest dll then it is ok, no problem but what if we are using a dll that supports .net framework 1.1 that might be before the latest dll.

在我的情况下,问题是某些pdf已损坏且无法正确解析,这就是为什么它会抛出异常为尝试阅读过去的结尾流。我在网上找到了一些pdf,在EOF Marker之后有更多的字符然后就是问题。所以,我们必须从文件中删除所有字符并在新创建的pdf文件中进行测试。它有效对我来说。

The problem in my case are some pdfs are corrupted and not able to parse correctly, that's why it is throwing an exception as "Attempt to Read Past the End of The Stream" .And i found in web that is some pdfs having some more characters after EOF Marker then it is the problem .So,we have to just remove all the characters from the file and test in the newly created pdf file. It has worked for me.

public void RemoveExtraBytes(string ofilepath,nfilepath)
{
        string oldfilePath =ofilepath;
        string newFilePath="nfilepath";
        WebClient client = new WebClient();
        byte[] buffer = client.DownloadData(filePath);
        string str;
        int position = 0;
        str = ASCIIEncoding.ASCII.GetString(buffer);
        if (str.Contains("%%EOF"))
        {
            position = str.LastIndexOf("%%EOF");
        }
        Stream stream = new System.IO.FileStream(newfilepath, FileMode.Create);
        stream.Write(buffer, 0, position);
        stream.Close();
}

这篇关于iTextSharp dll 4.1.2.0问题导致合并的pdf中出现空白页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆