PNG JPG BMP TIFF PDF
Aspose.PDF  para Python

Cambiar el tamaño de PDF en el SDK de Python

Cambiar el tamaño del Documento PDF utilizando el SDK de Python en la Nube.

Get Started

Cómo cambiar el tamaño de PDF a través del SDK de Python en la Nube

Para cambiar el tamaño de PDF, usaremos Aspose.PDF Cloud Python SDK. Este SDK en la Nube ayuda a los programadores de Python a desarrollar aplicaciones creadoras, anotadoras, editoras y convertidoras de PDF basadas en la nube utilizando el lenguaje de programación Python a través de Aspose.PDF REST API. Si el paquete de Python está alojado en Github, puede instalarlo directamente desde Github:

Instalación desde Github


     
    pip install git+https://github.com/aspose-pdf-cloud/aspose-pdf-cloud-python.git

Comando de la Consola del Administrador de Paquetes

     
    pip install asposepdfcloud

Pasos para cambiar el tamaño de PDF a través del SDK de Python

Los desarrolladores de Aspose.PDF Cloud pueden cargar y cambiar fácilmente el tamaño de un PDF en solo unas pocas líneas de código.

  1. Instale Python SDK
  2. Suba el archivo original a Aspose Cloud
  3. Configure la ruta y los parámetros para la conversión a HTML
  4. Convierta el PDF a HTML (formato XHTML)
  5. Convierta el HTML redimensionado de nuevo a PDF
  6. Descargue el archivo PDF final redimensionado
 

Cambiar el tamaño de 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_")
 

Con nuestra biblioteca de Python usted puede:

Cambiar el tamaño de documentos PDF con Aspose.PDF Cloud Python SDK.

  • Combinar documentos PDF.
  • Dividir archivos PDF.
  • Convertir PDF a otros formatos, y viceversa.
  • Manipular anotaciones.
  • Trabajar con imágenes en PDF, etc.
  • Puede probar nuestra aplicación gratuita para probar la funcionalidad en línea.