1

我正在尝试阅读 PDF 的页面大小,例如. height X weight. 页面大小可以在

File -> Properties -> Page Size

我使用下面的代码来获取属性值:

$path = FileOpenDialog("Select a file to read attributes",@ScriptDir,"All (*.*)")
$prop = _GetExtProperty($path,-1)
_ArrayDisplay($prop,"Property Array")

Func _GetExtProperty($sPath, $iProp)
    Local $iExist, $sFile, $sDir, $oShellApp, $oDir, $oFile, $aProperty, $sProperty
    $iExist = FileExists($sPath)
    If $iExist = 0 Then
        SetError(1)
        Return 0
    Else
        $sFile = StringTrimLeft($sPath, StringInStr($sPath, "\", 0, -1))
        $sDir = StringTrimRight($sPath, (StringLen($sPath) - StringInStr($sPath, "\", 0, -1)))
        $oShellApp = ObjCreate ("shell.application")
        $oDir = $oShellApp.NameSpace ($sDir)
        $oFile = $oDir.Parsename ($sFile)
        If $iProp = -1 Then
            Local $aProperty[35]
            For $i = 0 To 34
                $aProperty[$i] = $oDir.GetDetailsOf ($oFile, $i)
            Next
            Return $aProperty
        Else
            $sProperty = $oDir.GetDetailsOf ($oFile, $iProp)
            If $sProperty = "" Then
                Return 0
            Else
                Return $sProperty
            EndIf
        EndIf
    EndIf
EndFunc   ;==>_GetExtProperty

通过使用上面的代码,我设法获得了以 MB 为单位的文件大小、创建日期、修改日期、位置等,但不是页面大小。感激,如果有人可以建议我如何获得页面大小。非常感谢任何参考、建议或示例代码。

4

1 回答 1

1

几乎相同,但也许有帮助。

       #include <Array.au3>
;===============================================================================
; Function Name.....: _FileGetProperty
; Description.......: Returns a property or all properties for a file.
; Version...........: 1.0.2
; Change Date.......: 2008-07-28
; AutoIt Version....: 3.2.12.1
;
; Parameter(s)......: $S_PATH - String containing the file path to return the property from.
;                     $S_PROPERTY - [optional] String containing the name of the property to return. (default = "")
; Requirements(s)...: None
; Return Value(s)...: Success: Returns a string containing the property value.
;                       If $S_PROPERTY is empty, an two-dimensional array is returned:
;                         $av_array[0][0] = Number of properties.
;                         $av_array[1][0] = 1st property name.
;                         $as_array[1][1] = 1st property value.
;                         $av_array[n][0] = nth property name.
;                         $as_array[n][1] = nth property value.
;                     Failure: Returns 0 and sets @error to:
;                       1 = The folder $S_PATH does not exist.
;                       2 = The property $S_PROPERTY does not exist or the array could not be created.
;                       3 = Unable to create the "Shell.Application" object $objShell.
;
; Author(s).........: - Simucal <Simucal@gmail.com>
;                     - Modified by: Sean Hart <autoit@hartmail.ca>
;                     - Modified by: teh_hahn <sPiTsHiT@gmx.de>
; Company...........: None
; URL...............: None
; Note(s)...........: None
;===============================================================================

Global $re = _FileGetProperty(@ScriptDir & '\1Tutorial - AutoItWiki1.pdf')
If @error Then MsgBox(16, 'ERROR', 'Error: ' & @error & @CRLF & '1 = The folder $S_PATH does not exist.' & @CRLF & _
        '2 = The property $S_PROPERTY does not exist or the array could not be created.' & @CRLF & _
        '3 = Unable to create the "Shell.Application" object $objShell.')
_ArrayDisplay($re)

Func _FileGetProperty(Const $S_PATH, Const $S_PROPERTY = "")
    If Not FileExists($S_PATH) Then Return SetError(1, 0, 0)

    Local Const $S_FILE = StringTrimLeft($S_PATH, StringInStr($S_PATH, "\", 0, -1))
    Local Const $S_DIR = StringTrimRight($S_PATH, StringLen($S_FILE) + 1)

    Local Const $objShell = ObjCreate("Shell.Application")
    If @error Then Return SetError(3, 0, 0)

    Local Const $objFolder = $objShell.NameSpace($S_DIR)
    Local Const $objFolderItem = $objFolder.Parsename($S_FILE)

    If $S_PROPERTY Then
        For $i = 0 To 99
            If $objFolder.GetDetailsOf($objFolder.Items, $i) = $S_PROPERTY Then Return $objFolder.GetDetailsOf($objFolderItem, $i)
        Next
        Return SetError(2, 0, 0)
    EndIf

    Local $av_ret[1][2] = [[1]]
    For $i = 0 To 99
        If $objFolder.GetDetailsOf($objFolder.Items, $i) Then
            ReDim $av_ret[$av_ret[0][0] + 1][2]
            $av_ret[$av_ret[0][0]][0] = $objFolder.GetDetailsOf($objFolder.Items, $i)
            $av_ret[$av_ret[0][0]][1] = $objFolder.GetDetailsOf($objFolderItem, $i)
            $av_ret[0][0] += 1
        EndIf
    Next

    If Not $av_ret[1][0] Then Return SetError(2, 0, 0)
    $av_ret[0][0] -= 1

    Return $av_ret
EndFunc   ;==>_FileGetProperty
于 2013-10-30T08:25:17.737 回答