| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1080 人关注过本帖, 2 人收藏
标题:用免费的libhpdf.dll在pdf中输出文字
只看楼主 加入收藏
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:806
专家分:1231
注 册:2021-10-13
收藏
得分:0 
回复 10楼 seasoners
支持宋体和黑体的

HPDF_UseCNSFonts(Hpdf)

支持的简体字体如下
SimSun(宋体)
SimSun,Bold
SimSun,Italic
SimSun,BoldItalic
SimHei (黑体)
SimHei,Bold
SimHei,Italic
SimHei,BoldItalic

示例:
HPDF_UseCNSFonts(Hpdf)
HPDF_UseCNSEncodings(Hpdf)
def_font = HPDF_GetFont (Hpdf, "SimSun", [GBK-EUC-H])
HPDF_Page_SetFontAndSize (npage, def_font, 24)

[此贴子已经被作者于2023-11-13 21:18编辑过]

2023-11-13 19:46
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:806
专家分:1231
注 册:2021-10-13
收藏
得分:0 
附上加入汉字显示的代码:
程序代码:
DO decl
dime font_list[15]
    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"
    font_list[15]="SimSun" &&宋体

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

HPDF_UseCNSFonts(Hpdf) &&显示汉字必须调用这两个函数
HPDF_UseCNSEncodings(Hpdf) &&显示汉字必须调用这两个函数

*!* 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)
    IF i=15 
        samp_text="欢迎使用libhpdf宋体汉字库!"
              hfont = HPDF_GetFont(hpdf, font_list[i],[GBK-EUC-H])
    else    
        samp_text="abcdefgABCDEFG12345!#$%&+-@?"
           hfont = HPDF_GetFont(hpdf, font_list[i], 0)
    endif    

 
    *!*/* 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 hpdf, String filename, Integer embedding
    Declare Integer HPDF_GetEncoder In libhpdf.dll Integer hpdf, String encodingname
    Declare Integer HPDF_GetCurrentEncoder In libhpdf.dll Integer hpdf
    Declare Integer HPDF_SetCurrentEncoder In libhpdf.dll Integer hpdf, String encodingname
    Declare Integer HPDF_Encoder_GetType In libhpdf.dll Integer encoder
    Declare Integer HPDF_Encoder_GetByteType In libhpdf.dll Integer encoder, String ctext, Integer nindex
    Declare String  HPDF_Encoder_GetUnicode In libhpdf.dll Integer encoder, String ccode
    Declare Integer HPDF_Encoder_GetWritingMode In libhpdf.dll Integer encoder
    Declare Integer HPDF_UseJPEncodings In libhpdf.dll Integer hpdf
    Declare Integer HPDF_UseKREncodings In libhpdf.dll Integer hpdf
    Declare Integer HPDF_UseCNSEncodings In libhpdf.dll Integer hpdf
    Declare Integer HPDF_UseCNTEncodings In libhpdf.dll Integer hpdf
    Declare Integer HPDF_LoadPngImageFromFile In libhpdf.dll Integer hpdf, String cfilename
    Declare Integer HPDF_LoadJpegImageFromFile In libhpdf.dll Integer hpdf, String cfilename
    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 hpdf, Integer ntype, String cvalue
    Declare Integer HPDF_SetPassword In libhpdf.dll Integer hpdf, String ownerpassword, String userpassword
    Declare Integer HPDF_SetPermission In libhpdf.dll Integer hpdf, Integer npermission
    Declare Integer HPDF_SetEncryptionMode In libhpdf.dll Integer hpdf, Integer nmode, Integer nkeylen
    Declare Integer HPDF_SetCompressionMode In libhpdf.dll Integer hpdf, Integer nmode
    Declare Integer HPDF_Font_MeasureText In libhpdf.dll Integer hfont, String ctext, Integer nlength, Single nwidth, ;
                                                        Single nfontsize, Single ncharspace, Single nwordspace, Integer nwordwrap, Single @nrealwidth
    Declare Single  HPDF_Page_GetWidth In libhpdf.dll Integer hpage
    Declare Single  HPDF_Page_GetHeight In libhpdf.dll Integer hpage
    Declare Single  HPDF_Page_TextWidth In libhpdf.dll Integer hpage, String ctext
    Declare Integer HPDF_Page_GetCurrentFont In libhpdf.dll Integer hpage
    Declare Integer HPDF_Page_MeasureText In libhpdf.dll Integer hpage, String ctext, Single nwidth, Integer nwordwrap, Single @nrealwidth
    Declare Integer HPDF_Page_GetRGBFill In libhpdf.dll Integer hpage
    Declare Integer HPDF_Page_GetCurrentFont In libhpdf.dll Integer hpage
    Declare Single  HPDF_Page_GetCurrentFontSize In libhpdf.dll Integer hpage
    Declare Integer HPDF_Page_SetLineWidth In libhpdf.dll Integer npage, Single nlinewidth
    Declare Integer HPDF_Page_SetDash In libhpdf.dll Integer npage, String cdashptn, Integer nnumpara, Integer nphase
    Declare Integer HPDF_Page_MoveTo In libhpdf.dll Integer hpage, Single x, Single y
    Declare Integer HPDF_Page_LineTo In libhpdf.dll Integer hpage, Single x, Single y
    Declare Integer HPDF_Page_ClosePath In libhpdf.dll Integer hpage
    Declare Integer HPDF_Page_Rectangle In libhpdf.dll Integer hpage, Single x, Single y, Single nwidth, Single nheight
    Declare Integer HPDF_Page_Concat In libhpdf.dll Integer hpage, Single a, Single b, Single c, Single d, Single x, Single y
    Declare Integer HPDF_Page_SetCharSpace In libhpdf.dll Integer hpage, Single nspace
    Declare Integer HPDF_Page_SetWordSpace In libhpdf.dll Integer hpage, Single nspace
    Declare Integer HPDF_Page_SetHorizontalScalling In libhpdf.dll Integer hpage, Single nscalling
    Declare Integer HPDF_Page_SetTextLeading In libhpdf.dll Integer hpage, Single nleading
    Declare Integer HPDF_Page_SetTextRise In libhpdf.dll Integer hpage, Single nrise
    Declare Integer HPDF_Page_Stroke In libhpdf.dll Integer hpage
    Declare Integer HPDF_Page_ClosePathStroke In libhpdf.dll Integer hpage
    Declare Integer HPDF_Page_Fill In libhpdf.dll Integer hpage
    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


上面的代码在win7+VFP9 环境编译通过!

2023-11-13 20:46
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:806
专家分:1231
注 册:2021-10-13
收藏
得分:0 
回复 9楼 mail0595
跟打印没有关系的,这是Pdf库
2023-11-13 21:22
seasoners
Rank: 2
等 级:论坛游民
帖 子:58
专家分:19
注 册:2013-12-15
收藏
得分:0 
其他汉字不行吧
2023-12-14 07:54
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:806
专家分:1231
注 册:2021-10-13
收藏
得分:0 
回复 14楼 seasoners
好像目前只支持宋体和黑体。。。
2023-12-17 18:55
sostemp
Rank: 4
等 级:贵宾
威 望:10
帖 子:202
专家分:284
注 册:2009-6-2
收藏
得分:0 
先收藏学习代码,dll谁上传一个新版。
2023-12-19 09:10
csyx
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:火星
等 级:版主
威 望:37
帖 子:709
专家分:2848
注 册:2018-3-13
收藏
得分:0 
以下是引用sam_jiang在2023-12-17 18:55:29的发言:

好像目前只支持宋体和黑体。。。

可以的,只是用 HPDF_UseCNSFonts 仅加载了宋体和黑体字体,其他中文字体需要用 HPDF_LoadTTFontFromFile(加载 TTF 字体文件)或 HPDF_LoadTTFontFromFile2 (加载 TTC 字体文件)
图片附件: 游客没有浏览图片的权限,请 登录注册

总的来说这个 dll 问题很多,例如前面提到过的出口参数问题;中文也有问题,例如要显示 GBK 字符集中的汉字,例如:朱(镕)基、(焗)油,就必须将 GB-EUC-H 换成 GBK-EUC-H,但这样一来,英文/数字/符号又不显示了 。。。一言难尽,唯有弃用

这家伙很懒,啥也没留下
2023-12-19 10:18
foxfans
Rank: 5Rank: 5
等 级:贵宾
威 望:15
帖 子:113
专家分:324
注 册:2021-10-23
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册

是这个?代码调用问题?


[此贴子已经被作者于2023-12-19 11:16编辑过]

2023-12-19 11:14
csyx
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:火星
等 级:版主
威 望:37
帖 子:709
专家分:2848
注 册:2018-3-13
收藏
得分:0 
以下是引用foxfans在2023-12-19 11:14:27的发言:
是这个?代码调用问题?

不是,使用 HPDF_UseCNSFonts 装入的宋体、黑体没问题,问题出在使用 HPDF_LoadTTFontFromFile/HPDF_LoadTTFontFromFile2 装入的其他中文字体
图片附件: 游客没有浏览图片的权限,请 登录注册

这家伙很懒,啥也没留下
2023-12-19 13:21
老去的流星雨
Rank: 2
等 级:论坛游民
帖 子:24
专家分:57
注 册:2023-9-9
收藏
得分:0 
搞那么复杂干什么,直接调用WINDOWS的PDF打印机不就得了,可以完美保留字体和样式
自己使用的调用PDF打印机的代码片断
        DELETE FILE GETENV("TEMP")+'\pdf*.*'
        COPY FILE _Cfg.AppPath+IIF('ZDesigner'$Thisform.cPrintName,"Reports\ZT211\","Reports\")+ ALLTRIM(TB_BAG_STICKER_REPORT.打印模版)+'.*' TO GETENV("TEMP")+'\pdf.*'
        USE GETENV("TEMP")+'\pdf.frx' IN SELECT(1)
        APRINTERS(prt)
        lcPrintName = ""
        FOR i = 1 TO ALEN(prt,1)
            IF 'PDF'$prt(i,1)
                lcPrintName = prt(i,1)
            ENDIF
        ENDFOR
        SET PRINTER TO NAME (lcPrintName)
        REPLACE tag WITH '' tag2 WITH '' IN pdf
        USE IN pdf
        REPORT FORM GETENV("TEMP")+'\pdf.frx' NOEJECT NOCONSOLE TO PRINTER
2024-02-19 14:01
快速回复:用免费的libhpdf.dll在pdf中输出文字
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.046060 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved