问题
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