| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1081 人关注过本帖, 2 人收藏
标题:用免费的libhpdf.dll在pdf中输出文字
只看楼主 加入收藏
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:808
专家分:1231
注 册:2021-10-13
结帖率:96.83%
收藏(2)
已结贴  问题点数:20 回复次数:19 
用免费的libhpdf.dll在pdf中输出文字
上次狐友提供的libhpdf.dll库挺强大的,我把c++的输出文字到pdf的源码改成vfp的,在win7+VFP9.0下 运行通过,现在分享给大家。
可惜这个库里很多函数不知道怎么用,慢慢摸索吧。。。
奉上代码:

程序代码:
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
搜索更多相关主题的帖子: Integer String Single pdf dll 
2023-10-21 15:19
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:808
专家分:1231
注 册:2021-10-13
收藏
得分:0 
图片附件: 游客没有浏览图片的权限,请 登录注册
2023-10-21 15:33
schtg
Rank: 12Rank: 12Rank: 12
来 自:Usa
等 级:贵宾
威 望:67
帖 子:1790
专家分:3409
注 册:2012-2-29
收藏
得分:7 
谢谢!
2023-10-21 17:44
sych
Rank: 6Rank: 6
等 级:侠之大者
威 望:7
帖 子:322
专家分:450
注 册:2019-10-11
收藏
得分:7 
http://
有会的朋友,把最新的编译成dll吧,谢谢

2023-10-22 09:20
iswith
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:5
帖 子:474
专家分:621
注 册:2013-5-14
收藏
得分:7 
试了一下,确实OK,小日本的,用着心里头不舒服。。。。。
图片附件: 游客没有浏览图片的权限,请 登录注册


2023-10-22 10:55
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:808
专家分:1231
注 册:2021-10-13
收藏
得分:0 
回复 4楼 sych
有C语言编译器的应该都可以编译
2023-10-22 11:02
sam_jiang
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:14
帖 子:808
专家分:1231
注 册:2021-10-13
收藏
得分:0 
回复 5楼 iswith
小日本以前挺厉害的,记得日本在压缩算法有一款共享软件很出名的,另外在条码上也很厉害。还有一款反编译软件execope好像也是出自日本人之手。。。
2023-10-22 11:05
iswith
Rank: 7Rank: 7Rank: 7
等 级:黑侠
威 望:5
帖 子:474
专家分:621
注 册:2013-5-14
收藏
得分:0 
以下是引用sam_jiang在2023-10-22 11:05:25的发言:

小日本以前挺厉害的,记得日本在压缩算法有一款共享软件很出名的,另外在条码上也很厉害。还有一款反编译软件execope好像也是出自日本人之手。。。

这里有一个问题,就是从frx-->image-->>pdf 你的PDF就改变了性质了不是矢量图了!放大变型且不可选择文字。。。成为图片在PDF,这种应该不对。。。。,优点就是转换快速,不用依赖。。。。一个DLL有拥有FRX-->PDF

[此贴子已经被作者于2023-10-22 11:26编辑过]

2023-10-22 11:21
mail0595
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2022-9-20
收藏
得分:0 
好像没有指定打印机静默打印,放大缩小打印的函数!
2023-11-11 16:13
seasoners
Rank: 2
等 级:论坛游民
帖 子:58
专家分:19
注 册:2013-12-15
收藏(1)
得分:0 
汉字库好像不行
2023-11-13 14:01
快速回复:用免费的libhpdf.dll在pdf中输出文字
数据加载中...
 
   



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

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