在C#控制台应用程序中阅读PDF [英] PDF Reading in C# console application

查看:72
本文介绍了在C#控制台应用程序中阅读PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PdfReader reader = new PdfReader(@"C:\Users\Public\Documents\RMA.pdf");
            int n = reader.NumberOfPages;
            Rectangle psize = reader.GetPageSize(1);
            float width = psize.Width;
            float height = psize.Height;
            Console.WriteLine("Size of page 1 of {0} => {1} × {2}", n, width, height);
            Dictionary<string, string> infodict = reader.Info;
            foreach (KeyValuePair<string, string> kvp in infodict)
                Console.WriteLine(kvp.Key + " => " + kvp.Value);


在上面的代码上我得到了错误

无法将类型"System.Collections.Hashtable"隐式转换为"System.Collections.Generic.Dictionary"< string,string

请提出任何解决方案.


on the above code i got error

Cannot implicitly convert type ''System.Collections.Hashtable'' to ''System.Collections.Generic.Dictionary<string,string

any solution please suggest.

推荐答案

您从何处获得PdfReader类? PdfReader构造函数或GetPageSize方法很可能引发错误.如果您有PdfReader类的源代码,则可以尝试调试错误.
Where did you get the PdfReader class from? Most probably, either the PdfReader constructor or the GetPageSize method is throwing the error. If you have the source code for the PdfReader class, you can try debugging the error.


老实说,错误消息告诉您确切是什么问题.某种返回哈希表,并且您正在尝试将其分配给类型化的Dictionary.您在这里问这类问题是在浪费时间和我们的时间–一点知识,您就可以在不到25分钟的时间内解决这类问题.

从您的评论看来,这是一个相当老的阅读器类,它将Info作为哈希表返回.因此,请勿尝试将其分配给与之不兼容的类型!
Honestly, the error message tells you exactly what is wrong. Something is returning a Hashtable, and you are trying to assign it to a typed Dictionary. You are wasting your time and ours by asking this type of question here – a little knowledge and you could solve this kind of thing in far less than 25 minutes.

From your comment it appears this is quite an old reader class that returns Info as a Hashtable. So don''t try to assign it to a type it isn''t compatible with!


这篇关于在C#控制台应用程序中阅读PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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