PNG
JPG
BMP
TIFF
PDF
Como redimensionar PDF via Cloud Python SDK
Para redimensionar o PDF, usaremos Aspose.PDF Cloud Python SDK. Este Cloud SDK auxilia programadores Python a desenvolver aplicativos baseados em nuvem para criar, anotar, editar e converter PDFs usando a linguagem de programação Python via Aspose.PDF REST API. Se o pacote Python estiver hospedado no Github, você pode instalá-lo diretamente de lá:
Instalação a partir do Github
pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git
Comando do Console do Gerenciador de Pacotes
pip install asposepdfcloud
Etapas para redimensionar PDF via Python SDK
Os desenvolvedores do Aspose.PDF Cloud podem carregar e redimensionar PDF facilmente em apenas algumas linhas de código.
- Instalar Python SDK
- Carregar o arquivo original para a Aspose Cloud
- Configurar caminho e parâmetros para conversão para HTML
- Converter PDF para HTML (formato XHTML)
- Converter o HTML redimensionado de volta para PDF
- Baixar o arquivo PDF final redimensionado
Redimensionar PDF usando Python
import os
import logging
from pathlib import Path
from asposepdfcloud import PdfApi, AsposeResponse, HtmlDocumentType, OutputFormat
from change_layout_helper import PdfChangeLayoutHelper
class PdfResizePages:
def __init__(self, pdf_api: PdfApi, helper: PdfChangeLayoutHelper):
self.pdfApi = pdf_api
self.helper = helper
def resizeAllPages(self, documentName: str, htmlTempDoc: str, width: int, height: int, outputDocumentName: str, localFolder: Path, tempFolder: str):
self.helper.uploadFile(documentName, localFolder, tempFolder)
htmlTempPath = os.path.join(tempFolder, htmlTempDoc)
args = {
"folder": tempFolder,
"document_type": HtmlDocumentType.XHTML,
"output_format": OutputFormat.FOLDER,
}
response: AsposeResponse = self.pdfApi.put_pdf_in_storage_to_html(documentName, htmlTempPath, **args)
if response.code != 200:
logging.error("resizeAllPages(): Unexpected error in PDF to HTML conversion!")
else:
logging.info("resizeAllPages(): Successfully convert PDF to HTML!")
args2 = {
"dst_folder": tempFolder,
"html_file_name": htmlTempDoc,
"height": height,
"width": width,
}
response: AsposeResponse = self.pdfApi.put_html_in_storage_to_pdf(outputDocumentName, htmlTempPath, **args2)
if response.code != 200:
logging.error("resizeAllPages(): Unexpected error in HTML to PDF conversion!")
else:
logging.info("resizeAllPages(): Successfully convert HTML tot PDF!")
self.helper.downloadFile(outputDocumentName, outputDocumentName, localFolder, tempFolder, "resized_")
Com nossa biblioteca Python você pode:
Redimensionar documentos PDF com Aspose.PDF Cloud Python SDK.
- Combinar documentos PDF.
- Dividir arquivos PDF.
- Converter PDF para outros formatos e vice-versa.
- Manipular Anotações.
- Trabalhar com Imagens em PDF, etc.
- Você pode experimentar nosso App gratuito para testar a funcionalidade online.