Acrobat C Struct转换为Delphi Record

时间:2018-12-20 15:38:16

标签: delphi

我正在尝试利用Adobe Acrobat OLE来优化和压缩我们通过各种内部程序获取的PDF。 Adobe在所有文档中都使用C,但是在Delphi中将结构转换为记录时遇到了麻烦。

引用SDK here

Adob​​e结构:

struct _t_PDFOptParams{
    ASSize_t size;
    ASPathName asPathDest;
    ASFileSys fileSys;
    ProgressMonitor progMon;
    void* progMonClientData;
    PDFOptPDFVersion enmAcrobatVersion;
    PDFOptImageOptionsRec imageOptionsColor;
    PDFOptImageOptionsRec imageOptionsGrayscale;
    PDFOptImageOptionsRec imageOptionsMonochrome;
    PDFont* arrPDFontsToUnembed;
    ASInt32 cPDFontsToUnembed;
    PDFOptFlattenTransparencyOptions pdfOptFlattenTransparencyOptions;
    ASBool bRemoveFormActions;
    ASBool bFlattenFormFields;
    ASBool bRemoveJavascriptActions;
    ASBool bRemoveAlternateImages;
    ASBool bRemoveThumbnails;
    ASBool bRemoveDocumentTags;
    ASBool bSmoothenLines;
    ASBool bMergeImageFragments;
    ASBool bRemovePrintSettings;
    ASBool bRemoveSrchIndex;
    ASBool bRemoveBookmarks;
    ASBool bRemoveCommentsAndWidgets;
    ASBool bRemoveDocInfoAndMetadata;
    ASBool bRemoveObjectData;
    ASBool bRemoveFileAttachments;
    ASBool bRemoveCrossRefs;
    ASBool bRemovePrivateData;
    ASBool bFlattenVisibleLayers;
    PDFOptObjectCompression enmObjectCompression;
    ASBool bUnencodedToFlate;
    ASBool bLZWToFlate;
    ASBool bRemoveInvalidBookmarks;
    ASBool bRemoveInvalidLinks;
    ASBool bRemoveUnreferencedNamedDests;
    ASBool bLinearize;
}PDFOptParamsRec, *PDFOptParams;

我在Delphi中创建记录的尝试:

 type PDFParams = record
  size                      : byte;
  asPathDest                : string;
  //fileSys                 : ;
  //progMon                 : null
  //progMonClientData       : null
  //enmAcrobatVersion         : PDFOptPDFVersion;
  //imageOptionsColor
  //imageOptionsGrayscale
  //imageOptionsMonochrome
  //arrPDFontsToUnembed
  cPDFontsToUnembed         :Integer;
  //pdfOptFlattenTransparencyOptions
  bRemoveFormactions        : bool;
  bFlattenFormFields        : bool;
  bRemoveJavascriptActions : bool;
  bRemoveAlternateImages   : bool;
  bRemoveThumbnails        : bool;
  bRemoveDocumentTags      : bool;
  bSmoothenLines           : bool;
  bMergeImageFragments     : bool;
  bRemovePrintSettings     : bool;
  bRemoveSrchIndex         : bool;
  bRemoveBookmarks         : bool;
  bRemoveCommentsAndWidgets: bool;
  bRemoveDocInfoAndMetadata: bool;
  bRemoveObjectData        : bool;
  bRemoveFileAttachments   : bool;
  bRemoveCrossRefs         : bool;
  bRemovePrivateData       : bool;
  bFlattenVisibleLayers    : bool;
  //enmObjectCompression     : bool;
  bUnencodedToFlate        : bool;
  bLZWToFlate              : bool;
  bRemoveInvalidBookmarks  : bool;
  bRemoveInvalidLinks      : bool;
  bRemoveUnreferencedNamedDests  : bool;
  bLinearize               : bool;
end;

我不确定将注释掉的字段设置为什么?

1 个答案:

答案 0 :(得分:1)

到目前为止,您所翻译的内容甚至都不是准确的。 ASSize_t不是单个byteASPathName不是stringASBool不是bool,等等。

PDFOptParams结构依赖于许多其他类型。根据PDF,这些类型的定义如下所示:

type
  { define this manually only if your Delphi version does not already provide it }
  size_t = NativeUInt;

  ASSize_t = size_t;

  ASInt32 = Int32;
  ASUns16 = UInt16;
  ASBool = ASUns16;

  ASDuration = ASInt32;
  ASFileMode = ASUns16;
  ASMDFile = Pointer;
  ASErrorCode = ASInt32;

  { the following types are not documented in the PDF, so you need
    to track down what they are actually defined as in the SDK and
    translate them as needed... }

  _t_ASPathNameRec = record
    ...
  end;
  ASPathName = ^_t_ASPathNameRec;

  _t_PDFont = record
    ...
  end;
  PDFont = ^_t_PDFont;

  _t_ASTextRec = record
    ...
  end;
  ASText = ^_t_ASTextRec;

  { I'm not going to translate all of the following callback types,
    I'll leave that as an exercise for you to do. I've done the 1st
    two for you (note: the PDF doesn't describe calling conventions
    used, so if 'cdecl' doesn't work, try 'stdcall' instead)... }

  ASFileSysOpenProc = function(pathName: ASPathName; mode: ASFileMode; var fP: ASMDFile): ASErrorCode; cdecl;
  ASFileSysCloseProc = function(f: ASMDFile): ASErrorCode; cdecl;
  ASFileSysFlushProc = ...;
  ASFileSysSetPosProc = ...;
  ASFileSysGetPosProc = ...;
  ASFileSysSetEofProc = ...;
  ASFileSysGetEofProc = ...;
  ASFileSysReadProc = ...;
  ASFileSysWriteProc = ...;
  ASFileSysRemoveProc = ...;
  ASFileSysRenameProc = ...;
  ASFileSysIsSameFileProc = ...;
  ASFileSysGetNameProc = ...;
  ASFileSysGetTempPathNameProc = ...;
  ASFileSysCopyPathNameProc = ...;
  ASFileSysDiPathFromPathProc = ...;
  ASFileSysPathFromDIPathProc = ...;
  ASFileSysDisposePathNameProc = ...;
  ASFileSysGetFileSysNameProc = ...;
  ASFileSysGetStorageFreeSpaceProc = ...;
  ASFileSysFlushVolumeProc = ...;
  ASFileSysGetFileFlags = ...;
  ASFileSysAsyncReadProc = ...;
  ASFileSysAsyncWriteProc = ...;
  ASFileSysAsyncAbortProc = ...;
  ASFileSysYieldProc = ...;
  ASFileSysMReadRequestProc = ...;
  ASFileSysGetStatusProc = ...;
  ASFileSysCreatePathNameProc = ...;
  ASFileSysAcquireFileSysPathProc = ...;
  ASFileSysClearOutstandingMReadsProc = ...;
  ASFileSysGetItemPropsProc = ...;
  ASFileSysFirstFolderItemProc = ...;
  ASFileSysNextFolderItemProc = ...;
  ASFileSysDestroyFolderIteratorProc = ...;
  ASFileSysSetModeProc = ...;
  ASFileSysURLFromPathProc = ...;
  ASFileSysGetParentProc = ...;
  ASFileSysCreateFolderProc = ...;
  ASFileSysRemoveFolderProc = ...;
  ASFileSysDisplayStringFromPathProc = ...;
  ASFileSysSetTypeAndCreatorProc = ...;
  ASFileSysGetTypeAndCreatorProc = ...;
  ASFileSysReopenProc = ...;
  ASFileSysHardFlushProc = ...;
  ASFileSysGetPlatformThingProc = ...;
  ASFileSysGetItemPropsAsCabProc = ...;
  ASFileSysCanPerformOpOnItemProc = ...;
  ASFileSysPerformOpOnItemProc = ...;
  ASFileSysAcquirePlatformPathProc = ...;
  ASFileSysReleasePlatformPathProc = ...;
  ASFileSysGetNameAsASTextProc = ...;
  ASFileSysDisplayASTextFromPathProc = ...;
  ASFileSysRangeArrivedProc = ...;
  ASFileSysCanSetEofProc = ...;
  ASFileSysDIPathFromPathExProc = ...;
  ASFileSysPathFromDIPathExProc = ...;
  ASFileSysGetFilePositionLimitProc = ...;
  ASFileSysOpen64Proc = ...;
  ASFileSysSetPos64Proc = ...;
  ASFileSysGetPos64Proc = ...;
  ASFileSysSetEof64Proc = ...;
  ASFileSysGetEof64Proc = ...;
  ASFileSysGetNameForDisplayProc = ...;
  ASFileSysGetStorageFreeSpace64Proc = ...;

  _t_ASFileSysRec = record
    size: ASSize_t;
    open: ASFileSysOpenProc;
    close: ASFileSysCloseProc;
    flush: ASFileSysFlushProc;
    setpos: ASFileSysSetPosProc;
    getpos: ASFileSysGetPosProc;
    seteof: ASFileSysSetEofProc;
    geteof: ASFileSysGetEofProc;
    read: ASFileSysReadProc;
    write: ASFileSysWriteProc;
    remove: ASFileSysRemoveProc;
    rename: ASFileSysRenameProc;
    isSameFile: ASFileSysIsSameFileProc;
    getName: ASFileSysGetNameProc;
    getTempPathName: ASFileSysGetTempPathNameProc;
    copyPathName: ASFileSysCopyPathNameProc;
    diPathFromPath: ASFileSysDiPathFromPathProc;
    pathFromDIPath: ASFileSysPathFromDIPathProc;
    disposePathName: ASFileSysDisposePathNameProc;
    getFileSysName: ASFileSysGetFileSysNameProc;
    getStorageFreeSpace: ASFileSysGetStorageFreeSpaceProc;
    flushVolume: ASFileSysFlushVolumeProc;
    getFileFlags: ASFileSysGetFileFlags;
    readAsync: ASFileSysAsyncReadProc;
    writeAsync: ASFileSysAsyncWriteProc;
    abortAsync: ASFileSysAsyncAbortProc;
    yield: ASFileSysYieldProc;
    mreadRequest: ASFileSysMReadRequestProc ;
    getStatus: ASFileSysGetStatusProc;
    createPathName: ASFileSysCreatePathNameProc;
    acquireFileSysPath: ASFileSysAcquireFileSysPathProc;
    clearOutstandingMReads: ASFileSysClearOutstandingMReadsProc;
    getItemProps: ASFileSysGetItemPropsProc;
    firstFolderItem: ASFileSysFirstFolderItemProc;
    nextFolderItem: ASFileSysNextFolderItemProc;
    destroyFolderIterator: ASFileSysDestroyFolderIteratorProc;
    setFileMode: ASFileSysSetModeProc;
    urlFromPath: ASFileSysURLFromPathProc;
    getParent: ASFileSysGetParentProc;
    createFolder: ASFileSysCreateFolderProc;
    removeFolder: ASFileSysRemoveFolderProc;
    displayStringFromPath: ASFileSysDisplayStringFromPathProc;
    setTypeAndCreator: ASFileSysSetTypeAndCreatorProc;
    getTypeAndCreator: ASFileSysGetTypeAndCreatorProc;
    reopen: ASFileSysReopenProc;
    hardFlush: ASFileSysHardFlushProc;
    getPlatformThing: ASFileSysGetPlatformThingProc;
    getItemPropsAsCab: ASFileSysGetItemPropsAsCabProc;
    canPerformOpOnItem: ASFileSysCanPerformOpOnItemProc;
    performOpOnItem: ASFileSysPerformOpOnItemProc;
    acquirePlatformPath: ASFileSysAcquirePlatformPathProc;
    releasePlatformPath: ASFileSysReleasePlatformPathProc;
    getNameAsASText: ASFileSysGetNameAsASTextProc;
    displayASTextFromPath: ASFileSysDisplayASTextFromPathProc;
    rangeArrived: ASFileSysRangeArrivedProc;
    canSetEof: ASFileSysCanSetEofProc;
    diPathFromPathEx: ASFileSysDIPathFromPathExProc;
    pathFromDIPathEx: ASFileSysPathFromDIPathExProc;
    getfileposlimit: ASFileSysGetFilePositionLimitProc;
    open64: ASFileSysOpen64Proc;
    setpos64: ASFileSysSetPos64Proc;
    getpos64: ASFileSysGetPos64Proc;
    seteof64: ASFileSysSetEof64Proc;
    geteof64: ASFileSysGetEof64Proc;
    getNameForDisplay: ASFileSysGetNameForDisplayProc;
    getStorageFreeSpace64: ASFileSysGetStorageFreeSpace64Proc;
  end;
  ASFileSysRec = _t_ASFileSysRec;
  ASFileSys = ^_t_ASFileSysRec;

  PMBeginOperationProc = procedure(clientData: Pointer); cdecl;
  PMEndOperationProc = procedure(clientData: Pointer); cdecl;
  PMSetDurationProc = procedure(duration: ASDuration; clientData: Pointer); cdecl;
  PMSetCurrValueProc = procedure(currValue: ASDuration; clientData: Pointer); cdecl;
  PMGetDurationProc = function(clientData: Pointer): ASDuration; cdecl;
  PMGetCurrValueProc = function(clientData: Pointer): ASDuration;
  PMSetTextProc = procedure(text: ASText; clientData: Pointer); cdecl;

  _t_ProgressMonitor = record
    size: ASSize_t;
    beginOperation: PMBeginOperationProc;
    endOperation: PMEndOperationProc;
    setDuration: PMSetDurationProc;
    setCurrValue: PMSetCurrValueProc;
    getDuration: PMGetDurationProc;
    getCurrValue: PMGetCurrValueProc;
    setText: PMSetTextProc;
  end;
  ASProgressMonitorRec = _t_ProgressMonitor;
  ASProgressMonitor = ^_t_ProgressMonitor;
  ProgressMonitor = ASProgressMonitor;

  PDFOptPDFVersion = (kPDFOptRetainVersion = 0, kPDFOptAcrobat4, kPDFOptAcrobat5, kPDFOptAcrobat6, kPDFOptAcrobat7, kPDFOptAcrobat8);
  PDFOptDownsamplingAlgo = (kPDFOptNoDownsampling = 0, kPDFOptAverage, kPDFOptSubsampling, kPDFOptBicubic);
  PDFOptCompressionAlgo = (kPDFOptNoRecompression = 0, kPDFOptJpeg2000, kPDFOptJpeg, kPDFOptFlate, kPDFOptJBIG2, kPDFOptCCITT3, kPDFOptCCITT4, kPDFOptRunLengh);
  PDFOptCompressionQlty = (kPDFOptMinimumQlty = 0, kPDFOptLowQlty, kPDFOptMediumQlty, kPDFOptHighQlty, kPDFOptMaximumQlty, kPDFOptLossless);

  _t_PDFOptImageOptions = record
    size: ASSize_t;
    enmDownsamplingAlgo: PDFOptDownsamplingAlgo;
    ppiDownsampleTo: ASInt32;
    ppiDownsampleAbove: ASInt32;
    enmCompressionAlgo: PDFOptCompressionAlgo;
    enmCompressionQlty: PDFOptCompressionQlty;
    nTileSize: ASInt32;
  end;
  PDFOptImageOptionsRec = _t_PDFOptImageOptions;
  PDFOptImageOptions = ^_t_PDFOptImageOptions;

  _t_PDFOptFlattenTransparencyOptions = record
    size: ASSize_t;
    pctRasterVectorBalance,
    ppiLineArtAndText,
    ppiGradientAndMesh: ASInt32;
    bConvertText,
    bConvertStrokes,
    bClipComplexRegions,
    bPreserveOverprint: ASBool;
  end;
  PDFOptFlattenTransparencyOptionsRec = _t_PDFOptFlattenTransparencyOptions;
  PDFOptFlattenTransparencyOptions = ^_t_PDFOptFlattenTransparencyOptions;

  PDFOptObjectCompression = (kPDFOptUntouchedCompression = 0, kPDFOptFullCompression, kPDFOptPartialCompression, kPDFOptRemoveCompression);

  _t_PDFOptParams = record
    size: ASSize_t;
    asPathDest: ASPathName;
    fileSys: ASFileSys;
    progMon: ProgressMonitor;
    progMonClientData: Pointer;
    enmAcrobatVersion: PDFOptPDFVersion;
    imageOptionsColor,
    imageOptionsGrayscale,
    imageOptionsMonochrome: PDFOptImageOptionsRec;
    arrPDFontsToUnembed: ^PDFont;
    cPDFontsToUnembed: ASInt32;
    pdfOptFlattenTransparencyOptions: PDFOptFlattenTransparencyOptions;
    bRemoveFormActions,
    bFlattenFormFields,
    bRemoveJavascriptActions,
    bRemoveAlternateImages,
    bRemoveThumbnails,
    bRemoveDocumentTags,
    bSmoothenLines,
    bMergeImageFragments,
    bRemovePrintSettings,
    bRemoveSrchIndex,
    bRemoveBookmarks,
    bRemoveCommentsAndWidgets,
    bRemoveDocInfoAndMetadata,
    bRemoveObjectData,
    bRemoveFileAttachments,
    bRemoveCrossRefs,
    bRemovePrivateData,
    bFlattenVisibleLayers: ASBool;
    enmObjectCompression: PDFOptObjectCompression;
    bUnencodedToFlate,
    bLZWToFlate,
    bRemoveInvalidBookmarks,
    bRemoveInvalidLinks,
    bRemoveUnreferencedNamedDests,
    bLinearize: ASBool;
  end;
  PDFOptParamsRec = _t_PDFOptParams;
  PDFOptParams = ^_t_PDFOptParams;