问题描述
任何人都可以帮助我如何在Objective C中将元数据添加到pdf中。我遇到了一个名为CGPDFContextAddDocumentMetadata的类方法,但找不到任何有关如何实现它的文档。有人可以帮帮我吗。
Can anybody help me in how to add the metadata to a pdf in Objective C.I came across a class method called CGPDFContextAddDocumentMetadata,but could not find any documentation of how to achieve it. Can someone please help me.
提前致谢
推荐答案
可添加的元数据此方法是XMP元数据。它是基于XML的,看起来像这样(这里有完整的文档:):
The metadata that can be added with this method is XMP metadata. It is XML based and looks like this (it is fully documented here: http://www.adobe.com/products/xmp/):
<?xpacket begin="" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c041">
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" >
<rdf:Description rdf:about="" xmlns:dc="http://purl.org/dc/elements/1.1/">
<dc:format>application/pdf</dc:format>
<dc:title>
<rdf:Alt>
<rdf:li />
</rdf:Alt>
</dc:title>
<dc:description>
<rdf:Alt>
<rdf:li />
</rdf:Alt>
</dc:description>
<dc:creator>
<rdf:Seq>
<rdf:li />
</rdf:Seq>
</dc:creator>
</rdf:Description>
<rdf:Description rdf:about="" xmlns:pdf="http://ns.adobe.com/pdf/1.3/">
<pdf:Keywords />
<pdf:Producer />
</rdf:Description>
<rdf:Description rdf:about="" xmlns:xmp="http://ns.adobe.com/xap/1.0/">
<xmp:CreatorTool />
<xmp:CreateDate>2011-02-10T11:41:05+02:00</xmp:CreateDate>
<xmp:ModifyDate>2011-02-10T11:41:06+02:00</xmp:ModifyDate>
</rdf:Description></rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
方法如下:
void CGPDFContextAddDocumentMetadata(CGContextRef context,CFDataRef metadata);
'context'是您的pdf上下文,元数据是您的XMP元数据。您可以在NSString对象(下面的xmpString变量)中构造元数据,然后将NSString转换为CFDataRef:
'context' is your pdf context, metadata is your XMP metadata. You can construct the metadata in a NSString object (xmpString variable below) and then convert the NSString to CFDataRef:
CFDataRef xmpDataRef = (CFDataRef)[xmpString dataUsingEncoding:NSUTF8StringEncoding];
这篇关于任何人都可以帮助我如何在Objective C中将元数据添加到pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!