Assigning revit sheet parameters as PDF file metadata

So basically when renaming PDFs according to BS1192, the PDF files are not sorted in the folder properly according to the list of drawings, so I was wondering if a sheet parameter “sequence number” can be added to the PDF file as metadata and then in the windows explorer window the files are sorted accordingly.
Thanks

1 Like

Hi Amin,
You can add metadata to pdf by adding this code to the open source DynamoPDF package GitHub - grevit-dev/DynamoPDF: Dynamo PDF Parser :

        /// <summary>
        /// 
        /// </summary>
        /// <param name="pdfPath"></param>
        /// <param name="propertyKey"></param>
        /// <param name="propertyValue"></param>
        public static string AddMetadata(string pdfPath, string propertyKey, string propertyValue)

        {
            try
            {
                PdfDocument document = PdfReader.Open(pdfPath);

                var properties = document.Info.Elements;

                Dictionary<string, string> paramNameValue = new Dictionary<string, string>
            {
                { propertyKey, propertyValue },

            };

                foreach (var element in paramNameValue)
                {

                    if (properties.ContainsKey("/" + element.Key))
                    {
                        properties.SetValue("/" + element.Key, new PdfString(element.Value));
                    }
                    else
                    {
                        properties.Add(new KeyValuePair<String, PdfItem>("/" + element.Key, new PdfString(element.Value)));
                    }
                }


                document.Save(pdfPath);

                document.Close();

                return $"Custom properties added to {pdfPath}";
            }
            catch
            {
                return $"Can't process file {pdfPath}";
            }
        }

Unfortunately, I haven’t found a way to display those metadata in windows explorer:

Hello Giovanni,

I don’t really understand where I need to insert your Code. It’s not working by simply adding it to dynamo. Do I need to edit the DynamoPDF package and then make a new build in Visual Studio? (that’s what I tried by I have no experience there)

Is there the possibility you can share the .dyn file? It looks very promising and somehow there are no other topics around metadata in PDF to find anywhere.

Hi Enrico,

Yes I have added that bit of code to the DynamoPDF package. So you should clone this repo GitHub - giobel/DynamoPDF and compile it.

Please have a look at these link1 and link2 for the dyn file and package.

Let me know if it does not work…

Cheers

Hello Giovanni,

thank you very much for your time. The provided links were helping a lot and I was able to make it work as expected.

Let me point out for everyone else that you need to put the folder DynamoPDF, from the AddPdfMetadata folder in the direction of your Dynamo Packages. I also needed to give permission to each file in the folder in the windows properties, so that dynamo was able to load everything.

I am also able to make the Metadata visible in windows explorer for “Title”, “Author”, “Subject” and “keywords”. I’m using a german version where it is called “Titel”, “Autoren”, “Betreff” and “Markierungen”. We still need to use the english words in dynamo to feed the information. It’s then possible to sort/group and filter by the provided metadata.

thanks again ^^

how can i get the page size of several pdf