Spire.PDF for .NET【文档操作】演示:动态创建 PDF 并将其发送到客户端浏览器

这篇具有很好参考价值的文章主要介绍了Spire.PDF for .NET【文档操作】演示:动态创建 PDF 并将其发送到客户端浏览器。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

可移植文档格式 (PDF) 是 Adobe 制定的独立规范的固定版式文档。它封装了完整的描述,包括文本字体、图形和显示它所需的其他信息。

Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。

E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件,不受其他国家的技术或法律法规限制,同时适配国产操作系统如中科方德、中标麒麟等,兼容国产文档处理软件 WPS(如 .wps/.et/.dps 等格式

Spire.PDF for.net下载   Spire.PDF for java下载

动态创建PDF并将其发送到客户端浏览器

要动态生成 PDF 文件然后将其发送到客户端浏览器,您可以使用Spire.PDF for .NET来完成此任务。此外,Spire.PDF还支持加载现有的PDF文件并将其发送到客户端浏览器。在这篇技术文章中,我们将结合这两个功能来完整描述 Spire.PDF 的工作原理。下面是两个任务:

  • 任务1 动态创建PDF并将其发送到客户端浏览器。
  • 任务2 加载现有的PDF文件并将其发送到客户端浏览器(这是Spire.PDF for .NET的附加功能)

首先创建一个Asp.net应用程序并添加Spire.PDF.dll程序集。您可以在VS中的Aspx页面上添加两个按钮。指定其中一名负责任务 1,另一名负责任务 2。

spire.pdf for .net百度云,Spire.PDF for .Net 教程,pdf,.net,python,spire.pdf,pdf开发

对于任务1,首先需要启动一个Spire.PdfDocument对象

[C#]

PdfDocument doc = new PdfDocument();

并在这个新的 PDF 文档中添加一个新页面

[C#]

PdfPageBase page = newDoc.Pages.Add();

注意在该pdf页面上绘制字符串时需要相关的辅助对象。

[C#]

string message = "Hello world!";
PdfFont font = new PdfFont(PdfFontFamily.Helvetica, 13f);
PdfBrush brush = PdfBrushes.Red;
PointF location = new PointF(20, 20);

然后你可以在pdf页面中绘制一个字符串,如下所示:

[C#]

page.Canvas.DrawString(message, font, brush, location);

最后您可以在客户端浏览器中打开这个新生成的PDF文档:

[C#]

newDoc.SaveToHttpResponse("sample.pdf",HttpContext.Current.Response, HttpReadType.Open);

对于任务2,3行代码就可以直接解决。

启动 Spire.PdfDocument 对象

[C#]

pdfDocument doc = new PdfDocument();

加载 pdf 文件

[C#]

doc.LoadFromFile(this.Server.MapPath("/sample.pdf"));

加载pdf文档,然后将其作为附件发送到客户端浏览器。

[C#]

doc.SaveToHttpResponse("sample.pdf", this.Response, HttpReadType.Save);

综上所述,以下是这两个任务所需的完整代码片段:

[C#]

using System;

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Spire.Pdf;
using Spire.Pdf.Graphics;

namespace SendPdfToWebBrowser
{
public partial class WebForm_SendPdf : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}
// load a pdf document ,after that ,send it to client browser as an attachment
protected void btnClientSavePdf_Click(object sender,EventArgs e)
{

// initiated an object of Spire.PdfDocument
PdfDocument doc = new PdfDocument();
// Load a pdf file

doc.LoadFromFile(this.Server.MapPath("/sample.pdf"));
// send the pdf document to client browser as an attachment
doc.SaveToHttpResponse("sample.pdf",this.Response, HttpReadType.Save);
}

// Create an pdf document ,then open it in the client browser
protected void btnClientOpenPdf_Click(object sender, EventArgs e)
{
// Initiate an object of Spire.PdfDocument
PdfDocument newDoc = new PdfDocument();
// Add a new page in this newly created pdf file
PdfPageBase page = newDoc.Pages.Add();
string message = "Hello world!” ;

PdfFont font = new PdfFont(PdfFontFamily.Helvetica,13f);
PdfBrush brush = PdfBrushes.Red;
PointF location = new PointF(20, 20);
// Draw a string with designated brush, a font, position in pdf page
page.Canvas.DrawString(message, font, brush, location);
//To open this pdf document in client browser.
newDoc.SaveToHttpResponse("sample.pdf",HttpContext.Current.Response, HttpReadType.Open);
}
}
}

最后,你可以运行它,并得到如下结果:

spire.pdf for .net百度云,Spire.PDF for .Net 教程,pdf,.net,python,spire.pdf,pdf开发

动态创建 PDF 并将其发送到客户端浏览器的屏幕截图

spire.pdf for .net百度云,Spire.PDF for .Net 教程,pdf,.net,python,spire.pdf,pdf开发

加载现有 PDF 文件并将其发送到客户端浏览器的屏幕截图

spire.pdf for .net百度云,Spire.PDF for .Net 教程,pdf,.net,python,spire.pdf,pdf开发

以上便是如何态创建 PDF 并将其发送到客户端浏览器,如果您有其他问题也可以继续浏览本系列文章,获取相关教程~文章来源地址https://www.toymoban.com/news/detail-858047.html

到了这里,关于Spire.PDF for .NET【文档操作】演示:动态创建 PDF 并将其发送到客户端浏览器的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • PDF控件Spire.PDF for .NET【安全】演示:在 PDF 中添加或删除数字签名

    随着 PDF 文档在商业中越来越流行,确保其真实性已成为一个关键问题。使用基于证书的签名对 PDF 进行签名可以保护内容,还可以让其他人知道谁签署或批准了该文档。在本文中,您将了解如何使用不可见或可见签名对 PDF 进行数字签名,以及如何使用Spire.PDF for .NET从 PDF 中

    2024年02月03日
    浏览(39)
  • PDF控件Spire.PDF for .NET【安全】演示:使用文本或/和图像对 PDF 进行数字签名

    数字签名确保签名的文档不能被除其作者之外的任何人更改。添加签名是确保文档内容真实性的最常见方法。PDF 文档中的可视数字签名可以显示文本或图像(例如手写签名)。本文从以下三个方面介绍如何使用Spire.PDF for .NET对PDF 进行数字签名。 Spire.PDF for .NET 是一款独立

    2024年01月23日
    浏览(35)
  • PDF控件Spire.PDF for .NET【安全】演示:使用时间戳服务器对 PDF 进行数字签名

    Spire.PDF for .NET 是一款独立 PDF 控件,用于 .NET 程序中创建、编辑和操作 PDF 文档。使用 Spire.PDF 类库,开发人员可以新建一个 PDF 文档或者对现有的 PDF 文档进行处理,且无需安装 Adobe Acrobat。 E-iceblue 功能类库Spire 系列文档处理组件均由中国本土团队研发,不依赖第三方软件

    2024年04月10日
    浏览(43)
  • Spire.PDF for .NET 9.8.5 Crack

    Spire.PDF for .NET is a professional PDF API applied to creating, writing, editing, handling and reading PDF files without any external dependencies within .NET ( C#, VB.NET, ASP.NET, .NET Core, .NET 5.0, .NET 6.0, .NET 7.0, MonoAndroid and Xamarin.iOS ) application. Using this .NET PDF library, you can implement rich capabilities to create PDF files from sc

    2024年02月10日
    浏览(32)
  • Spire.Barcode for Java 5.1.0 + Spire.Barcode for .NET 7.2.0

    Spire.Barcode for Java is a professional barcode component specially designed for developers to generate, read and scan 1D 2D barcodes on Java applications (J2SE and J2EE). Developers and programmers can use Spire.Barcode to add Enterprise-Level barcode formats to their Java applications quickly and easily. Spire.Barcode for Java provides a very easy way to

    2024年02月16日
    浏览(33)
  • 【itext7】itext7操作PDF文档之创建PDF文档、加载PDF文档、添加空白页、操作PDF页面、itext中的常见类及其方法

    这篇文章,主要介绍itext7操作PDF文档之创建PDF文档、加载PDF文档、添加空白页、操作PDF页面、itext中的常见类及其方法。 目录 一、itext7操作PDF 1.1、itext7介绍 1.2、引入itext-core依赖 1.3、创建PDF文档 1.4、加载PDF文档 1.5、操作PDF页面 1.6、添加空白页面 二、itext常见类和方法 2.1、

    2024年02月16日
    浏览(34)
  • Spire.Office for.NET Crack

    Spire.Office for.NET是E-iceblue提供的企业级Office.NET API的组合。它包括Spire.Doc、Spire.XLS、Spire.Seadsheet、Spire.Presentation、Spire_PDF、Spire.DataExport、SpireOfficeViewer、Spire-PDFViewer、Spire.DocViewer、Spire.Barcode和Spire.Email.Spire.Office包含上述.NET API的最新版本。 使用Spire.Officefor.NET,开发人员可以创

    2024年02月15日
    浏览(34)
  • 利用Spire.Pdf实现PDF添加印章的操作

    在一些文档处理中,我们需要对PDF盖上公司的印章操作,本篇随笔介绍利用Spire.Pdf实现PDF添加印章的操作,如全章和骑缝章的处理。 有时候,需要在特定的位置盖章,以及各个页面盖上骑缝章,如下界面效果所示。 全章的位置定位好后,绘制一个图片即可,骑缝章则是根据

    2024年02月16日
    浏览(36)
  • Spire.Office for .NET 8.4.1 FIX

    Spire.Office for .NET is a combination of Enterprise-Level Office .NET API offered by E-iceblue. It includes Spire.Doc, Spire.XLS, Spire.Spreadsheet, Spire.Presentation, Spire.PDF, Spire.DataExport, Spire.OfficeViewer, Spire.PDFViewer, Spire.DocViewer, Spire.Barcode and Spire.Email. Spire.Office contains the most up-to-date versions of the above .NET API.  

    2024年02月02日
    浏览(24)
  • Spire.Office 8.5.3 for .NET 哪里值得更新?

    Spire.Office for .NET is a combination of Enterprise-Level Office .NET API offered by E-iceblue. It includes Spire.Doc, Spire.XLS, Spire.Spreadsheet, Spire.Presentation, Spire.PDF, Spire.DataExport, Spire.OfficeViewer, Spire.PDFViewer, Spire.DocViewer, Spire.Barcode and Spire.Email. Spire.Office contains the most up-to-date versions of the above .NET API. Wi

    2024年02月06日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包