Spire.Cloud.PDF.SDK提供了接口PdfTextApi及PdfImagesApi用于添加文本和图片到PDF文档,添加文本时,可格式化文本样式,包括文本字体类型、字 、字体样式、文本颜色、字符间距、行距、首行缩进、文本对齐方式、文本环绕方式等;添加图片时,可格式化图片,包括图片位置、高度、宽度等。
Spire.Cloud提供了四种语言的SDK(包括.NET、Java、python、PHP),你可以Spire.Cloud Web SDK。
步骤1:dll文件获取及引用。下载获取Spire.Cloud.PDF.SDK package,并将Spire.Cloud.PDF.Sdk.dll及其依赖项的dll添加引用至程序(如下图)
步骤2:ID及Key获取。在冰蓝云 页注册账 并登陆,在“我的应用”板块创建应用程序,获得 App ID 及 App Key。

示例1:添加文本到PDF
using System;using Spire.Cloud.Pdf.Sdk.Client;using Spire.Cloud.Pdf.Sdk.Api;using Spire.Cloud.Pdf.Sdk.Model;namespace AddText_Cloud.PDF{ class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账 信息 Configuration PdfConfiguration = new Configuration(appId, appKey); PdfTextApi PdfTextApi = new PdfTextApi(PdfConfiguration); string name = "sample.pdf";//源文档 string outPath = "output/AddText.pdf";//结果文档路径 int pageNumber = 2;//指定文本内容所在页码 string folder = "input";//源文档所在文件夹 Spire.Cloud.Pdf.Sdk.Model.Text text = new Spire.Cloud.Pdf.Sdk.Model.Text("This is a test. This is a test. This is a test. This is a test. This is a test. This is a test.", new Font(Font.FontTypeEnum.TrueType, "Arial", 13, Font.FontStyleEnum.Regular), new RectangleF(50, 320, 500, 200));//实例化文本信息(文本内容、字体类型、字 、字体样式、文本位置) text.BackgroundColor = new Color(255, 244, 164, 96);//设置文本背景色 text.ForegroundColor = new Color(255, 135, 206, 235);//设置文本前景色 text.CharSpacing = 5;//字符间距 text.FirstLineIndent = 100;//首行缩进 text.LineSpacing = 15;//行距 text.HorizontalAlignment = Spire.Cloud.Pdf.Sdk.Model.Text.HorizontalAlignmentEnum.Left;//文本水平对齐方式 text.VerticalAlignment = Spire.Cloud.Pdf.Sdk.Model.Text.VerticalAlignmentEnum.Middle;//文本垂直对齐方式 text.WordSpacing = 12;//单词间距 text.WordWrap = Spire.Cloud.Pdf.Sdk.Model.Text.WordWrapEnum.Character;//文本环绕方式 //调用方法添加文本 PdfTextApi.AddText(name, outPath, pageNumber, text, folder, null); } }}

示例2:添加图片到PDF
using Spire.Cloud.Pdf.Sdk.Api;using Spire.Cloud.Pdf.Sdk.Client;using System;using System.IO;namespace AddImg_Cloud.PDF{ class Program { static String appId = "App ID"; static String appKey = "App Key"; static void Main(string[] args) { //配置账 信息 Configuration PdfConfiguration = new Configuration(appId, appKey); PdfImagesApi pdfImagesApi = new PdfImagesApi(PdfConfiguration); string name = "sample.pdf";//源文档 string outPath = "output/AddImg.pdf";//结果文档路径 int pageNumber = 2;//指定图片所在文档页码 string folder = "input";//源文档所在文件夹 string password = null;//源文档密码 System.IO.Stream file = new FileStream("logo.png", FileMode.Open);//打开图片 //指定图片位置及大小 float x = 50; float y = 320; float width = 200; float height = 200; //调用方法添加图片 pdfImagesApi.AddImage(name, outPath, pageNumber, file, x, y, width, height, folder, password); } }}

是E-iceblue官方友好合作伙伴,如果您对Spire
.Cloud感兴趣或需要临时License,可以联系在线客服了解具体授权价格和使用机制。标签:
声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!