iTextSharp dll 4.1.2.0 issue causing blank pages in a merged pdf

喜夏-厌秋 提交于 2019-12-11 16:47:42

问题


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.

Thanks


回答1:


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.

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();
}


来源:https://stackoverflow.com/questions/8784012/itextsharp-dll-4-1-2-0-issue-causing-blank-pages-in-a-merged-pdf

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!