如何在Objective C中将元数据添加到pdf中? [英] How to add the metadata to a pdf in Objective C?

查看:128
本文介绍了如何在Objective C中将元数据添加到pdf中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Objective C中将元数据添加到pdf中?我遇到了一个名为CGPDFContextAddDocumentMetadata的类方法,但是找不到有关如何实现它的任何文档.

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.

推荐答案

可以使用此方法添加的元数据是XMP元数据.它基于XML,看起来像这样(此处完整记录: http://www.adobe.com /products/xmp/):

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);

上下文"是您的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中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆