When generating PDFs on iOS, it seems that the format version of the resulting file always defaults to version 1.3 of the PDF specification. Even when opening an existing PDF file with format version 1.7, after the file is written back to disk the format version is changed to 1.3. This behavior is observable with each of Apple's PDF APIs as shown by the following example:
let documentDirectoryUrl = FileManager.default.urls(for: .documentDirectory,
in: .userDomainMask).first
let pdfVersion: ((URL) -> (String?)) = { url in
if let pdf = PDFDocument(url: url) {
return "\(pdf.majorVersion).\(pdf.minorVersion)"
}
return nil
}
if let url = documentDirectoryUrl?.appendingPathComponent("pdfKit").appendingPathExtension("pdf") {
let pdf = PDFDocument()
pdf.write(to: url)
print("PDFKit \(pdfVersion(url) ?? "")")
}
if let url = documentDirectoryUrl?.appendingPathComponent("uiKit").appendingPathExtension("pdf"),
let context = CGContext(url as CFURL, mediaBox: nil, nil) {
context.closePDF()
print("UIKit \(pdfVersion(url) ?? "")")
}
if let url = documentDirectoryUrl?.appendingPathComponent("coreGraphics").appendingPathExtension("pdf") {
UIGraphicsBeginPDFContextToFile(url.path, .zero, nil)
UIGraphicsEndPDFContext()
print("CoreGraphics \(pdfVersion(url) ?? "")")
}
What's interesting is that there are several references in Apple's documentation and header files that mention version 1.7 of the PDF specification, for example: CGPDFContext.addDocumentMetadata(_:)
How can I specify the format version when writing a PDF file on iOS? Is this even possible?
Thanks!
ISO 19005-1. It is based on PDF 1.4, the file format of Acrobat 5,XMP was introduced with Acrobat 5 and PDF 1.4 in 2001. Ideally you should compare requirements against both levels