HTML
JPG
PDF
XML
DOCX
PDF
How to resize PDF via Cloud .NET SDK
To resize PDF documents, we’ll use Aspose.PDF Cloud .NET SDK This Cloud SDK allows you to easily build cloud-based PDF creator, editor & converter apps in C#, ASP.NET, or other .NET languages for various cloud platforms. Open NuGet package manager, search for Aspose.PDF Cloud and install. You may also use the following command from the Package Manager Console.
Package Manager Console Command
PM> Install-Package Aspose.Pdf-Cloud
Steps to resize PDF using .NET SDK
Aspose.PDF Cloud developers can easily load & resize PDF in just a few lines of code.
- Uploads the PDF.
- Converts it to HTML (retaining structure/content).
- Converts the HTML back to a new PDF with the specified dimensions.
- Downloads the resized document.
Resize PDF using .NET Cloud SDK
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_");
}
}
}
}
}