HTML
JPG
PDF
XML
DOCX
PDF
如何通过云 .NET SDK 替换书签
为了通过云 .NET SDK 替换书签,我们将使用 Aspose.PDF Cloud .NET SDK 此云 SDK 允许您轻松构建基于云的 PDF 创建、编辑和转换应用程序,适用于 C#、ASP.NET 或其他 .NET 语言的各种云平台。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 并安装。您也可以使用包管理器控制台中的以下命令。
包管理器控制台命令
PM> Install-Package Aspose.Pdf-Cloud
通过 .NET SDK 替换书签的步骤
Aspose.PDF Cloud 开发人员可以通过几行代码轻松加载和更改 PDF 中的书签。
- 使用您的应用程序密钥和密钥创建一个新的配置对象
- 创建一个对象以连接到云 API
- 上传您的文档文件
- 使用 PutBookmarkAsync 函数设置所需属性
- 检查响应并记录结果
- 下载更新的文件以便本地使用
此示例代码显示如何在 PDF 文档中替换书签
using Aspose.Pdf.Cloud.Sdk.Model;
namespace Bookmarks
{
public class BookmarksReplace
{
public static async Task Modify(string documentName, string outputName, string bookmarkPath, string title, string localFolder, string remoteFolder)
{
// Get your AppSid and AppSecret from https://dashboard.aspose.cloud (free registration required).
pdfApi = new PdfApi(AppSecret, AppSid);
using (var file = File.OpenRead(Path.Combine(localFolder, documentName)))
{ // Upload the local PDF to cloud storage folder name.
FilesUploadResult uploadResponse = await pdfApi.UploadFileAsync(Path.Combine(remoteFolder, documentName), documentName);
Console.WriteLine(uploadResponse.Uploaded[0]);
}
// Create new bookmark with input parameters for the PDF on cloud storage.
Bookmark bookmark = new Bookmark(
Action: "GoTo",
Bold: true,
Italic: false,
Title: title,
PageDisplay: "XYZ",
PageDisplayBottom: 10,
PageDisplayLeft: 10,
PageDisplayRight: 10,
PageDisplayTop: 10,
PageDisplayZoom: 2,
PageNumber: 1,
Color: new Color(A: 0x00, R: 0x00, G: 0xFF, B: 0x00)
);
// Replace a bookmark with bookmarkPath in the PDF on cloud storage.
BookmarkResponse response = await pdfApi.PutBookmarkAsync(documentName, bookmarkPath, bookmark, folder: remoteFolder);
// Checks the response and logs the result.
if (response == null)
Console.WriteLine("BookmarksReplace(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("BookmarksReplace(): Failed to append bookmark to the document.");
else
{ // Downloads the updated file for local use.
Console.WriteLine("BookmarksReplace(): bookmark successfully replaced in the document '{0}.", documentName);
Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
using var fileStream = File.Create(Path.Combine(localFolder, "replace_bookmark_" + outputName));
stream.Position = 0;
await stream.CopyToAsync(fileStream);
Console.WriteLine("BookmarksReplace(): File '{0}' successfully downloaded.", "replace_bookmrk_" + outputName);
}
}
}
}
使用我们的 .NET SDK,您可以
- 添加 PDF 文档的文本或图像格式的页眉和页脚。
- 向 PDF 文档添加表格和文本或图像戳记。
- 将多个 PDF 文档附加到现有文件。
- 处理 PDF 附件、注释和表单字段。
- 对 PDF 文档应用加密或解密并设置密码。
- 从页面或整个 PDF 文档中删除所有戳记和表格。
- 按 ID 从 PDF 文档中删除特定的戳记或表格。
- 替换 PDF 页面或整个文档中的单个或多个文本实例。
- 广泛支持将 PDF 文档转换为各种其他文件格式。
- 提取 PDF 文件的各种元素并优化 PDF 文档。
- 您可以尝试我们的免费应用在线替换 PDF 文件中的书签并测试功能。