HTML
JPG
PDF
XML
DOCX
PDF
Cloud .NET SDK でのブックマーク操作方法
Cloud .NET SDK を介して PDF のブックマークを操作するために使用するのは、 Aspose.PDF Cloud .NET SDK この Cloud SDK を使用すると、C#、ASP.NET、またはその他の .NET 言語でさまざまなクラウドプラットフォーム向けにクラウドベースの PDF 作成、編集、変換アプリを簡単に構築できます。開く 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);
}
}
}
}