IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

PureBasic Discussion :

Utilisation de la DLL GS32DLL.Dll


Sujet :

PureBasic

  1. #1
    Membre à l'essai
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 38
    Points : 23
    Points
    23
    Par défaut Utilisation de la DLL GS32DLL.Dll
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    ;--- 00 Info
    ;
    ; Accessing the ghostscript (gs) api from PureBasic, 21. July 2004 by Max.
    ;
    ; Ghostscript API: http://www.cs.wisc.edu/~ghost/doc/cvs/API.htm
    ; Examples:        http://www.cs.wisc.edu/~ghost/doc/gsapi.htm
    ; PureBasic Forum: http://forum.purebasic.com
    ; GNU Ghostscript 7.06 downloadable at:
    ;                  http://prdownloads.sourceforge.net/ghostscript/gs706w32.exe?download
    ; GPL Licensing:   http://www.gnu.org/copyleft/gpl.html
    ;
    ; Goal was to evaluate if it is possible (and suitable) to create PDF files from PS input
    ; without the need of a seperate ghostscript installation, meaning:
    ; - all needed files, own program as ghostscript, should be packaged into one installer
    ; - no messing with existing gs installations
    ; - no access of registry required, so easy installation and even more easy deinstallation
    ;
    ; Not checked yet:
    ; - minimum requirement of ghostscript files (i.e. unneeded files)
    ; - passing PS input from StdIn directly to the gs api without a seperate input ps file
    ; - using the graphical rendering abilities of gs to create PDF output on the display
    ; - converting other file types
    ;
    ; Installation:
    ; - Copy and paste this code to PureBasic
    ; - Create a fitting directory structure and define the variables according to it
    ;   I am using:
    ;   Z:\PDFGS (for the main program, the gs DLL and the test input file
    ;   Z:\PDFGS\GS (fonts and libs)
    ; - Save the PB file
    ; - Download and install GS 7.06 to the standard paths
    ; - Copy all files from :\gs\fonts, :\gs\gs.706\lib and the dll gsdll32.dll (:\gs\gs.706\bin)
    ;   to your PB source directory
    ; - Rename the original gs installation directory, so it doesn't interfere.
    ;
    ; Good luck!
     
    ;--- 01 Program directory, defined for convenience                           
    Path.s = "C:pdf_ghost"
    ;--- 02 Defining the structure and variable the function gsapi_revision requires
    Structure TGS_Revision
      strProduct.l
      strCopyright.l
      intRevision.l
      intRevisionDate.l
    EndStructure
     
    GS_Revision.TGS_Revision
     
    ;--- 03 Other ghostscript variables
    intGSInstanceHandle.l
    callerHandle.l
     
    ;--- 04 Array that will hold the pointers to the parameters for the ghostscript call
    Global Dim gsargv(10)
     
    ;--- 05 Passing the locations of the fonts, the libs and the gsdll32.dll as environment variable
    ;    without this step, the ghostscript paths are sought in the registry, messing with a regular
    ;    installation.
    SetEnvironmentVariable("GS_LIB",Path.s)
    Debug GetEnvironmentVariable("GS_LIB")
     
    SetEnvironmentVariable("GS_DLL",Path.s+"\gs\gsdll32.dll")
     
    Debug GetEnvironmentVariable("GS_DLL")
    ;--- 06 Opening the DLL
     
    Debug path 
    OpenGSDLL=OpenLibrary(0,Path.s+"\gsdll32.dll")
     
     
    If OpenGSDLL
     
        ;--- 07 Checking the revision of the ghostscript DLL (gs32dll.dll)
        ;    if you use another version, change the revision check (or just remove it)
      Result=CallFunction(0,"gsapi_revision",@GS_Revision,SizeOf(TGS_Revision))
      Debug  GS_Revision\intRevision
      Debug  GS_Revision\intRevisionDate
       Debug  GS_Revision\StrCopyright
       If GS_Revision\intRevision=920
     
          ;--- 08 Revision fits, so start a new instance of ghostscript
         Result =  CallFunction(0,"gsapi_new_instance",@intGSInstanceHandle,0)
         Debug result
     
         gsargv(0) =@"ps2pdf" 
        gsargv(1) = @"-dNOPAUSE"
       gsargv(2) = @"-dBATCH"
      gsargv(3) = @"-dSAFER"   
      gsargv(4) = @"-sDEVICE=pdfwrite"
       gsargv(5) = @"-sOutputfile=page1.pdf"
      gsargv(6) = @"-c"
      gsargv(7) = @".setpdfwrite"
      gsargv(8) = @"-f"
       gsargv(9) = @"avis1.ps" 
       gsargc.i=10                             ;Number of parameters passed
     
     
     
     
          Result= CallFunction(0,"gsapi_set_arg_encoding",intGSInstanceHandle,1)
            Debug result
            ;--- 10 Initializing the api & passing the array of arguments
            Debug "Ligne 114"
            Debug @gsargv()
            nombre.l = @gsargv()
     
          Result = CallFunction(0,"gsapi_init_with_args",intGSInstanceHandle,gsargc, @gsargv())
          Debug Str(result) + "Ligne 123"
     
     
          ;--- 11 Return value of 0 means "No Error"
         Debug "Input file:  "+PeekS(gsargv(9))
          Debug "Output param: "+PeekS(gsargv(5))
          If Result=0
            Debug "No error."        
          Else
            Debug "Error: "+Str(Result)
          EndIf
     
          ;--- 12 Closing all gs related stuff
          Result = CallFunction(0,"gsapi_exit",intGSInstanceHandle)
          Result = CallFunction(0,"gsapi_delete_instance",intGSInstanceHandle)
        EndIf
      CloseLibrary(0)
     
    EndIf
    Je bloque sur la balise
    Result = CallFunction(0,"gsapi_init_with_args",intGSInstanceHandle,gsargc, @gsargv())
    Debug Str(result) + "Ligne 123"
    qui retourne un message d'erreur -100 provenant semble-t-il du passage du tableau des arguments.
    Qulequ'un peut-il m'aider ?

  2. #2
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 261
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 261
    Points : 9 924
    Points
    9 924
    Billets dans le blog
    8
    Par défaut
    srod a écrit un truc plus récent et qui fonctionne :

    enregistre le code suivant avec le nom GhostScriptHelper.pbi
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    ;/////////////////////////////////////////////////////////////////////////////////
    ;GhostScriptHelper.
    ;
    ;©nsxSoftware 2011.
    ;==============
    ;   Stephen Rodriguez (srod)
    ;   Created with Purebasic 4.6 for Windows.
    ;
    ;   Platforms:  Windows.
    ;   Fully Unicode compliant.
    ;
    ;Thanks to progi1984 for his GhostScript library from which I stole the ps2pdf routine and converted to Unicode etc.
    ;/////////////////////////////////////////////////////////////////////////////////
     
     
    ;/////////////////////////////////////////////////////////////////////////////////
    ;The following function attempts to locate the GhostScript library on the user's computer. This assumes that the GhostScript installer was used.
    ;If successful, returns the full path (including the library name) of the latest version of the library found on the machine,
    ;otherwise an empty string is returned.
    ;Failure does not necessarily mean that the library is not present - just that we cannot locate it.
    Procedure.s GhostScriptHelper_GetGhostScriptInstallation()
      Protected result$, hKey1, numSubkeys, maxSubKeyLen, nameBuffer, i, t1, t1$, key$, latestKey, latestKey$
      Protected bufferSize, type
      ;Attempt to open the relevant registry parent key.
      If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, "Software\GPL Ghostscript", 0, #KEY_READ, @hKey1) = #ERROR_SUCCESS And hKey1
        If RegQueryInfoKey_(hKey1, 0, 0, 0, @numSubkeys, @maxSubKeyLen, 0, 0, 0, 0, 0, 0) = #ERROR_SUCCESS
          If numSubkeys And maxSubKeyLen
            nameBuffer = AllocateMemory((maxSubKeyLen+1)<<(SizeOf(CHARACTER)-1))
            If nameBuffer
              For i = 0 To numSubkeys - 1
                t1 = maxSubKeyLen+1
                RegEnumKeyEx_(hKey1, i, nameBuffer, @t1, 0, 0, 0, 0)
                key$ = PeekS(nameBuffer)
                If key$
                  t1$ = RemoveString(key$, ".")
                  t1 = Val(key$)
                  If t1 > latestKey
                    latestKey = t1
                    latestKey$ = key$
                  EndIf
                EndIf
              Next
              FreeMemory(nameBuffer)       
              If latestKey$
                latestKey$ = "Software\GPL Ghostscript\" + latestKey$
              EndIf
            EndIf
          EndIf
        EndIf
        RegCloseKey_(hKey1)
        ;latestKey$ contains the subkey name of the relevant registry entry. We just have to read it's value.
        If latestKey$
          If RegOpenKeyEx_(#HKEY_LOCAL_MACHINE, latestKey$, 0, #KEY_READ, @hKey1) = #ERROR_SUCCESS And hKey1
            RegQueryValueEx_(hKey1, "GS_DLL", 0, @type, 0, @bufferSize)
            If type = #REG_SZ And bufferSize
              nameBuffer = AllocateMemory(buffersize)
              If nameBuffer
                If RegQueryValueEx_(hKey1, "GS_DLL", 0, 0, nameBuffer, @bufferSize) = #ERROR_SUCCESS
                  result$ = PeekS(nameBuffer)
                EndIf
                FreeMemory(nameBuffer)
              EndIf
            EndIf
            RegCloseKey_(hKey1)
          EndIf
        EndIf
      EndIf
      ProcedureReturn result$
    EndProcedure
    ;/////////////////////////////////////////////////////////////////////////////////
     
     
    ;/////////////////////////////////////////////////////////////////////////////////
    ;The following uses GhostScript to convert a ps file to pdf.
    ;ghostScript$ should contain the complete path to the GhostScript dll. Either use a local copy of the dll stored in the application
    ;folder or, if prefering to use the GhostScript installation itself, try locating the GhostScript installation folder using the
    ;above GhostScriptHelper_GetGhostScriptInstallation() function.
    ;Returns zero if an error.
    Procedure.i GhostScriptHelper_ps2pdf(ghostScript$, inputFile$, outputFile$="")
      Protected result, libID, t1$, gsargc = 10, code, instance, utf8Buffer, *ptr
      Protected Dim  gsargv.i(gsargc)
      If ghostScript$ And inputFile$ And FileSize(inputFile$) > 0
        If outputFile$ = ""
          t1$ = GetExtensionPart(inputFile$)
          If t1$
            outputFile$ = ReplaceString(inputFile$, t1$, "pdf")
          Else
            outputFile$ = inputFile$ + ".pdf"
          EndIf
        EndIf
        ;Create a UTF-8 array of command strings.
          utf8Buffer = AllocateMemory(2048)
        If utf8Buffer
          *ptr = utf8Buffer
          gsargv(0) = ?GhostScript_ps2pdf_ps2pdf
          gsargv(1) = ?GhostScript_ps2pdf_dNOPAUSE
          gsargv(2) = ?GhostScript_ps2pdf_dBATCH
          gsargv(3) = ?GhostScript_ps2pdf_dSAFER
          gsargv(4) = ?GhostScript_ps2pdf_sDEVICEpdfwrite
          gsargv(6) = ?GhostScript_ps2pdf_C
          gsargv(7) = ?GhostScript_ps2pdf_setpdfwrite
          gsargv(8) = ?GhostScript_ps2pdf_F
          PokeS(*ptr, "-sOutputFile="+outputFile$, -1, #PB_UTF8)
          gsargv(5) = *ptr : *ptr + StringByteLength("-sOutputFile="+outputFile$, #PB_UTF8) + 1
          PokeS(*ptr, inputFile$, -1, #PB_UTF8)
          gsargv(9) = *ptr
          libID = OpenLibrary(#PB_Any, ghostScript$)
          If libID
            code = CallFunction(libID, "gsapi_new_instance", @instance, #Null)
            If code >= 0
              code = CallFunction(libID, "gsapi_init_with_args", instance, gsargc, @gsargv())
              If code >=0
                result = #True
              EndIf
              CallFunction(libID, "gsapi_exit", instance)
              CallFunction(libID, "gsapi_delete_instance", instance)
            EndIf 
            CloseLibrary(libID) 
          EndIf
          FreeMemory(utf8Buffer)
        EndIf
      EndIf
      ProcedureReturn result
    EndProcedure
    ;/////////////////////////////////////////////////////////////////////////////////
     
     
    ;/////////////////////////////////////////////////////////////////////////////////
    ;DATA SECTION (UTF8 STRINGS).
      DataSection
        GhostScript_ps2pdf_ps2pdf: ;'ps2pdf'
          Data.a 112, 115, 50, 112, 100, 102, 0
        GhostScript_ps2pdf_dNOPAUSE: ;'-dNOPAUSE'
          Data.a 45, 100, 78, 79, 80, 65, 85, 83, 69, 0
        GhostScript_ps2pdf_dBATCH: ;'-dBATCH'
          Data.a 45, 100, 66, 65, 84, 67, 72, 0
        GhostScript_ps2pdf_dSAFER: ;'-dSAFER'
          Data.a 45, 100, 83, 65, 70, 69, 82, 0
        GhostScript_ps2pdf_sDEVICEpdfwrite: ;'-sDEVICE=pdfwrite'
          Data.a 45, 115, 68, 69, 86, 73, 67, 69, 61, 112, 100, 102, 119, 114, 105, 116, 101, 0
        GhostScript_ps2pdf_C: ;'-c'
          Data.a 45, 99, 0
        GhostScript_ps2pdf_setpdfwrite: ;'.setpdfwrite'
          Data.a 46, 115, 101, 116, 112, 100, 102, 119, 114, 105, 116, 101, 0
        GhostScript_ps2pdf_F: ;'-f'
          Data.a 45, 102, 0
      EndDataSection
    ;/////////////////////////////////////////////////////////////////////////////////
    Et voici un exemple d'utilisation, il suffit de copier un fichier test.ps dans le même répertoire pour générer un pdf.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    ;/////////////////////////////////////////////////////////////////////////////////
    ;GhostScriptHelper demo program
    ;/////////////////////////////////////////////////////////////////////////////////
     
    XIncludeFile "GhostScriptHelper.pbi"
     
    ghostScript$ = GhostScriptHelper_GetGhostScriptInstallation()
     
    Debug ghostScript$
     
    If GhostScriptHelper_ps2pdf(ghostScript$, "test.ps")
      MessageRequester("GhostScript Helper", "Conversion of 'test.ps' to PDF successful.")
    Else
      MessageRequester("GhostScript Helper", "Conversion of 'test.ps' to PDF unsuccessful.")
    EndIf
    Source de l'information
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  3. #3
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 261
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 261
    Points : 9 924
    Points
    9 924
    Billets dans le blog
    8
    Par défaut
    Note : Tu peux te passer des datas en utilisant la fonction UTF8()

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
          gsargv(0) = UTF8("ps2pdf")                  ;?GhostScript_ps2pdf_ps2pdf
          gsargv(1) = UTF8("-dNOPAUSE")           ;?GhostScript_ps2pdf_dNOPAUSE
          gsargv(2) = UTF8("-dBATCH")               ;?GhostScript_ps2pdf_dBATCH
          gsargv(3) = UTF8("-dSAFER")               ;?GhostScript_ps2pdf_dSAFER
          gsargv(4) = UTF8("-sDEVICE=pdfwrite") ;?GhostScript_ps2pdf_sDEVICEpdfwrite
          gsargv(6) = UTF8("-c")                       ;?GhostScript_ps2pdf_C
          gsargv(7) = UTF8(".setpdfwrite")          ;?GhostScript_ps2pdf_setpdfwrite
          gsargv(8) = UTF8("-f")                        ;?GhostScript_ps2pdf_F
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  4. #4
    Membre à l'essai
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 38
    Points : 23
    Points
    23
    Par défaut Suite et fin
    J'ai testé la création de fichier PDF comme indiqué, ça fonctionne bien Merci SROD et COMTOIS
    J'ai voulu m'attaquer à la conversion d'un fichier en PDF/A mais là ça ne marche pas avec les paramétres suivants:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
        gsargv(0) = UTF8("ps2pdf")
          gsargv(1) =  UTF8("-dBATCH")
          gsargv(2) =  UTF8("-dNOPAUSE")
          gsargv(3) =  UTF8("-dPDFSETTINGS=/screen")
          gsargv(4) =  UTF8("-dPDFA=3")
          gsargv(5) =  UTF8("-dCompatibilityLevel=1.4")
          gsargv(6) =  UTF8("-dNOOUTERSAVE")
          gsargv(7) =  UTF8("-sProcessColorModel=DeviceRGB")
          gsargv(8) =  UTF8("-sDEVICE=pdfwrite")
          gsargv(9) =  UTF8("-o")
          gsargv(10) =  UTF8("C:\Users\toto\Desktop\nouveau.pdf")
          gsargv(11) =  UTF8("C:\Users\Patrick\Documents\\PDFA_def.ps")
          gsargv(12) =  UTF8("C:\Users\toto\Desktop\dds.pdf")
    Em dimensionnant bie sur gsargv à 13 et gasrgc à 13
    Les mêmes paramétres avec lancement du programme gswin32.exe fonctionne parfaitement.
    Merci s'ile st possible de me dire ce qui coince.

  5. #5
    Responsable Purebasic

    Avatar de comtois
    Inscrit en
    Avril 2003
    Messages
    1 261
    Détails du profil
    Informations forums :
    Inscription : Avril 2003
    Messages : 1 261
    Points : 9 924
    Points
    9 924
    Billets dans le blog
    8
    Par défaut
    Je ne connais pas cette DLL je ne peux pas tester ton truc, par contre il n'y a pas de raison pour que ça ne marche pas. Vérifie ta syntaxe, par exemple :
    gsargv(11) = UTF8("C:\Users\Patrick\Documents\\PDFA_def.ps")
    C'est normal d'avoir \\ ?
    Vous souhaitez participer à la rubrique PureBasic (tutoriels, FAQ, sources) ? Contactez-moi par MP.

  6. #6
    Membre à l'essai
    Profil pro
    Inscrit en
    Décembre 2012
    Messages
    38
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Décembre 2012
    Messages : 38
    Points : 23
    Points
    23
    Par défaut Créer du PDF/X
    J'utilise les mémes arguments que pour générer du PDF /A mais ça ne marche pas
    Voici les arguments
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
     gsargv(0) = UTF8("ps2pdf")   
      gsargv(1) =  UTF8("-dBATCH")
        gsargv(2) =  UTF8("-dNOPAUSE")
            gsargv(3) =  UTF8("-dSAFER")
            gsargv(4) = UTF8("-sDEVICE=pdfwrite")
              gsargv(5) =         UTF8("-dEmbedAllFonts")
            gsargv(6) = UTF8("--sProcessColorModel=DeviceCMYK")
        gsargv(7) =         UTF8("-sColorConversionStrategy=/CMYK")
            gsargv(8) =  UTF8("-dPDFX")
          gsargv(9) = UTF8("-dPDFACompatibilityPolicy=1")
         gsargv(10) =  UTF8("-dNOOUTERSAVE")
          gsargv(11) = UTF8("-o")
          gsargv(12) = UTF8(outputfile)
          gsargv(13) =  UTF8(path+"\PDFX_def.ps")
          gsargv(14) =  UTF8(inputfile)

    Quelqu"un peut-il m'aider car j'ai une erreur -100 en essayant de générer du PDF/X 3 ?

Discussions similaires

  1. comment utiliser les fonctions d'une dll
    Par sebled dans le forum MFC
    Réponses: 3
    Dernier message: 24/02/2006, 16h59
  2. utilisation de classe dans une DLL
    Par _stef_ffff_f34 dans le forum Windows
    Réponses: 1
    Dernier message: 10/02/2006, 16h03
  3. Réponses: 7
    Dernier message: 25/11/2005, 17h11
  4. utilisation des fonctions d'une dll
    Par jackk dans le forum C++
    Réponses: 14
    Dernier message: 15/06/2005, 16h50
  5. Utilisation fonction définie dans un .Dll
    Par jeab. dans le forum Windows
    Réponses: 5
    Dernier message: 23/03/2004, 16h23

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo