使用CoreGraphics修改pdf元数据颜色空间
我试图更改pdf文件的图像对象的颜色空间,但第一个问题是在pdf元数据中找不到ICC颜色配置文件 元数据中只有一个包含2个组件的数组:使用CoreGraphics修改pdf元数据颜色空间,pdf,core-graphics,quartz-graphics,color-space,Pdf,Core Graphics,Quartz Graphics,Color Space,我试图更改pdf文件的图像对象的颜色空间,但第一个问题是在pdf元数据中找不到ICC颜色配置文件 元数据中只有一个包含2个组件的数组: ColorSpace : Name value: ICCBased Stream value (null) 当我将流解析到字典中时: Color Space Name ICCBased Filter : Name value: FlateDecode Length : integer value: 389757 N
ColorSpace :
Name value: ICCBased
Stream value (null)
当我将流解析到字典中时:
Color Space Name ICCBased
Filter :
Name value: FlateDecode
Length :
integer value: 389757
N :
integer value: 4
Range :
ARRAY with value:
integer value: 0
integer value: 1
integer value: 0
integer value: 1
integer value: 0
integer value: 1
integer value: 0
integer value: 1
但我无法在元数据中找到图像颜色空间中使用的ICC配置文件数据,您可以通过acrobat看到:
顺便说一下,如果您对如何使用coreGraphics获取元数据表单pdf文件感兴趣,我在这里提供了一些代码:
CGPDFDocumentRef pdfDocument=CGPDFDocumentCreateWithURL(pdfURL)
CGPDFPageRef page=CGPDFDocumentGetPage(pdfDocument,页码)
CGPDFContentStreamRef内容流=
CGPDFContentStreamCreateWithPage(第页);CGPDFOOperatorTableRef
operatorTable=CGPDFOOperatorTableCreate()
CGPDFOOperatorTableSetCallback(operatorTable,“Do”和op_-Do)
CGPDFScannerRef内容流扫描程序=
CGPDFScannerCreate(contentStream,可操作,NULL)
CGPDFScannerScan(contentStreamScanner)
然后在回调中:
静态void op_Do(CGPDFScannerRef s,void*info){
CGPDFObjectRef imageObject=CGPDFContentStreamGetResource(cs,“XObject”,imageLabel)
CGPDFStreamRef xObjectStream
if (CGPDFObjectGetValue(imageObject, kCGPDFObjectTypeStream, &xObjectStream)) {
CGPDFDictionaryRef xObjectDictionary = CGPDFStreamGetDictionary(xObjectStream);
const char *subtype;
CGPDFDictionaryGetName(xObjectDictionary, "Subtype", &subtype);
if (strcmp(subtype, "Image") == 0) {
NSString *imageID = [NSString stringWithCString: imageLabel encoding: NSASCIIStringEncoding];
CGPDFDictionaryApplyFunction(xObjectDictionary, ListDictionaryObjects, NULL);
if(CGPDFDictionaryGetName(xObjectDictionary,“ColorSpace”和ColorSpace名称)){
}否则{
//Getting Color space array
CGPDFArrayRef objectArray;
CGPDFDictionaryGetArray(xObjectDictionary, "ColorSpace", &objectArray);
//getting each array position
CGPDFStreamRef colorsSpaceStream;
CGPDFArrayGetName(objectArray, 0, &colorSpaceName);
fprintf(stdout,"Color Space Name %s\n", colorSpaceName);
CGPDFArrayGetStream(objectArray, 1, &colorsSpaceStream);
CGPDFDictionaryRef dictionary = CGPDFStreamGetDictionary(colorsSpaceStream);
CGPDFDictionaryApplyFunction(dictionary, ListDictionaryObjectsLow, NULL);
}
最后,在ListDictionaryObjects函数中,我介绍了字典对象:
void ListDictionaryObject(常量字符*键,CGPDFObjectRef对象,void*信息){
fprintf(标准输出,“%s:\n”,键)
PDF规范中描述了您看到的内容: 请参阅第8.6.5.5节,该节定义了基于ICC的颜色空间-您要查找的数据包含在粘贴在邮件顶部的流中。由于它是扁平编码(ZIP编码)的,因此不容易识别 问题是你到底想实现什么?如果你只是想扔掉这个基于ICC的颜色空间并创建一个新的,你不需要找到这些数据,只需要创建一个新的颜色空间对象,并使图像引用你的新对象
要更改现有的ICC配置文件(通常这是一个坏主意),您必须解压缩流数据,调整要调整的内容,然后再次重新压缩。指定新的颜色配置文件(即不更改对象中的值)通过使用ColorSync实用程序创建石英过滤器,可以对特定颜色空间的所有对象进行颜色同步 Mac开发者库2005年关于“”的技术说明指出: 石英过滤器目前只能通过各种Mac OS X系统构建的实用程序和应用程序使用。不过,一套新的API即将推出 但我在苹果的开发者文档中找不到其他提到石英过滤器的内容 我知道这不是很有帮助,但也许它给了你一个提示我们应该看看
编辑:请参见以下步骤: 1-使用ColorSync实用程序创建石英过滤器,并将其另存为.qfilter文件 2-使用以下代码将此筛选器应用于pdf文件:
PDFDocument *pdf = [[PDFDocument alloc]initWithURL:[NSURL fileURLWithPath:@"_pdfURL_"]];
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:[QuartzFilter quartzFilterWithURL:[NSURL fileURLWithPath:@"_myFilter.qfilter_"]], @"QuartzFilter", nil];
[pdf writeToFile:@"_pdfFilePath_" withOptions:dict];
谢谢你的回答,这正是我想要做的(扔掉这个基于ICC的颜色空间,创建一个新的)所以,创建新的颜色空间并使图像引用这个新对象是正确的。你能粘贴一些代码作为例子来完成吗?谢谢!这解决了我的问题!我跟随了关于石英过滤器的链接,我能够为pdf文件中的所有图像对象更改基于ICC的颜色空间。谢谢!我发布了我遵循的步骤我们只是为了万一有人需要复制它:
CGPDFObjectType type = CGPDFObjectGetType(object);
switch (type) {
case kCGPDFObjectTypeDictionary: {
CGPDFDictionaryRef objectDictionary;
if (CGPDFObjectGetValue(object, kCGPDFObjectTypeDictionary, &objectDictionary)) {
fprintf(stdout," Dictionary value with: %zd elements\n", CGPDFDictionaryGetCount(objectDictionary));
CGPDFDictionaryApplyFunction(objectDictionary, ListDictionaryObjectsLow, NULL);
}
}
break;
case kCGPDFObjectTypeInteger: {
CGPDFInteger objectInteger;
if (CGPDFObjectGetValue(object, kCGPDFObjectTypeInteger, &objectInteger)) {
fprintf(stdout," integer value: %ld \n", (long int)objectInteger);
}
}
break;
case kCGPDFObjectTypeReal:{
CGPDFReal objectReal;
if (CGPDFObjectGetValue(object, kCGPDFObjectTypeReal, &objectReal)){
fprintf(stdout," real value: %5.2f\n", objectReal);
}
} ...
PDFDocument *pdf = [[PDFDocument alloc]initWithURL:[NSURL fileURLWithPath:@"_pdfURL_"]];
NSDictionary *dict = [[NSDictionary alloc]initWithObjectsAndKeys:[QuartzFilter quartzFilterWithURL:[NSURL fileURLWithPath:@"_myFilter.qfilter_"]], @"QuartzFilter", nil];
[pdf writeToFile:@"_pdfFilePath_" withOptions:dict];