aspose pdf 转成html,使用Aspose.PDF for .NET将PDF转换为HTML格式示例解读(3)——将字体另存为WOFF或TTF...

aspose.pdf for .net是一种高级pdf处理和解析api,用于在跨平台应用程序中执行文档管理和操作任务。api可以轻松用于生成,修改,转换,渲染,保护和打印pdf文档,而无需使用adobe acrobat。此外,还提供pdf压缩选项,表格创建和操作,图形和图像功能,广泛的超链接功能,印章和水印任务,扩展的安全控制和自定义字体处理。

pdf是当今最流行的文档格式之一,各种应用程序将其用作最终输出。由于支持多种数据类型和可移植性,因此它是创建和共享内容的首选格式。作为对开发文档管理应用程序感兴趣的.net应用程序开发人员,可能希望嵌入处理功能,以读取pdf文档并将其转换为其他文件格式,例如html。

pdf转html-将字体另存为woff或ttf

aspose.pdf for .net提供了将html文件转换为pdf格式并将pdf文件转换为html的功能。在pdf到html的转换过程中,pdf中使用的truetype字体可以保存在文件系统中。为了确保最大的浏览器兼容性,可以嵌入几种字体类型.

生成tiff或woff字体

为了实现此要求,已添加了htmlsaveoptions.fontsavingmodes枚举数和htmlsaveoptions.fontsavingmode转换选项。以下代码段可在将pdf文件转换为html格式时将字体另存为ttf。

//文档目录的路径。

string datadir = runexamples.getdatadir_asposepdf_documentconversion_pdftohtmlformat();

//输出html文件路径信息

string outfile = path.getfullpath(datadir + "36192_out.html");

//源pdf文档

document doc = new document(datadir + "input.pdf");

//使用测试的功能创建htmlsaveoption

htmlsaveoptions saveoptions = new htmlsaveoptions();

saveoptions.fixedlayout = true;

saveoptions.splitintopages = false;

//将字体另存为ttf格式

saveoptions.fontsavingmode = htmlsaveoptions.fontsavingmodes.alwayssaveasttf;

string htmlfile = path.getfullpath(outfile);

string linkedfilesfolder = path.getdirectoryname(htmlfile) + @"\36192_files";

if (directory.exists(linkedfilesfolder))

{

directory.delete(linkedfilesfolder, true);

}

//保存输出

doc.save(outfile, saveoptions);

要以woff格式保存字体,请使用以下代码:

saveoptions。fontsavingmode  =  htmlsaveoptions。fontsavingmodes。alwayssaveaswoff ;

生成3套字体

aspose.pdf for .net v9.3.0发行之前,api支持将字体保存为woff或ttf。这意味着无法在internet explorer 6至8中加载字体,因此在这些浏览器中查看文档时看起来不正确。同样对于移动浏览器,ttf字体是最大兼容性所必需的。解决方案是生成3组字体,以确保最大程度的浏览器兼容性,然后在css中引用所有字体,如下所示。以下格式类似于此处描述的格式。

@font-face {

font-family:"wbulfr+arial-boldmt";

src:url("fa507958-0001-0000-0000-000000000000.eot");

src:url("fa507958-0001-0000-0000-000000000000.eot?#iefix") format("embedded-opentype"),

url("fa507958-0001-0000-0000-000000000000.woff") format("woff"),

url("fa507958-0001-0000-0000-000000000000.ttf") format("truetype");

}

为了实现此要求,saveinallformats在htmlsaveoptions.fontsavingmodes枚举中引入了字体保存模式。下面的代码片段演示了如何生成3组字体。

//文档目录的路径。

string datadir = runexamples.getdatadir_asposepdf_documentconversion_pdftohtmlformat();

document doc = new document(datadir + "input.pdf");

htmlsaveoptions htmloptions = new htmlsaveoptions();

htmloptions.fixedlayout = true;

htmloptions.rasterimagessavingmode = htmlsaveoptions.rasterimagessavingmodes.asexternalpngfilesreferencedviasvg;

htmloptions.fontsavingmode = htmlsaveoptions.fontsavingmodes.saveinallformats;

doc.save(datadir + "threesetfonts_out.html", htmloptions);

如果您有任何疑问或需求,请随时加入aspose技术交流群(642018183)。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值