Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7166905
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T14:29:22+00:00 2026-05-28T14:29:22+00:00

noob to C# here, using iTextSharp examples from around SO I’ve made a basic

  • 0

noob to C# here, using iTextSharp examples from around SO I’ve made a basic exe to change title, description and keywords to an existing PDF. Using MS Visual C# 2010, I don’t understand all this ‘Generic’ change to C#, so I’m getting this error:

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

and

Cannot implicitly convert type 'System.Collections.Hashtable' to 'System.Collections.Generic.IDictionary<string,string>'. An explicit conversion exists (are you missing a cast?)

The Code:

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();
            }
        }
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T14:29:23+00:00Added an answer on May 28, 2026 at 2:29 pm

    Change the below line:

    Dictionary<string,string> newInfo = pdfReader.Info;             
    

    instead of

    Hashtable newInfo = pdfReader.Info;
    

    Should fix both errors.

    The reason why this is happening is because you are trying to cast from a Hashtable to a Generic Dictionary and the hashtable does not have an implicit type conversion available for this. look here to see the difference between a hashtable and a Dictionary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

noob here, I'm trying to transfer a file using rsync from windows to linux.
c#/oop noob here. I am creating a datatable from the schema of a sql
I think this script is of big interest to any noob around here :)
Noob here - I'm working on a simple Javascript calculator, and I'm using lists
complete Python noob here (and rusty in C). I am using a Mac with
Noob question here, every time I change a certain record in an SQL Server
Rails noob here. I am using carrierwave in a rails 3 app so users
This is probably a java noob question but here is my scenario: using selenium,
Using python to pick it some pieces so definitely a noob ? here but
noob here and need help from the pros... i am doing a voice record

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.