How to get page count of pdf byte array generated through SSRS

孤街浪徒 提交于 2019-12-12 20:13:52

问题


My task is to get page count of a pdf content. I made use of SSRS tools to generate pdf byte array. Once I get byte array I need to get the page count of this byte array generated. C# is the programming language used.

Currently I am creating a pdf file physically, using the generated pdf byte array. Later I am opening the pdf file in the memory and getting the page count. Finally I am deleting the file that has been created for temporary purpose.

Is there any way to get the page count of the generated pdf byte array without creating a physical file? Or can I create a pdf file object in the memory?

PDF creation needs extra security permissions and we don't use pdf file for any other purpose.


回答1:


I fixed this problem using the below code.

Thanks for your help.

int pageCount;
MemoryStream stream = new MemoryStream(pdfContent);
using (var r = new StreamReader(stream))
{
    string pdfText = r.ReadToEnd();
    System.Text.RegularExpressions.Regex regx = new Regex(@"/Type\s*/Page[^s]");
    System.Text.RegularExpressions.MatchCollection matches = regx.Matches(pdfText);
    pageCount = matches.Count;
}



回答2:


Save the PDF stream. Use an iTextSharp reference to open the PDF on the server and count pages.



来源:https://stackoverflow.com/questions/21158067/how-to-get-page-count-of-pdf-byte-array-generated-through-ssrs

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