• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Exporting embedded images from InDesign

Community Beginner ,
Sep 20, 2011 Sep 20, 2011

Copy link to clipboard

Copied

[Apologies for cross-posting. I mistakenly posted in the InDesign SDK earlier, where it didn't get a lot of views or helpful responses. I couldn't find a way to move the post.]

I am looking for a way to programatically export embedded images from InDesign documents. These images are not linked files are a placed image would normally be. Instead, they seem to be completely embedded within the InDesign file; exporting as IDML causes the raw image data to be exported within XML itself. The itemLink property is null for the Image object.

Searching in the scripting reference leads to the Image.exportForWeb and Image.exportFile methods. However, when I tried the exportForWeb function, it failed silently and returned null.

The exportFile method worked but it takes as input the export format. Since the format of the original image is not available within the script, using exportFile will entail a potentially lossy conversion. (Checking for the imageTypeName for the Image object throws a "The property is not applicable in the current state" error.) Also, the exported file generated with exportFile seems to be limited to 20kb regardless of how large the original image is.

One suggestion on the old post was to try Link.unembed. However, the Image.itemLink property is itself null so unembedding doesn't seem to be possible that way.

Is there a better way to go about exporting these images? Any ideas why exportForWeb won't work. Thank you.

TOPICS
Scripting

Views

2.6K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 20, 2011 Sep 20, 2011

Copy link to clipboard

Copied

Interesting problem. I toyed a bit around and found out that I was unable to export embedded images as jpg, but png worked.  PNG is lossless and I could export files of several megabyte.
The original file format of the image did not seem to matter. Maybe InDesign treats all embedded images as png?

var myImage = app.activeDocument.allGraphics[0];

var myFile = new File("~/Desktop/test_image.png");

myImage.exportFile("png", myFile);

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

ILinkObject provides access to the link object, which can be used to access the
linked graphic resource. If the link is embedded, IStoreInternal provides access to kPMPersist-
DataBlobBoss, which stores the bitmap of the image.

 

// 페이지 항목이 그래픽 프레임인지 확인
InterfacePtr<IGraphicFrameData> graphicFrameData(pageItemRef, IID_IGRAPHICFRAMEDATA);
if (graphicFrameData) {
// ILinkObject를 사용하여 임베디드 리소스 접근
InterfacePtr<ILinkObject> linkObject(graphicFrameData, IID_ILINKOBJECT);
if (linkObject) {
// IStoreInternal을 쿼리하여 kPMPersistDataBlobBoss에 접근
InterfacePtr<IStoreInternal> storeInternal(linkObject, IID_ISTOREINTERNAL);
if (storeInternal) {
// 데이터 블롭을 읽기 위해 스트림 열기
InterfacePtr<IPMStream> blobStream(storeInternal->GetStreamForReading());
if (blobStream) {
// 파일 저장 경로 설정
PMString filePath = "/path/to/save/embedded_image.jpg"; // 실제 경로로 수정
 
// Blob 데이터를 파일에 저장
std::ofstream outputFile(filePath.GetPlatformString().c_str(), std::ios::binary);
if (outputFile) {
int32 bufferSize = 1024;
char buffer[1024];
int32 bytesRead = 0;
 
while ((bytesRead = blobStream->XferByte(buffer, bufferSize)) > 0) {
outputFile.write(buffer, bytesRead);
}
outputFile.close();
 
TdpsLog::logging("SaveImage", "Saved embedded image to %s", filePath.GetPlatformString().c_str());
}
}
}
}
}

 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

LATEST
// 페이지 항목이 그래픽 프레임인지 확인
InterfacePtr<IGraphicFrameData> graphicFrameData(pageItemRef, IID_IGRAPHICFRAMEDATA);
if (graphicFrameData) {
// ILinkObject를 사용하여 임베디드 리소스 접근
InterfacePtr<ILinkObject> linkObject(graphicFrameData, IID_ILINKOBJECT);
if (linkObject) {
// IStoreInternal을 쿼리하여 kPMPersistDataBlobBoss에 접근
InterfacePtr<IStoreInternal> storeInternal(linkObject, IID_ISTOREINTERNAL);
if (storeInternal) {
 
// 파일 저장 경로 설정
PMString filePath = PMString("c:/wepnp/log/embedded_image_", PMString::kUnknownEncoding);
filePath.AppendNumber(itemIdx);
filePath.Append(PMString(".jpg", PMString::kUnknownEncoding));
 
// 데이터를 읽기 위해 스트림 생성
IDFile inFile(filePath);
InterfacePtr<IPMStream> blobStream(StreamUtil::CreateFileStreamRead(inFile, kOpenIn));
 
// ImplementationID는 객체의 구현 ID로, 보통 kDefaultIID를 사용함
if (blobStream) {
storeInternal->ReadWrite(blobStream, kPMPersistDataBlobBoss);
TdpsLog::logging("SaveImage", "Saved embedded image to %s", filePath.GetPlatformString().c_str());
}
}
}
}

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Nov 04, 2024 Nov 04, 2024

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines