Page 1 of 1

Ejemplo con Image2Pdf SOLUCIONADO

PostPosted: Tue Sep 04, 2012 11:58 pm
by Armando
Amigos:

He descargado el ZIP de image2pdf y trato de probarla pero no encuentro la hebra, alguien podría tirarme
una punta?, si es un ejemplo mejor!.

He buscado en el foro pero los ejemplos que encontré tampoco me funcionan.

En el zip vienen varias DLLS, cual usar?

Saludos

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 10:14 am
by José Vicente Beltrán
Hola Armando,
Yo lo hago de la siguiente forma:

1.- creo un archivo 'opciones.txt' (que coloco junto al EXE Image2PDF) con el siguiente contenido:
Code: Select all  Expand view

-UseActualImageDPI
-UseEMFDeviceSize
 


y después desde código FW llamo al EXE que convierte a PDF (no utilizo las DLL)
Code: Select all  Expand view

    local nFor, cLista:= ""
    local cVerPDF := " -openpdf"

        FOR nFor := 1 TO len(aFiles)
            cLista += "-image "+aFiles[nFor]+" "  //-----------> array de WMF  a convertir
        NEXT

        if file(RutaDelExe+"opciones.txt")
            waitrun( RutaDelExe+cLista+;
                     "    -output "+RutaDelExe+cNombre+;   //------> nombre del documento PDF de salida
                        " -Options "+RutaDelExe+"opciones.txt"+;
                        cVerPDF+;      //-----> permite ver el PDF generado
                        " -License XXXXX-XXXXX-XXXXX-XXXXX-XXXXX" )  //------> numero de licencia de uso
        else
            msgStop( "No existe el archivo:"+CRLF+CRLF+;
                        RutaDelExe+"opciones.txt", "Avisor")
        endif
 


Espero haber ayudado
Saludos :shock:

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 3:36 pm
by George
Armando,
Aqui te dejo la funcion que añadi, en rpreview.prg, para salvar un archivo en formato PDF usando Image2Pdf.dll.
Code: Select all  Expand view
FUNCTION SaveAsPDF(cRepName)
    // cRepName = Name of Report to be saved
    LOCAL result, hLib
    LOCAL cBuffer:=space(300)

    hLib = LOADLIBRARY( "Image2PDF.dll" )

    I2PDF_UseEMFDeviceSize()

    I2PDF_License("Image2PDF License Number") // Put here your Image2PDF License Number

    nRc :=  I2PDF_Log(".\log.txt", 3)

    I2PDF_MetaTextFitBoundingRect()

    nRc := I2PDF_UseEMFDeviceSize()

    nRc := I2PDF_MetaToNativePDF()

    nRc := I2PDF_SetDPI(0)                     //- or to whatever value you require

    DECLARE aEmf := {}
    aEmf := directory("*.emf")

    FOR nX := 1 TO  len(aEmf)
        nRc := I2PDF_AddImage(alltrim(aEmf[nX, F_NAME]))
    NEXT

    nResult := I2PDF_MakePDF(cRepName, 0, @cBuffer ,300)

    FreeLibrary(hLib)

    AEVAL(DIRECTORY(cAppliDir+"\*.EMF"), { |aFile| ferase(aFile[F_NAME])})   // cAppliDir is application path
RETURN (.T.)
 


Saludos,

George

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 3:47 pm
by Armando
José:

Agradezco el ejemplo, me amplia el panorama pues ahora conozco otra forma de ejecutar image2pdf, aunque
mi intención es usar la DLL, de todas formas muy agradecido con tu ejemplo.

George:

Voy a probar tu ejemplo ya daré mis resultados. Por cierto, necesito algunos wrappers???, alguna LIB?.

Nuevamente, muy agradecido a ambos.

Saludos

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 8:30 pm
by George
Armando,
Aqui estan los wrappers:
Code: Select all  Expand view
///////////////////////////////////////////////////////////////////////////
DLL32 Function I2PDF_AddImage(image as LPSTR);
AS LONG PASCAL FROM "I2PDF_AddImage" LIB "IMAGE2PDF.DLL"
//Public Shared Function I2PDF_AddImage(ByVal image As String) As Integer
  //  End Function

DLL32 Function I2PDF_SetProducer(producer as LPSTR);
AS LONG PASCAL FROM "I2PDF_SetProducer" LIB "IMAGE2PDF.DLL"
//Public Shared Function I2PDF_SetProducer(ByVal producer As String) As Integer
//    End Function


DLL32 Function I2PDF_GetDLLVersion();
AS LONG PASCAL FROM "I2PDF_GetDLLVersion" LIB "IMAGE2PDF.DLL"
//Public Shared Function I2PDF_GetDLLVersion() As Integer
//    End Function


DLL32 Function I2PDF_License(code As LPSTR);
AS LPSTR PASCAL FROM "I2PDF_License" LIB "IMAGE2PDF.DLL"
// Public Shared Sub I2PDF_License(ByVal code As String)
//   End Sub


DLL32 Function I2PDF_MetaImageMaxMP(maxmp as LONG);
AS LONG PASCAL FROM "I2PDF_MetaImageMaxMP" LIB "IMAGE2PDF.DLL"
//Public Shared Function I2PDF_MetaImageMaxMP(ByVal maxmp As Double) As Integer
//    End Function

DLL32 Function I2PDF_DeleteImagesOnConvert();
AS VOID PASCAL FROM "I2PDF_DeleteImagesOnConvert" LIB "IMAGE2PDF.DLL"
//Public Shared Sub I2PDF_DeleteImagesOnConvert()


DLL32 Function I2PDF_SetDPI(dpi as LONG);
AS LONG PASCAL FROM "I2PDF_SetDPI" LIB "IMAGE2PDF.DLL"
//Public Shared Function I2PDF_SetDPI(ByVal dpi As Integer) As Integer
//   End Function

DLL32 Function I2PDF_MakePDF(output As LPSTR, options as LONG, @cBuffer As LPSTR, ;
    maxErrorTextSize As LONG);
AS LONG PASCAL FROM "I2PDF_MakePDF" LIB "IMAGE2PDF.DLL"
 //Public Shared Function I2PDF_MakePDF(ByVal output As String, ByVal int options,;
 //  ByRef errorText As String, ByVal maxErrorTextSize As Integer) As Integer
 // End Function

DLL32 Function I2PDF_SetPermissionPrint();
AS VOID PASCAL FROM "I2PDF_SetPermissionPrint" LIB "IMAGE2PDF.DLL"
//Public Shared Sub I2PDF_SetPermissionPrint()
//   End Sub


DLL32 Function I2PDF_MetaImageMaxMP_Int(maxmp as LONG);
AS LONG PASCAL FROM "I2PDF_MetaImageMaxMP_Int" LIB "IMAGE2PDF.DLL"
//Public Shared Function I2PDF_MetaImageMaxMP_Int(ByVal maxmp As Integer) As Integer
//   End Function

DLL32 Function I2PDF_UseEMFDeviceSize();
AS VOID PASCAL FROM "I2PDF_UseEMFDeviceSize" LIB "IMAGE2PDF.DLL"
//Public Shared Sub I2PDF_UseEMFDeviceSize()
//  End Sub

DLL32 Function I2PDF_MetaToNativePDF();
AS VOID PASCAL FROM "I2PDF_MetaToNativePDF" LIB "IMAGE2PDF.DLL"
//Public Shared Sub I2PDF_MetaToNativePDF()
//  End Sub

DLL32 Function I2PDF_Log(logFilename As LPSTR, logLevel as LONG);
AS LONG PASCAL FROM "I2PDF_Log" LIB "IMAGE2PDF.DLL"

DLL32 Function I2PDF_MetaTextFitBoundingRect();
AS VOID PASCAL FROM "I2PDF_MetaTextFitBoundingRect" LIB "IMAGE2PDF.DLL"
 


Espero te sean de utilidad.

George

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 8:38 pm
by Armando
George:

Ahora va mejorando !, ya compilo pero se me queda colgado en la prueba, sera que tengo
la dll o Lib equivocadas?, aquí mi código:

Code: Select all  Expand view

FUNCTION SaveAsPDF(aFiles,pdfFileName)
    LOCAL imageFilename := "   "
    LOCAL ix
    LOCAL iErr := 0
    LOCAL errorText := "  "

   hLib := LoadLib32( "Image2PDF StdCall.DLL" )

   iErr := I2PDF_License( "YOUR LICENSE CODE HERE" )

   // ensure that any EMF files are converted at highest quality
//   iErr := I2PDF_MetaToNativePDF( )
//   iErr := I2PDF_UseEMFDeviceSize( )
//   iErr := I2PDF_SetDPI(0) // Set PDF DPI to the same as the image

   // Build the pages using the array of image files
   FOR ix := 1 TO LEN( aFiles )
      imageFilename := aFiles[ix]
      IF (iErr := I2PDF_AddImage(imageFilename)) # 0
         EXIT
      ENDIF
   NEXT

   // Create the PDF.
   iErr := I2PDF_MakePDF(Rtrim(pdfFilename), 0, errorText, 40 )

    MsgInfo(iErr)

   FreeLib32( hLib )
RETURN (.T.)
 


Saludos

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 9:02 pm
by George
Posiblemente es un problema con la DLL.
Trata con otra de las DLL.
Te sugiero tambien que verfiques los resultados a cada una de las llamadas que haces a la funciones.
Por ejemplo:
Code: Select all  Expand view
hLib = LOADLIBRARY( "Image2PDF.dll" )
     msginfo(hLib)
     MsgInfo(I2PDF_GetDLLVersion())
 

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 9:39 pm
by Armando
George:

Ya compila bien y no se cuelga, te muestro el resultado de los MsgInfo()

Code: Select all  Expand view

FUNCTION SaveAsPDF(aFiles,pdfFileName)
    LOCAL imageFilename := "   "
    LOCAL ix
    LOCAL iErr := 0
    LOCAL errorText := "  "

    MsgInfo(pdfFileName)                                    // C:\PdvWin\Pdfs\Prueba.Pdf

   hLib := LoadLib32( "Image2PDF.DLL" )

    MsgInfo(hLib,"hLib")                                    // 268435456
   MsgInfo(I2PDF_GetDLLVersion(),"Versión")        // 273

   iErr := I2PDF_License( "YOUR LICENSE CODE HERE" )

    MsgInfo(iErr,"Licencia")                            //

   // ensure that any EMF files are converted at highest quality
   iErr := I2PDF_MetaToNativePDF( )
    MsgInfo(iErr,"MetaNative")                          // nil
   iErr := I2PDF_UseEMFDeviceSize( )
    MsgInfo(iErr,"UseEMF")                              // nil
   iErr := I2PDF_SetDPI(0) // Set PDF DPI to the same as the image
    MsgInfo(iErr,"SetDPI")                              // 0

   // Build the pages using the array of image files
   FOR ix := 1 TO LEN( aFiles )
      imageFilename := aFiles[ix]
        MsgInfo(ImageFileName,"FileName")           // C:\Users\Armando\AppData\Local\Temp\21064705.Emf
      IF (iErr := I2PDF_AddImage(imageFilename)) # 0
            MsgInfo(iErr,"iErr")                            // No pasa por aquí
         EXIT
      ENDIF
   NEXT

   // Create the PDF.
   iErr := I2PDF_MakePDF(Rtrim(pdfFilename), 0, errorText, 40 )

    MsgInfo(errorText)
    MsgInfo(iErr,"iErr1")                               // 3  creo que aquí esta el problema

   FreeLib32( hLib )
RETURN (.T.)
 


Al final de cada línea con MsgInfo() esta el resultado, revisando un poco veo que el problema esta
en la llamada a I2PDF_MakePDF, el contenido de la variable errorText es: GetEMFBound failed

Y el error 3 segun la doc de image2pdf es: Internal PDF generation error, podrían ser los nombres largos???

Saludos y muchas gracias por tu apoyo

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 9:56 pm
by George
Armando,
Trata de esta manera:
Code: Select all  Expand view
nResult := I2PDF_MakePDF(cRepName, 0, @cBuffer ,300)

Donde cRepName es el nombre del reporte y cBuffer es una variable char(300) que debes pasarla por referencia.
Verifica el resultado de nResult.

George

Re: Ejemplo con Image2Pdf

PostPosted: Wed Sep 05, 2012 10:30 pm
by Armando
George:

El resultado es el mismo: :cry:

Texto del error: GetEmfBounds failed
Número de error: 3

Saludos

Re: Ejemplo con Image2Pdf SOLUCIONADO

PostPosted: Thu Sep 06, 2012 3:36 pm
by acuellar
Hola Armando.

El rpreview ya guarda en formato PDF usando Office
Tambien existe el nconvert.exe de XnView que es menos complicado.

Por si quiren pasar un TXT a PDF les dejo este pequeño programa.
http://200.58.169.10/acr/txt2pdf.rar

Solo hay que escribir el siguiente código:
Code: Select all  Expand view

 WaitRun("txt2pdf C:\prueba\RRHH\TXTFILE.TXT C:\prueba\PDFFILE",0)
 


Espero les sirva

Saludos,

Adhemar

Re: Ejemplo con Image2Pdf SOLUCIONADO

PostPosted: Thu Sep 06, 2012 6:22 pm
by Armando
Adhemar:

Muchas gracias por el tip y por el programa, por el momento ya brinque la línea gracias
a este excelente foro y en especial a George.

Saludos