HTML
JPG
PDF
XML
DOCX
PDF
クラウド .NET SDK を使用して PDF をリサイズする方法
PDF ドキュメントをリサイズするには、 Aspose.PDF Cloud .NET SDK このクラウド SDK を使用すると、C#、ASP.NET、または他の .NET 言語で、さまざまなクラウドプラットフォーム向けのクラウドベースの PDF 作成、編集、変換アプリを簡単に構築できます。 NuGet パッケージマネージャーを開き、 Aspose.PDF Cloud を検索してインストールします。パッケージ マネージャー コンソールから次のコマンドを使用することもできます。
パッケージ マネージャー コンソール コマンド
PM> Install-Package Aspose.Pdf-Cloud
.NET SDK を使用して PDF をリサイズする手順
Aspose.PDF Cloud 開発者は、わずか数行のコードで PDF を簡単に読み込み、リサイズできます。
- PDF をアップロードします。
- それを HTML に変換します(構造/内容を保持)。
- HTML を指定された寸法で新しい PDF に変換します。
- リサイズされたドキュメントをダウンロードします。
.NET クラウド SDK を使用して PDF をリサイズ
using Aspose.Pdf.Cloud.Sdk.Model;
namespace ChangeLayout
{
public class ResizeDocumentAllPages
{
private ChangeLayoutHelper _helper;
public ResizeDocumentAllPages(ChangeLayoutHelper helper)
{
_helper = helper;
}
public async Task MakeResizeDocumentAllPages(string document, string htmlTempDoc, int pageWidth, int pageHeight)
{
await _helper.UploadFile(document);
string htmlTempPath = Path.Combine(_helper.config.REMOTE_TEMP_FOLDER, htmlTempDoc);
AsposeResponse response = await _helper.pdfApi.PutPdfInStorageToHtmlAsync(
document, htmlTempPath,
documentType: HtmlDocumentType.Xhtml.ToString(),
outputFormat: OutputFormat.Folder.ToString(),
folder: _helper.config.REMOTE_TEMP_FOLDER
);
if (response == null)
Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in Pdf to Html convert!");
else if (response.Code != 200)
Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
else
{
Console.WriteLine("MakeResizeDocumentAllPages(): temporary file '{0}' successfully created.", htmlTempDoc);
string outputDocument = "resized_" + document;
await _helper.pdfApi.PutHtmlInStorageToPdfAsync(
outputDocument, htmlTempPath,
dstFolder: _helper.config.REMOTE_TEMP_FOLDER,
htmlFileName: htmlTempDoc,
height: pageHeight,
width: pageWidth
);
if (response == null)
Console.WriteLine("MakeResizeDocumentAllPages(): Unexpected error - no response in html to Pdf convert!");
else if (response.Code != 200)
Console.WriteLine("MakeResizeDocumentAllPages(): Error -> Code {0} -> Status '{1}'", [response.Code, response.Status]);
else
{
Console.WriteLine("resizePages(): Pages successfully resized.");
await _helper.DownloadFile(outputDocument, "resized_doc_");
}
}
}
}
}