Answered
Assistance Needed: Troubleshooting Adobe InDesign Plug-in to export PDF on macOS
Hello Team,
I am currently working on an Adobe InDesign plug-in designed to export PDFs to a specified location. Below are the details of my setup:
InDesign SDK Version: plugin_sdk_19.3.0.58.zip
macOS Version: Sonoma 14.7.2
InDesign Version: 19.5.1
The code functions as expected on Windows, successfully creating a PDF in the same directory as the InDesign file. However, on macOS, I encounter the error "Command processing failed," and no PDF is generated.
I have confirmed that folder permissions are not the issue, as I can save InDesign files to the same location without any problems.
Could you please provide guidance on how to troubleshoot this issue further? Any insights or suggestions would be greatly appreciated.
ErrorCode status = kFailure;
UIFlags uiFlags = kSuppressUI;
InterfacePtr<ICommand> pdfExportCmd(CmdUtils::CreateCommand(kPDFExportCmdBoss));
if (!pdfExportCmd) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to create PDF export command");
return status;
}
// set export prefs on the command by copying from the workspace export prefs.
InterfacePtr<IPDFExportPrefs> pdfExportPrefs(pdfExportCmd, UseDefaultIID());
InterfacePtr<IPDFExportPrefs> appExportPrefs((IPDFExportPrefs*)::QuerySessionPreferences(IID_IPDFEXPORTPREFS));
if (!pdfExportPrefs || !appExportPrefs) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to retrieve export preferences");
return status;
}
pdfExportPrefs->CopyPrefs(appExportPrefs);
// set ISysFileData to point to the output file.
InterfacePtr<ISysFileData> trgSysFileData(pdfExportCmd, IID_ISYSFILEDATA);
if (!trgSysFileData) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to set output file data");
return status;
}
trgSysFileData->Set(fileToExport);
// set security prefs on the command by copying from the workspace security prefs.
InterfacePtr<IPDFSecurityPrefs> securityPrefs(pdfExportCmd, UseDefaultIID());
InterfacePtr<IPDFSecurityPrefs> appSecurityPrefs((IPDFSecurityPrefs*)::QuerySessionPreferences(IID_IPDFSECURITYPREFS));
if (!securityPrefs || !appSecurityPrefs) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to retrieve security preferences");
return status;
}
securityPrefs->CopyPrefs(appSecurityPrefs);
// set print content prefs, if needed. We are doing nothing here.
InterfacePtr<IPrintContentPrefs> printContentPrefs(pdfExportCmd, IID_IPRINTCONTENTPREFS);
// set to true if outputting a book file
InterfacePtr<IBoolData> bookExport(pdfExportCmd, IID_IBOOKEXPORT);
if (!bookExport) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to set book export flag");
return status;
}
bookExport->Set(kFalse);
// set UI flags, kFullUI, kMinimalUI, or kSuppressUI
InterfacePtr<IUIFlagData> uiFlagData(pdfExportCmd, IID_IUIFLAGDATA);
if (!uiFlagData) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to set UI flags");
return status;
}
uiFlagData->Set(uiFlags);
// set up the scope of export (pages)
UIDList pageItemList(pagesUIDList);
pdfExportCmd->SetItemList(pageItemList);
InterfacePtr<IOutputPages> outputPages(pdfExportCmd, UseDefaultIID());
if (!outputPages) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to initialize output pages");
return status;
}
outputPages->Clear();
IDataBase* db = pageItemList.GetDataBase();
if (!db) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to get database from page item list");
return status;
}
outputPages->SetMasterDataBase(db);
bool16 isExportingSpreads = (pdfExportPrefs->GetPDFExReaderSpreads() == IPDFExportPrefs::kExportReaderSpreadsON);
// Initialize output pages with the given page list and spread setting
outputPages->InitializeFrom(pageItemList, isExportingSpreads); // for spreads
int32 nProgressItems = pageItemList.Length();
// set PDF document name (get name from IDocument)
InterfacePtr<IDocument> doc ((IDocument*)db->QueryInstance(db->GetRootUID(), IID_IDOCUMENT));
if (!doc) {
LOG_ERROR(LayerSetLogger::getLogger(), "Failed to get document instance");
return status;
}
PMString documentName;
doc->GetName(documentName);
outputPages->SetName(documentName);
// setup progress bar, if not suppressing the UI.
K2::scoped_ptr<RangeProgressBar> deleteProgressBar;
bool16 bShowImmediate = kTrue;
if(uiFlags != kSuppressUI)
{
RangeProgressBar *progress = new RangeProgressBar( "Generating PDF", 0, nProgressItems, bShowImmediate, kTrue, nil, kTrue);
pdfExportPrefs->SetProgress(progress);
deleteProgressBar.reset(progress);
}
// finally process command
status = CmdUtils::ProcessCommand(pdfExportCmd);
if (status != kSuccess) {
LOG_ERROR(LayerSetLogger::getLogger(), "Command processing failed");
} else {
LOG_ERROR(LayerSetLogger::getLogger(), "Command processed successfully");
}
