#2
sam_jiang2023-10-21 15:33
|
可惜这个库里很多函数不知道怎么用,慢慢摸索吧。。。
奉上代码:
程序代码:
DO decl
dime font_list[14]
font_list[1]="Courier"
font_list[2]="Courier-Bold"
font_list[3]="Courier-Oblique"
font_list[4]="Courier-BoldOblique"
font_list[5]="Helvetica"
font_list[6]="Helvetica-Bold"
font_list[7]="Helvetica-Oblique"
font_list[8]="Helvetica-BoldOblique"
font_list[9]="Times-Roman"
font_list[10]="Times-Bold"
font_list[11]="Times-Italic"
font_list[12]="Times-BoldItalic"
font_list[13]="Symbol"
font_list[14]="ZapfDingbats"
local page_title,hpdf,fname,npage,def_font,ntextwidth,nheight,nwidth,i,samp_text,hfont
page_title= "Font Demo"
hpdf=hpdf_new(0,0)
IF hpdf=0
RETURN .f.
ENDIF
*!* Add a new page object. *!*
npage = HPDF_AddPage (hpdf)
nheight = HPDF_Page_GetHeight(npage)
nwidth = HPDF_Page_GetWidth (npage)
*!* Print the lines of the page. *!*
HPDF_Page_SetLineWidth (npage, 1)
HPDF_Page_Rectangle(npage, 50, 50, nwidth - 100, nheight - 110)
HPDF_Page_Stroke(npage)
*!* Print the title of the page (with positioning center). */
def_font = HPDF_GetFont (hpdf, "Helvetica", 0)
HPDF_Page_SetFontAndSize (npage, def_font, 24)
ntextwidth = HPDF_Page_TextWidth (npage, page_title)
HPDF_Page_BeginText (npage)
HPDF_Page_TextOut (npage, (nwidth - ntextwidth) / 2, nheight - 50, page_title)
HPDF_Page_EndText (npage)
*!* /* output subtitle. */
HPDF_Page_BeginText (npage)
HPDF_Page_SetFontAndSize (npage, def_font, 16)
HPDF_Page_TextOut (npage, 60, nheight - 80, "<Standerd Type1 fonts samples>")
HPDF_Page_EndText (npage)
HPDF_Page_BeginText (npage)
HPDF_Page_MoveTextPos (npage, 60, nheight - 105)
FOR i=1 TO aLEN(font_list)
samp_text="abcdefgABCDEFG12345!#$%&+-@?"
hfont = HPDF_GetFont(hpdf, font_list[i], 0)
*!*/* print a label of text */
HPDF_Page_SetFontAndSize (npage, def_font, 9)
HPDF_Page_ShowText(npage, font_list[i])
HPDF_Page_MoveTextPos(npage, 0, -18)
*!* /* print a sample text. */
HPDF_Page_SetFontAndSize(npage, hfont, 20)
HPDF_Page_ShowText(npage, samp_text)
HPDF_Page_MoveTextPos(npage, 0, -20)
ENDFOR
HPDF_Page_EndText(npage)
fname=PUTFILE("","pdftest","pdf")
HPDF_SaveToFile (hpdf, fname)
*!* /* clean up */
HPDF_Free(hpdf)
RETURN .t.
*!* pdf = HPDF_New(0, 0)
*!* HPDF_UseCNSFonts(pdf)
*!* HPDF_UseCNSEncodings(pdf)
*!* HPDF_SetCompressionMode(pdf, HPDF_COMP_ALL)
*!* page1 = HPDF_AddPage(pdf)
*!* lnHandle=HPDF_LoadJpegImageFromFile(pdf, lcFile)
*!* HPDF_Page_DrawImage(Page1, lnHandle, 0,0,620,878)
*!* HPDF_SaveToFile (pdf,(dir1)+'\'+afile1+".pdf")
*!* HPDF_Free(pdf)
*!* 我试了,
*!* HPDF_Page_DrawImage(Page1, lnHandle, nx,ny,nwidth,nheight) &&nx,ny是以左下角为坐标点的
*!* 单个文件转换代码:
*!* pdf=hpdf_new(0,0)
*!* nhandle=hpdf_loadjpegimagefromfile(pdf,GETFILE())
*!* page1=hpdf_addpage(pdf)
*!* y=hpdf_page_getheight(page1)
*!* hpdf_page_drawimage(page1,nhandle,0,y-nheight,nwidth,nheight) && nwidth,nheight得是图片尺寸,才不会变型,否则图像被放大或缩小
*!* hpdf_savetofile(pdf,putfile("","unnamed","pdf"))
*!* DO decl
PROCEDURE decl
Declare Integer HPDF_New In libhpdf.dll Integer herror, Integer pointer
Declare Integer HPDF_Free In libhpdf.dll Integer hpdf
Declare Integer HPDF_SaveToFile In libhpdf.dll Integer hpdf, String cfilename
Declare Integer HPDF_GetError In libhpdf.dll Integer hpdf
Declare Integer HPDF_ResetError In libhpdf.dll Integer hpdf
Declare Integer HPDF_SetPageMode In libhpdf.dll Integer hpdf, Integer npagemode
Declare Integer HPDF_GetCurrentPage In libhpdf.dll Integer hpdf
Declare Integer HPDF_AddPage In libhpdf.dll Integer hpdf
Declare Integer HPDF_Page_SetWidth In libhpdf.dll Integer hpdf, Single nwidth
Declare Integer HPDF_Page_SetHeight In libhpdf.dll Integer hpdf, Single nheight
Declare Integer HPDF_GetFont In libhpdf.dll Integer hpdf, String fontname, String encodingname
Declare String HPDF_LoadTTFontFromFile In libhpdf.dll Integer hpdf, String filename, Integer embedding
Declare String HPDF_LoadTTFontFromFile2 In libhpdf.dll Integer, String, Integer
Declare Integer HPDF_GetEncoder In libhpdf.dll Integer, String
Declare Integer HPDF_GetCurrentEncoder In libhpdf.dll Integer
Declare Integer HPDF_SetCurrentEncoder In libhpdf.dll Integer, String
Declare Integer HPDF_Encoder_GetType In libhpdf.dll Integer
Declare Integer HPDF_Encoder_GetByteType In libhpdf.dll Integer, String, Integer
Declare String HPDF_Encoder_GetUnicode In libhpdf.dll Integer, String
Declare Integer HPDF_Encoder_GetWritingMode In libhpdf.dll Integer
Declare Integer HPDF_UseJPEncodings In libhpdf.dll Integer
Declare Integer HPDF_UseKREncodings In libhpdf.dll Integer
Declare Integer HPDF_UseCNSEncodings In libhpdf.dll Integer
Declare Integer HPDF_UseCNTEncodings In libhpdf.dll Integer
Declare Integer HPDF_LoadPngImageFromFile In libhpdf.dll Integer, String
Declare Integer HPDF_LoadJpegImageFromFile In libhpdf.dll Integer, String
Declare Integer HPDF_Image_GetWidth In libhpdf.dll Integer hpage
Declare Integer HPDF_Image_GetHeight In libhpdf.dll Integer hpage
Declare Integer HPDF_SetInfoAttr In libhpdf.dll Integer, Integer, String
Declare Integer HPDF_SetPassword In libhpdf.dll Integer, String, String
Declare Integer HPDF_SetPermission In libhpdf.dll Integer, Integer
Declare Integer HPDF_SetEncryptionMode In libhpdf.dll Integer, Integer, Integer
Declare Integer HPDF_SetCompressionMode In libhpdf.dll Integer, Integer
Declare Integer HPDF_Font_MeasureText In libhpdf.dll Integer, String, Integer, Single, Single, Single, Single, Integer, Single @
Declare Single HPDF_Page_GetWidth In libhpdf.dll Integer
Declare Single HPDF_Page_GetHeight In libhpdf.dll Integer
Declare Single HPDF_Page_TextWidth In libhpdf.dll Integer, String
Declare Integer HPDF_Page_GetCurrentFont In libhpdf.dll Integer
Declare Integer HPDF_Page_MeasureText In libhpdf.dll Integer, String, Single, Integer, Single @
Declare Integer HPDF_Page_GetRGBFill In libhpdf.dll Integer
Declare Integer HPDF_Page_GetCurrentFont In libhpdf.dll Integer
Declare Single HPDF_Page_GetCurrentFontSize In libhpdf.dll Integer
Declare Integer HPDF_Page_SetLineWidth In libhpdf.dll Integer, Single
Declare Integer HPDF_Page_SetDash In libhpdf.dll Integer, String, Integer, Integer
Declare Integer HPDF_Page_MoveTo In libhpdf.dll Integer, Single, Single
Declare Integer HPDF_Page_LineTo In libhpdf.dll Integer, Single, Single
Declare Integer HPDF_Page_ClosePath In libhpdf.dll Integer
Declare Integer HPDF_Page_Rectangle In libhpdf.dll Integer, Single, Single, Single, Single
Declare Integer HPDF_Page_Concat In libhpdf.dll Integer, Single, Single, Single, Single, Single, Single
Declare Integer HPDF_Page_SetCharSpace In libhpdf.dll Integer, Single
Declare Integer HPDF_Page_SetWordSpace In libhpdf.dll Integer, Single
Declare Integer HPDF_Page_SetHorizontalScalling In libhpdf.dll Integer, Single
Declare Integer HPDF_Page_SetTextLeading In libhpdf.dll Integer, Single
Declare Integer HPDF_Page_SetTextRise In libhpdf.dll Integer, Single
Declare Integer HPDF_Page_Stroke In libhpdf.dll Integer
Declare Integer HPDF_Page_ClosePathStroke In libhpdf.dll Integer
Declare Integer HPDF_Page_Fill In libhpdf.dll Integer
Declare Integer HPDF_Page_FillStroke In libhpdf.dll Integer
Declare Integer HPDF_Page_EndPath In libhpdf.dll Integer
Declare Integer HPDF_Page_BeginText In libhpdf.dll Integer
Declare Integer HPDF_Page_EndText In libhpdf.dll Integer
Declare Integer HPDF_Page_SetFontAndSize In libhpdf.dll Integer, Integer, Single
Declare Integer HPDF_Page_SetTextRenderingMode In libhpdf.dll Integer, Integer
Declare Integer HPDF_Page_MoveTextPos In libhpdf.dll Integer, Single, Single
Declare Integer HPDF_Page_MoveToNextLine In libhpdf.dll Integer
Declare Integer HPDF_Page_SetRGBFill In libhpdf.dll Integer, Single, Single, Single
Declare Integer HPDF_Page_SetRGBStroke In libhpdf.dll Integer, Single, Single, Single
Declare Integer HPDF_Page_Ellipse In libhpdf.dll Integer, Single, Single, Single, Single
Declare Integer HPDF_Page_DrawImage In libhpdf.dll Integer, Integer, Single, Single, Single, Single
Declare Integer HPDF_Page_TextRect In libhpdf.dll Integer, Single, Single, Single, Single, String, Integer, Integer
Declare Integer HPDF_Page_TextOut In libhpdf.dll Integer, Single, Single, String
Declare Integer HPDF_Page_SetTextMatrix In libhpdf.dll Integer ,Single, Single, Single, Single, Single, Single
Declare Integer HPDF_Page_ShowText In libhpdf.dll Integer, String
Declare Integer HPDF_Page_CurveTo In libhpdf.dll Integer, Single, Single, Single, Single, Single, Single
Declare integer HPDF_UseCNSFonts In libhpdf.dll Integer
ENDPROC