PDF ファイルの画像オブジェクトの色空間を変更しようとしていますが、最初の問題は、PDF メタデータ内に ICC カラー プロファイルが見つからないことです。
メタデータにあるのは、2 つのコンポーネントを持つ 1 つの配列だけです。
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, pageNumber);
CGPDFContentStreamRef contentStream =
CGPDFContentStreamCreateWithPage(ページ); CGPDFOperatorTableRef
operatorTable = CGPDFOperatorTableCreate();
CGPDFOperatorTableSetCallback(operatorTable, "Do", &op_Do);
CGPDFScannerRef contentStreamScanner =
CGPDFScannerCreate(contentStream, operatorTable, NULL);
CGPDFScannerScan(contentStreamScanner);
....
そして、コールバックで:
static 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", &colorSpaceName)){
fprintf(stdout,"Color Space Name %s\n", colorSpaceName);
}そうしないと{
//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 ListDictionaryObjects (const char *key, CGPDFObjectRef object, void *info) { fprintf(stdout, "%s :\n", key);
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); } } ...