How to set metadata in PDF format using ColdFusion (& iText)

I am trying to set copyright metadata to PDF using ColdFusion and iText. Adobe ColdFusion 9-11 allows you to retrieve and customize the Title, Subject, Keywords, Creator, and Author fields, but it does not seem to allow access to the Advanced Metadata properties. (This is my first question.)

I found a potential iTextSharp / C # solution and tried to convert it to CFML, but I could not determine how to successfully access System.IO.MemoryStream () w / ColdFusion. I get "Can't find ColdFusion component or MemoryStream interface. Make sure the name is correct and that the component or interface exists." error and search on the Internet do not give any results.

stack overflow

NOTE. I use iText because PDF files are created using ABBYY FineReader. In the past, I ran into many problems when ColdFusion refuses to identify PDF files created without Acrobat as valid PDF files using isPDFFile ().

Any ideas? Is there functionality at present and is not documented somewhere? Thanks.

+6
source share
2 answers

(Too long for comments ...)

As Ryan mentioned, this may be possible using DDX. The cfpdf documentation lists Metadata as a supported item. So you can first examine this parameter.

I found a potential iTextSharp / C # solution

However, there is no need to use an external C # library. CF is already associated with the old version of iText (written in java). Therefore use java classes. iTextSharp is the port of the java source library, so class and method names will usually be the same.

 source = "c:/path/to/input.pdf"; target = "c:/path/to/output.pdf"; reader = createObject("java", "com.lowagie.text.pdf.PdfReader").init( source ); output = createObject("java", "java.io.FileOutputStream").init( target ); stamper = createObject("java", "com.lowagie.text.pdf.PdfStamper").init( reader, output ); copyrightName = "YOUR NAME HERE"; copyrightUrl = "http://www.example.com/"; baos = createObject("java", "java.io.ByteArrayOutputStream").init(); xmp = createObject("java", "com.lowagie.text.xml.xmp.XmpWriter").init(baos); xmp.addRdfDescription("xmlns:dc=""http://purl.org/dc/elements/1.1/""", "<dc:rights><rdf:Alt><rdf:li xml:lang=""x-default"">"& copyrightName &"</rdf:li></rdf:Alt></dc:rights>"); xmp.addRdfDescription("xmlns:xmpRights=""http://ns.adobe.com/xap/1.0/rights/""" , "<xmpRights:Marked>True</xmpRights:Marked><xmpRights:WebStatement>"& copyrightUrl &"</xmpRights:WebStatement>"); xmp.close(); stamper.setXmpMetadata(baos.toByteArray()); stamper.close(); 
+5
source

You may be able to do this with DDX features. See the following links:

System.IO.MemoryStream is a C # class. You will not be able to access it directly from CFML. You can try to use the net net functions to access it or the iTextSharp solution directly.

+1
source

Source: https://habr.com/ru/post/979135/


All Articles