欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

PDF开发工具Aspose.PDF功能推荐——在.NET中将PDF转换为HTML

程序员文章站 2023-11-08 16:59:04
PDF是当今最流行的文档格式之一,各种应用程序将其用作最终输出。由于支持多种数据类型和可移植性,因此它是创建和共享内容的首选格式。作为对开发文档管理应用程序感兴趣的.NET应用程序开发人员,可能希望嵌入处理功能,以读取PDF文档并将其转换为其他文件格式,例如HTML。 下面,来探索并演示一下Aspo ......

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

下面,来探索并演示一下aspose.pdf for .net api的强大转换功能,以使用多种选项读取pdf文件并将其转换为html。

 

将html转换到pdf

只需使用几行代码和资源加载回调就可以以非常基本的方式将html转换为pdf,以下是使您达到目的的代码段:

// the path to the documents directory.
string datadir = runexamples.getdatadir_asposepdf_documentconversion();

htmlloadoptions options = new htmlloadoptions();
options.customloaderofexternalresources = new loadoptions.resourceloadingstrategy(samepictureloader);

document pdfdocument = new document(datadir + "htmltopdf.html", options);
pdfdocument.save("htmltopdf_out.pdf");

将pdf转换为多页html

可以使用以下示例代码在将pdf转换为html的过程中,将上述步骤中的html分为多个页面。

// the path to the documents directory.
string datadir = runexamples.getdatadir_asposepdf_documentconversion();

// open the source pdf document
document pdfdocument = new document(datadir + "pdftohtml.pdf");

// instantiate html saveoptions object
htmlsaveoptions htmloptions = new htmlsaveoptions();

// specify to split the output into multiple pages
htmloptions.splitintopages = true;

// save the document
pdfdocument.save(@"multipagehtml_out.html", htmloptions);

将splitintopages标志设置为true可以为您完成所有工作,并且输出html由多个页面而不是单个页面组成。

将图像保存到特定文件夹

pdf文档除了文本详细信息外还可以包含图像。html可以包含html内基于64位编码的图像,也可以引用这些图像所在的文件夹中的图像。aspose.pdf api具有丰富的功能,可以将图像保存到光盘上用户指定的文件夹中。以下代码示例显示了在将pdf转换为html的过程中如何将图像保存到特定文件夹。

// create htmlsaveoption with tested feature
htmlsaveoptions newoptions = new htmlsaveoptions();

// specify the separate folder to save images
newoptions.specialfolderforallimages = datadir;