Trying to add function addText (that's why I'm interested in this lib) by myself, I didn't succeed:
Code: Select all
CompilerIf #PB_Compiler_IsMainFile
EnableExplicit
CompilerEndIf
Structure cpdf_position
cpdf_anchor.l; /* Position anchor */
cpdf_coord1.d; /* Parameter one */
cpdf_coord2.d; /* Parameter two */
EndStructure
Enumeration cpdf_anchor
#cpdf_posCentre; /* Absolute centre */
#cpdf_posLeft ; /* Absolute left */
#cpdf_posRight; /* Absolute right */
#cpdf_top; /* Top top centre of the page */
#cpdf_topLeft; /* The top left of the page */
#cpdf_topRight; /* The top right of the page */
#cpdf_left; /* The left hand side of the page, halfway down */
#cpdf_bottomLeft; /* The bottom left of the page */
#cpdf_bottom; /* The bottom middle of the page */
#cpdf_bottomRight; /* The bottom right of the page */
#cpdf_right; /* The right hand side of the page, halfway down */
#cpdf_diagonal; /* Diagonal, bottom left To top right */
#cpdf_reverseDiagonal; /* Diagonal, top left To bottom right */
EndEnumeration
Enumeration cpdf_font
#cpdf_timesRoman ; /* Times Roman */
#cpdf_timesBold ; /* Times Bold */
#cpdf_timesItalic ; /* Times Italic */
#cpdf_timesBoldItalic ; /* Times Bold Italic */
#cpdf_helvetica ; /* Helvetica */
#cpdf_helveticaBold ; /* Helvetica Bold */
#cpdf_helveticaOblique ; /* Helvetica Oblique */
#cpdf_helveticaBoldOblique ; /* Helvetica Bold Oblique */
#cpdf_courier ; /* Courier */
#cpdf_courierBold ; /* Courier Bold */
#cpdf_courierOblique ; /* Courier Oblique */
#cpdf_courierBoldOblique ; /* Courier Bold Oblique */
EndEnumeration
Enumeration cpdf_justification
#cpdf_leftJustify ; /* Left justify */
#cpdf_CentreJustify ; /* Centre justify */
#cpdf_RightJustify ; /* Right justify */
EndEnumeration
PrototypeC.i prototype_cpdf_version()
PrototypeC prototype_cpdf_startup(*argv)
PrototypeC.i prototype_cpdf_fromFile(filename.p-utf8, userpw.p-utf8)
PrototypeC prototype_cpdf_clearError()
PrototypeC.i prototype_cpdf_mergeSimple(*pdfs, length.l)
PrototypeC prototype_cpdf_toFile(pdf.l, filename.p-utf8, linearize.l, make_id.l)
PrototypeC prototype_cpdf_pages(pdf.l)
PrototypeC prototype_cpdf_addText(flag_add.l, pdf.l, page.l, txt.p-utf8, *position.cpdf_position, linespacing.d,
stbates.l, font.i, size.d, red.d, green.d, blue.d, flagunder.l, flagcrop.l, flagoutline.l, opacity.d,
justification.i, flag_midline.l, flag_topline.l, fname.p-utf8, linewidth.d, embed.l)
PrototypeC prototype_cpdf_addTextSimple(pdf.l, page.l, txt.p-utf8, *position.cpdf_position, font.i, size.d)
Global cpdf_library.i
Global cpdf_version_.prototype_cpdf_version
Global cpdf_startup.prototype_cpdf_startup
Global cpdf_fromFile.prototype_cpdf_fromFile
Global cpdf_clearError.prototype_cpdf_clearError
Global cpdf_mergeSimple.prototype_cpdf_mergeSimple
Global cpdf_toFile.prototype_cpdf_toFile
Global cpdf_pages.prototype_cpdf_pages
Global cpdf_addText.prototype_cpdf_addText
Global cpdf_addTextSimple.prototype_cpdf_addTextSimple
Global.i cpdf_lastError_
Global.i cpdf_lastErrorString_
Macro cpdf_version()
PeekS(cpdf_version_(), -1, #PB_UTF8)
EndMacro
Macro cpdf_lastError
PeekI(cpdf_lastError_)
EndMacro
Macro cpdf_lastErrorString
PeekS(cpdf_lastErrorString_, -1, #PB_UTF8)
EndMacro
Procedure.i OpenCPDF()
If Not IsLibrary(cpdf_library)
CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
cpdf_library = OpenLibrary(#PB_Any, "E:\install\dvd2\PDF utilities\sdk\cpdf\win32\libcpdf.dll")
CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x64
cpdf_library = OpenLibrary(#PB_Any, "E:\install\dvd2\PDF utilities\sdk\cpdf\win64\libcpdf.dll")
CompilerEndIf
If cpdf_library
cpdf_version_ = GetFunction(cpdf_library, "cpdf_version")
cpdf_startup = GetFunction(cpdf_library, "cpdf_startup")
cpdf_fromFile = GetFunction(cpdf_library, "cpdf_fromFile")
cpdf_clearError = GetFunction(cpdf_library, "cpdf_clearError")
cpdf_mergeSimple = GetFunction(cpdf_library, "cpdf_mergeSimple")
cpdf_toFile = GetFunction(cpdf_library, "cpdf_toFile")
cpdf_pages = GetFunction(cpdf_library, "cpdf_pages")
cpdf_addText = GetFunction(cpdf_library, "cpdf_addText")
cpdf_addTextSimple = GetFunction(cpdf_library, "cpdf_addTextSimple")
cpdf_lastError_ = GetFunction(cpdf_library, "cpdf_lastError")
cpdf_lastErrorString_ = GetFunction(cpdf_library, "cpdf_lastErrorString")
Else
MessageRequester("Error","no libcpdf.dll present")
EndIf
EndIf
ProcedureReturn cpdf_library
EndProcedure
Procedure CloseCPDF()
If IsLibrary(cpdf_library)
CloseLibrary(cpdf_library)
cpdf_library = #Null
EndIf
EndProcedure
CompilerIf #PB_Compiler_IsMainFile
Define *argv
Define.i orig_pdf, output
Dim pdfs.l(2)
Global pos.cpdf_position
pos\cpdf_anchor=#cpdf_posCentre ; /* Position anchor */
pos\cpdf_coord1=100 ; /* Parameter one */
pos\cpdf_coord2=100 ; /* Parameter two */
If OpenCPDF()
; Initialise cpdf
cpdf_startup(@*argv)
;Debug cpdf_version()
; We will take the input hello.pdf And Repeat it three times
orig_pdf = cpdf_fromFile("hello.pdf", "")
; Check the error state
If cpdf_lastError = 1
Debug cpdf_lastErrorString
End 1
EndIf
; Clear the error state
cpdf_clearError()
; The Array of PDFs To merge
pdfs(0) = orig_pdf
pdfs(1) = orig_pdf
pdfs(2) = orig_pdf
; Merge them
output = cpdf_mergeSimple(pdfs(), 3)
; cpdf_addText(#False, output, 1, "hello!!!", @pos, 1, 0, #cpdf_helveticaBoldOblique, 14, 0.5, 0.5, 0.5, #False, #False,
; #False, 1, #cpdf_CentreJustify, #False, #False, "xxx", 5, #False)
cpdf_addTextSimple(output, 1, "hello!!!", @pos, #cpdf_helveticaBoldOblique, 14)
; Check the error state
If cpdf_lastError = 1
Debug cpdf_lastErrorString
End 1
EndIf
cpdf_clearError()
; Write output
cpdf_toFile(output, "output.pdf", #False, #False)
Debug cpdf_pages(output)
; Check the error state
If cpdf_lastError = 1
Debug cpdf_lastErrorString
End 1
EndIf
CloseCPDF()
EndIf
CompilerEndIf
"The debugged executable quit unexpectedly." always at line "cpdf_addTextSimple(output, 1, "hello!!!", @pos, #cpdf_helveticaBoldOblique, 14)"
any help is appreciated.