HTML
JPG
PDF
XML
DOCX
PDF
如何通过云端 .NET SDK 处理书签
为了通过云端 .NET SDK 处理 PDF 中的书签,我们将使用 Aspose.PDF Cloud .NET SDK 这个 Cloud SDK 允许您轻松构建基于云的 PDF 创建、编辑和转换应用程序,支持 C#、ASP.NET 或其他 .NET 语言,用于各种云平台。打开 NuGet 包管理器,搜索 Aspose.PDF Cloud 并安装。您也可以在包管理器控制台中使用以下命令。
包管理器控制台命令
PM> Install-Package Aspose.Pdf-Cloud
通过 .NET SDK 创建书签的步骤
Aspose.PDF Cloud 开发人员只需几行代码即可轻松加载和创建 PDF 中的书签。
- 使用您的应用程序密钥和密钥创建一个新的 Configuration 对象
- 创建一个对象以连接到云 API
- 上传您的文档文件
- 使用 PostBookmarkAsync 设置所需属性
- 检查响应并记录结果。
- 下载更新的文件以供本地使用。
此示例代码显示如何在 PDF 文档中创建书签
using Aspose.Pdf.Cloud.Sdk.Model;
namespace Bookmarks
{
public class BookmarkAdd
{
public static async Task Append(string documentName, string outputName, string parentBookmarkPath, 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)
);
List<Bookmark> newBookmarks = new List<Bookmark>() { bookmark };
// Append new bookmark under the parentBookmarkPath in the PDF on cloud storage.
BookmarksResponse response = await pdfApi.PostBookmarkAsync(documentName, parentBookmarkPath, newBookmarks, folder: remoteFolder);
// Checks the response and logs the result.
if (response == null)
Console.WriteLine("BookmarkAdd(): Unexpected error!");
else if (response.Code < 200 || response.Code > 299)
Console.WriteLine("BookmarkAdd(): Failed to append bookmark to the document.");
else
{ // Downloads the updated file for local use.
Console.WriteLine("BookmarkAdd(): bookmark successfully appended to the document '{0}.", documentName);
Stream stream = pdfApi.DownloadFile(Path.Combine(remoteFolder, documentName));
using var fileStream = File.Create(Path.Combine(localFolder, "append_bookmark_" + outputName));
stream.Position = 0;
await stream.CopyToAsync(fileStream);
Console.WriteLine("BookmarkAdd(): File '{0}' successfully downloaded.", "append_bookmrk_" + outputName);
}
}
}
}