spire.pdf支持为pdf文档中的文本添加短语或特定单词作为工具提示,这样当用户将鼠标悬停在文本上时,会弹出提示提供更多信息给客户。该文将介绍如实使用spire.pdf for .net通过在搜索文本上添加不可见按钮来创建工具提示。
首先请查看添加了工具提示的pdf结果文档:
c#
using spire.pdf;
using spire.pdf.fields;
using spire.pdf.general.find;
using system.drawing;
namespace tooltippdf
{
class program
{
static void main(string[] args)
{
//加载示例文档
pdfdocument doc = new pdfdocument();
doc.loadfromfile("sample.pdf");
//获取第一页并查找字符串“spire.pdf for .net”,获取其位置
pdfpagebase page = doc.pages[0];
pdftextfind[] result = page.findtext("spire.pdf for .net").finds;
rectanglef rec = result[0].bounds;
//在搜索文本上添加不可见按钮
pdfbuttonfield field1 = new pdfbuttonfield(page, "field1");
field1.bounds = rec;
//设置工具提示文本及样式
field1.tooltip = "在搜索文本上添加不可见按钮来创建工具提示";
field1.borderwidth = 0;
field1.backcolor = color.transparent;
field1.forecolor = color.transparent;
field1.layoutmode = pdfbuttonlayoutmode.icononly;
field1.iconlayout.isfitbounds = true;
//保存文档
doc.savetofile("result.pdf", fileformat.pdf);
}
}
}
vb.net
imports spire.pdf
imports spire.pdf.fields
imports spire.pdf.general.find
imports system.drawing
namespace tooltippdf
class program
private shared sub main(args as string())
'加载示例文档
dim doc as new pdfdocument()
doc.loadfromfile("sample.pdf")
'获取第一页并查找字符串“spire.pdf for .net”,获取其位置
dim page as pdfpagebase = doc.pages(0)
dim result as pdftextfind() = page.findtext("spire.pdf for .net").finds
dim rec as rectanglef = result(0).bounds
'在搜索文本上添加不可见按钮
dim field1 as new pdfbuttonfield(page, "field1")
field1.bounds = rec
'设置工具提示文本及样式
field1.tooltip = "在搜索文本上添加不可见按钮来创建工具提示"
field1.borderwidth = 0
field1.backcolor = color.transparent
field1.forecolor = color.transparent
field1.layoutmode = pdfbuttonlayoutmode.icononly
field1.iconlayout.isfitbounds = true
'保存文档
doc.savetofile("result.pdf", fileformat.pdf)
end sub
end class
end namespace