Class CPDFDocument

java.lang.Object
com.compdfkit.core.document.CPDFDocument

public class CPDFDocument extends Object
Document instance. One CPDFDocument object for one document. This class is used to represent a specified directory, which contains PDF files and user wants to search among these PDF files.
  • Constructor Details

    • CPDFDocument

      public CPDFDocument()
      Creates PDF document
  • Method Details

    • createDocument

      public static CPDFDocument createDocument()
      Creates a CPDFDocument object with new PDF.
      Returns:
      Document object.
    • setDocPtr

      public void setDocPtr(long docPtr)
    • isValid

      public boolean isValid()
      Whether CPDFDocument object is valid, false means CPDFDocument object is released.
      Returns:
      Returns whether CPDFDocument object is valid.
    • shouleReloadDocument

      public boolean shouleReloadDocument()
      Whether to reload document, true means it needs to call to reload document.
      Returns:
      Returns whether to reload document.
    • open

      public CPDFDocument.PDFDocumentError open(String absolutePath)
      Loads the document
      Parameters:
      absolutePath - Absolute path of document.
      Returns:
      Returns the error type when loading document.
    • open

      public CPDFDocument.PDFDocumentError open(String absolutePath, String password)
      Loads the encrypted document.
      Parameters:
      absolutePath - Absolute path of document.
      password - Document password.
      Returns:
      Returns the error type when loading document.
    • openWithStream

      public CPDFDocument.PDFDocumentError openWithStream(InputStream stream, String password)
    • getPassword

      public String getPassword()
      Gets document password.
      Returns:
      Returns document password.
    • isEncrypted

      public boolean isEncrypted()
      Whether document is encrypted.
      Returns:
      Returns whether document is encrypted.
    • isLocked

      public boolean isLocked()
      Whether the document is locked.
      Returns:
      Returns whether the document is locked.
    • getInfo

      public CPDFInfo getInfo()
      Gets document information, more:CPDFInfo
      Returns:
      Returns document information.
    • setInfo

      public boolean setInfo(CPDFInfo info)
      Sets document information, more:CPDFInfo
      Returns:
      Returns true on success, false on failure.
    • getMajorVersion

      public int getMajorVersion()
      Gets major version string of document.
      Returns:
      Returns major version string of document.
    • getMinorVersion

      public int getMinorVersion()
      Gets minor version string of document.
      Returns:
      Returns minor version string of document.
    • getReVersion

      public int getReVersion()
      Gets revision string of document.
      Returns:
      Returns revision string of document.
    • getBuildTag

      public String getBuildTag()
      Gets build tag string of document.
      Returns:
      Returns build tag string of document.
    • getPermissions

      public CPDFDocument.PDFDocumentPermissions getPermissions()
      Gets permission status of document, more:CPDFDocument.PDFDocumentPermissions.
      Returns:
      Returns permission status of document.
    • getPermissionsInfo

      public CPDFDocumentPermissionInfo getPermissionsInfo()
      Gets permission information of document, more:CPDFDocumentPermissionInfo
      Returns:
      Returns permissions of document.
    • setPermissionsInfo

      public boolean setPermissionsInfo(CPDFDocumentPermissionInfo info)
      Sets permission information of document, more:CPDFDocumentPermissionInfo.
      Parameters:
      info - Permission information.
      Returns:
      Returns whether to successfully set document permission.
    • getPageCount

      public int getPageCount()
      Gets total count of document pages.
      Returns:
      Returns total count of document pages.
    • setUserPassword

      public boolean setUserPassword(String password)
      Sets user password.
      Parameters:
      password - Password string.
      Returns:
      Returns whether to successfully set user password.
    • setOwnerPassword

      public boolean setOwnerPassword(String password)
      Not in use currently
    • checkOwnerPassword

      public boolean checkOwnerPassword(String password)
    • importAnnotations

      public boolean importAnnotations(String importFilePath, String tmpCachePath)
      Import annotations from XFDF document.
      Parameters:
      importFilePath - Path of XFDF.
      tmpCachePath - Cache path.
      Returns:
      Returns whether to successfully import annotations from XFDF document.
    • importAnnotations

      public boolean importAnnotations(String importXPDFPath)
      Import annotations from XFDF document.
      Parameters:
      importXPDFPath - Path of XFDF.
      Returns:
      Returns whether to successfully import annotations from XFDF document.
    • exportAnnotations

      public boolean exportAnnotations(String exportXPDFPath, String tmpCacheDirPath)
      Exports annotations to XFDF document.
      Parameters:
      exportXPDFPath - XFDF path.
      tmpCacheDirPath - Cache dir path.
      Returns:
      Returns whether to successfully export annotations to XFDF document.
    • getPageSize

      public RectF getPageSize(int pageNum)
      Gets page size at the specified index.
      Parameters:
      pageNum - Page index.
      Returns:
      Returns page size at the specified index.
    • getPageLabel

      public String getPageLabel(int pageNum)
      Gets the page label at the specified index.
      Parameters:
      pageNum - Page index.
      Returns:
      Returns the page label at the specified index.
    • pageAtIndex

      public CPDFPage pageAtIndex(int pageNum)
      Returns a pageNum object representing the page at index, more: CPDFPage.
      Parameters:
      pageNum - Page index.
      Returns:
      Returns a pageNum object representing the page at index.
    • copyPage

      public CPDFPage copyPage(int pageNum)
      Copy the page at page index
      Parameters:
      pageNum - Page Index
      Returns:
      Returns a page object at index
    • addPage

      public boolean addPage(CPDFPage page, int pageNum)
      Add page to document
      Parameters:
      page - Page object to add to document.
      pageNum - Position to add to.
      Returns:
      Returns whether add is suceess.
    • insertBlankPage

      public CPDFPage insertBlankPage(int pageIndex, float width, float height)
      Inserts a blank page at the specified index point.
      Parameters:
      pageIndex - Page index.
      width - Page width.
      height - Page height.
      Returns:
      Returns the inserted blank page.
    • insertPageWithImagePath

      public CPDFPage insertPageWithImagePath(int pageNum, float width, float height, String imagePath, CPDFDocument.PDFDocumentImageMode imageMode)
      Inserts a blank page with image at the specified index point.
      Parameters:
      pageNum - Page.
      width - Page width.
      height - Page height.
      imagePath - File path of image resource.
      imageMode - Fill mode.
      Returns:
      Returns the inserted image page.
    • importPages

      public boolean importPages(CPDFDocument otherDocument, int start, int end, int insertPosition)
      Import page(s) from another document at the specified index point and insert to insertPosition.
      Parameters:
      otherDocument - Other document.
      start - Start page index.
      end - End page index.
      insertPosition - Insert position.
      Returns:
      Returns whether to successfully import page(s).
    • importPages

      public boolean importPages(CPDFDocument otherDocument, int[] pages, int insertPosition)
      Import page(s) from another document at the specified index point and insert to insertPosition.
      Parameters:
      otherDocument - Other document.
      pages - Page index array.
      insertPosition - Insert position.
      Returns:
      Returns whether to successfully import page(s).
    • removePages

      public boolean removePages(int[] pageNums)
      Remove page(s).
      Parameters:
      pageNums - Page index array.
      Returns:
      Returns whether to successfully remove page(s).
    • movePage

      public boolean movePage(int fromIndex, int toIndex)
      Moves page.
      Parameters:
      fromIndex - Source page index.
      toIndex - Destination page index.
      Returns:
      Returns whether to successfully move page.
    • exchangePage

      public boolean exchangePage(int firstIndex, int secondIndex)
      Exchanges one page with another.
      Parameters:
      firstIndex - The first page index.
      secondIndex - The second page index.
      Returns:
      Returns whether to successfully exchange page.
    • indexOfPage

      public int indexOfPage(CPDFPage page)
      Gets the index number for the specified page.
      Parameters:
      page - Page object.
      Returns:
      Returns the index number for the specified page.
    • releaseAllPages

      public void releaseAllPages()
      When CPDFPage is no longer in use, release all resource of CPDFPage.
    • releaseAllWatermarks

      public void releaseAllWatermarks()
    • close

      public void close()
      When the object is no longer in use, call this method to release resources.
    • hasChanges

      public boolean hasChanges()
      Whether document is modified.
      Returns:
      Returns whether document is modified.
    • canSaveIncrementally

      public boolean canSaveIncrementally()
      Whether document can be saved incrementally.
      Returns:
      Returns whether document can be saved incrementally.
    • hasRepaired

      public boolean hasRepaired()
      Whether document is repaired.
      Returns:
      Returns whether document is repaired.
    • flattenAllPages

      public boolean flattenAllPages(CPDFPage.PDFFlattenOption flattenOption)
      Flatten all pages.
      Parameters:
      flattenOption - flatten type, more: CPDFPage.PDFFlattenOption
      Returns:
      Returns whether to successfully flatten all pages.
    • saveForceByNoincremental

      public boolean saveForceByNoincremental()
      Mandatory saving, the principle is to use non-incremental saving as a document to copy the current document
    • save

      public boolean save(String absolutePath, CPDFDocument.PDFDocumentSaveType saveType)
      The doucment has changes, sava file.
    • getDocPtr

      public long getDocPtr()
    • save

      public boolean save(CPDFDocument.PDFDocumentSaveType saveType)
      The doucment has changes, sava file.
    • getFilePath

      public String getFilePath()
      document absolute path
    • getWatermarkCount

      public int getWatermarkCount()
    • getWatermark

      public CPDFWatermark getWatermark(int index)
      getWatermark
      Parameters:
      index - index
      Returns:
      CPDFWatermark
    • createWatermark

      public CPDFWatermark createWatermark(CPDFWatermark.Type type)
      createWatermark
      Parameters:
      type - CPDFWatermark.Type
      Returns:
      CPDFWatermark
    • createCompare

      public CPDFCompare createCompare(CPDFDocument baseDoc, CPDFDocument compDoc)
    • createCompare

      public CPDFCompare createCompare(CPDFDocument compDoc)
    • createCompareDrawings

      public CPDFCompareDrawings createCompareDrawings(CPDFDocument compDoc)
    • removeSignature

      public boolean removeSignature(CPDFSignature signature, CPDFDocument document, boolean isRemoveAP)
      Delete signature
      Parameters:
      signature - CPDFSignature
      document - CPDFDocument
      isRemoveAP - isRemove
      Returns:
      boolean
    • removeAllSignStamps

      public boolean removeAllSignStamps(CPDFDocument document, boolean isRemoveAP)
      Remove all signatures
      Parameters:
      document - CPDFDocument
      isRemoveAP - isRemove
      Returns:
      boolean
    • getSignatureCount

      public int getSignatureCount()
      Get the total number of signatures in the document.
      Returns:
      Total number of signatures.
    • getPdfSignature

      public CPDFSignature getPdfSignature(int index)
      Get the signature of the specified index in the document.
      Parameters:
      index - index
      Returns:
      CPDFSignature
    • writeSignature

      public boolean writeSignature(CPDFSignatureWidget signatureWidget, String savePath, String pkcs12certPath, String password, String location, String reason, CPDFDocument.PDFDocMdpP type)
      Add a signature to document.
      Parameters:
      signatureWidget - Signature widget.
      savePath - Save path for the signature file.
      pkcs12certPath - Pkcs12 certificate file path.
      password - Pkcs12 certificate file password
      location - The CPU host name or physical location of the signing.
      reason - Signature reason.
      type - Modify permission type. more:CPDFDocument.PDFDocMdpP
      Returns:
      Returns true:write signature succeed, false:fail.
    • exportWidgets

      public boolean exportWidgets(String exportFilePath, String tmpCachePath)
      以xfdf文件格式导出当前文档的表单数据
      Parameters:
      exportFilePath - xfdf的路径
      tmpCachePath - 文件的中转路径,该路径一定要具有权限
      Returns:
      是否成功导出表单数据
    • importWidgets

      public boolean importWidgets(String importFilePath, String cachePath)
      导入表单数据
      Parameters:
      importFilePath -
      cachePath -
      Returns:
      是否成功导入表单数据
    • exportCustomWidgets

      public boolean exportCustomWidgets(String exportFilePath, String tmpCachePath, String[] fieldNames)
      以xfdf文件格式导出当前文档的所有自定义表单
      Parameters:
      exportFilePath - xfdf的路径
      tmpCachePath - 文件的中转路径,该路径一定要具有权限
      Returns:
      是否成功导出表单
    • importCustomWidgets

      public boolean importCustomWidgets(String importFilePath, String tmpCachePath)
      通过xfdf文件导入自定义表单到当前文档
      Parameters:
      importFilePath - xfdf的路径
      tmpCachePath - 文件的中转路径,该路径一定要具有权限
      Returns:
      是否成功导入表单
    • addTable

      public boolean addTable(int pageIndex, int tableWidth, int tableHeight, int positionx, int positiony, int rows, int cols, String[] textArr, PointI[] textPosArr, String[] imageArr, PointI[] imagePosArr)