noob to C# 여기서 iTextSharp 예제를 사용합니다. 기존 exe로 제목, 설명 및 키워드를 기존 PDF로 변경했습니다. MS 비주얼 C# 2010를 사용하여, 나는 C#을 모든이 '일반'변화를 이해하지 못하는, 그래서 나는이 오류를 받고 있어요 :iTextSharp HashTable 또는 다른 것을 사용하는 속성?
Cannot implicitly convert type 'System.Collections.Generic.Dictionary<string,string>' to 'System.Collections.Hashtable'
및
Cannot implicitly convert type 'System.Collections.Hashtable' to 'System.Collections.Generic.IDictionary<string,string>'. An explicit conversion exists (are you missing a cast?)
강령
:using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using iTextSharp.text.pdf;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
if ((args == null) || (args.Length < 3))
{
Console.WriteLine("args: PDFProp [fileName] [outputPath] [Title] [Description] [Keywords]");
Console.WriteLine();
Console.Write("<Continue>");
Console.ReadLine();
return;
}
string filePath = args[0];
string newFilePath = args[1];
string title = args[2];
string desc = "";
string keywords = "";
if (args.Length > 3)
desc = args[3];
if (args.Length > 4)
keywords = args[4];
Console.Write(filePath + "->" + newFilePath + " title: " + title + " description: " + desc + " keywords: " + keywords);
Console.WriteLine();
Console.ReadLine();
PdfReader pdfReader = new PdfReader(filePath);
using (FileStream fileStream = new FileStream(newFilePath, FileMode.Create, FileAccess.Write))
{
// string title = pdfReader.Info["Title"] as string;
PdfStamper pdfStamper = new PdfStamper(pdfReader, fileStream);
// The info property returns a copy of the internal HashTable
Hashtable newInfo = pdfReader.Info; // error 1
newInfo["Title"] = title;
if (args.Length > 3)
newInfo["Description"] = desc;
if (args.Length > 4)
newInfo["Keywords"] = keywords;
pdfStamper.MoreInfo = newInfo; // error 2
pdfReader.Close();
pdfStamper.Close();
}
}
}
}
당신의 의견이 정확합니다. C#으로 새 라이브러리를 발견 할 때 메소드를 호출하고 속성에 액세스 할 때'var' 키워드를 사용하는 것이 더 쉬울 때가 있습니다. 'var newInfo = pdfReader.Info;'확실히'var'을 악용 할 수 있지만, 이런 것들은 매우 유용 할 수 있습니다. –
크리스, 예,하지만 혼란을 피하기 위해 명확한 설명을 위해 전체 정의를 사용하고 싶습니다. –
Ahh thankyou 얘들 아, 내 인생에 대한 내가 볼 수 없습니다 : pdfReader.Info는 사전으로 정의되었습니다. pdfReader.Info에 대한 문서는 어디에 있습니까? – ChrisAdmin