HTML JPG PDF XML DOCX
  Product Family
PDF

.NET SDKでPDFをトリミング

.NETを使用してPDFドキュメントをリサイズするAPI。

Get Started

Cloud .NET SDKを使用してPDFをトリミングする方法

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を使用してPDFをトリミングする手順

Aspose.PDF Cloudの開発者は、わずか数行のコードでPDFを簡単に読み込み、トリミングできます。

  1. PDFファイルをクラウドにアップロードします。
  2. ページ情報を取得します。
  3. ページを画像として抽出します。
  4. 新しい空のPDFドキュメントを作成します。
  5. 画像を新しいPDFに挿入します。
  6. 最終的にトリミングされたPDFをダウンロードします。
 

.NET Cloud SDKを使用してPDFをトリミング


    using Aspose.Pdf.Cloud.Sdk.Model;

    namespace ChangeLayout
    {
        public class CropDocumentPage
        {
            private ChangeLayoutHelper _helper;

            public CropDocumentPage(ChangeLayoutHelper helper)
            {
                _helper = helper;
            }

            public async Task MakeCropDocumentPage(string document, string outputDocument, int pageNumber, int llx, int lly, int width, int height)
            {
                await _helper.UploadFile(document);
                await _helper.GetPageInfo(document, pageNumber);
                string imageFile = await _helper.ExtractPdfPage(document, pageNumber, _helper.config.CROP_PAGE_WIDTH, _helper.config.CROP_PAGE_HEIGHT);
                DocumentResponse? newPdf = await _helper.CreatePdfDocument(outputDocument, width, height);
                if (newPdf == null)
                    Console.WriteLine("MakeCropDocumentPage(): Unexpected error - new document is NULL");
                else if (newPdf.Code != 200)
                    Console.WriteLine("MakeCropDocumentPage(): Failed to create new PDF document!");
                else
                {
                    AsposeResponse? response = await _helper.InsertPageAsImage(outputDocument, imageFile, llx, lly);
                    if (response == null)
                        Console.WriteLine("MakeCropDocumentPage(): Unexpected error - insert image return NULL");
                    else if (newPdf.Code != 200)
                        Console.WriteLine("MakeCropDocumentPage(): Failed to insert image to the new PDF document!");
                    else
                    {
                        Console.WriteLine("cropPage(): Page successfully cropped.");
                        await _helper.DownloadFile(outputDocument, "cropped_");
                    }
                }
            }
        }
    }