How to find out the name of a PDF file using the link to the CGPDFDictionaryRef object

I have an object of type CGPDFDictionaryRef returned in some way from a method that is considered to be part of a static library (so I don’t have access to its code to change it), however I want to know the name of the PDF file that is stored in this dictionary? How can I query it to get the file name?

+4
source share
2 answers

CGPDF * functions are a functional mechanism that allows you to go to a series of arrays, dictionaries, integers, string and name elements in PDF documents. PDF documents themselves really only consist of these β€œcore” elements. If you want some kind of bright reading, look at the 1,500-page PDF specification. As rob mayoff pointed out, you basically point to memory when you have a CGPDFDocumentRef.

However, there is no value that is guaranteed in the PDF structure, which will give you the file name. Download Voyeur and dig up your PDF to look around and prove that I'm wrong (I could be).

Here is a sample of the true PDF content:

voyeur sample

+5
source

There are two functions that take a CGPDFDocumentRef and return a CGPDFDictionaryRef . They are CGPDFDocumentGetInfo and CGPDFDocumentGetCatalog . None of the functions returns a dictionary that contains the name of the source file. Also the array is not returned by CGPDFDocumentGetID .

This makes sense because you can create a CGPDFDocumentRef without a file, from the data you receive through the socket, or by drawing in CGPDFContext with Quartz 2D.

If you want to specify a file name, you will have to use it in a different way.

+5
source

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


All Articles