Copy link to clipboard
Copied
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");
}
Search the SDK and this forum for the recent change of the macOS version from HFS to Posix paths.
Copy link to clipboard
Copied
Is there a specific reason why you need to do it as a plug-in - instead of a script?
Copy link to clipboard
Copied
Search the SDK and this forum for the recent change of the macOS version from HFS to Posix paths.
Copy link to clipboard
Copied
Copy link to clipboard
Copied
The issue was indeed related to file paths using HFS instead of the POSIX path style. I confirmed this by temporarily removing the cookie file named 'ENABLE_POSIX_PATH'. I have since updated the plug-in code, and it is now functioning as expected. Thank you very much for pointing me in the right direction.