This project has moved and is read-only. For the latest updates, please go here.

Persist Custom properties from PDF to Image using Magick

Oct 9, 2014 at 1:22 PM

I am trying to persist custom properties from PDF to PNG, but When I open the PNG-->Properties-->Details. I do not see the custom information. I need to persist custom properties stored in PDF file along with custom information in PNG file details.

string guid = Guid.NewGuid().ToString();
        string folderPath = FOLDERPATH;;
        var imageFolderPath = folderPath + guid;

        var settings = new MagickReadSettings();
        // Settings the density to 300 dpi will create an image with a better quality
        settings.Density = new MagickGeometry(300, 300);
        using (var images = new MagickImageCollection())

            // loading bytes from a file 
            byte[] pdfFileAsbytes = System.IO.File.ReadAllBytes(Path of PDF ));

            // Add all the pages of the pdf file to the collection
            images.Read(pdfFileAsbytes, settings);

            int page = 1;
            foreach (MagickImage image in images)
                    new KeyValuePair<string, string>(
                        string.Format(imageFolderPath + "\\{0}.png", page),

                // attempt to get the profile(s)...
              var  updatedIptcProfile = image.GetIptcProfile();
              var  updatedExifProfile = image.GetExifProfile();

                // if the profile(s) are null, create a new one; otherwise use existing profile data...
                updatedIptcProfile = (updatedIptcProfile ?? new IptcProfile());
                updatedExifProfile = (updatedExifProfile ?? new ExifProfile());

                // update the various stuff
                updatedIptcProfile.SetValue(IptcTag.Title, " ID ");
                updatedIptcProfile.SetValue(IptcTag.Keyword, "Id card");
                updatedIptcProfile.SetValue(IptcTag.Caption, "image magick");
                updatedIptcProfile.SetValue(IptcTag.CustomField1, "1234567890");
                updatedIptcProfile.SetValue(IptcTag., "image magick");


                // Write page to file that contains the page number
                image.Write(imageFolderPath + "\\" + page + ".png");

Please let me know, how to persist Metadata/Custom attribute information in PNG using your library.
Oct 9, 2014 at 2:21 PM
Can you post your PDF on something like DropBox? Feel free to contact me if you don't want to publicly share the PDF file.