Hello,
I am trying to use convert Api to takes a PPTX file and transform to PDF with an SDK on Python-Django but I dont know what I am doing wrong.
Now with my code doesnt get into response and on the other hand say I dont have a file or directory for pdf which is false, If I just try to save a pptx on that directory it works perfectly. ¿So, where is my mistake?
def generate_and_save_pptx(self):
# Path PPTX
pptx_template_path = ‘panel/templates/originals/Prueba.pptx’
# Path PDF
pdf_filename = f’{self.client.name} - {self.type_submission.name}_tutorial.pdf’
pdf_path = submission_directory_path(self,pdf_filename)
api_instance = groupdocs_conversion_cloud.ConvertApi.from_keys(app_sid, app_key)
# Configura la solicitud de conversión directa
convert_request = groupdocs_conversion_cloud.ConvertDocumentDirectRequest(
"pdf",
pptx_template_path,
None,
None,
None
)
try:
# Realiza la conversión directa
response = api_instance.convert_document_direct(convert_request)
# Save file converted
with open(pdf_path, "wb") as pdf_file:
pdf_file.write(response)
except ApiException as e:
print(f"Error during conversion: {e}")
Thank you very much
@holaauxers
Please find the sample code to convert a PPTX to PDF without using cloud storage. Hopefully, it will help you accomplish the task.
# Import module
import groupdocs_conversion_cloud
from shutil import copyfile
# Get your client_id and client_key at https://dashboard.groupdocs.cloud (free registration is required).
client_id = "xxx-xxx-xxxx-xxxx-xxx"
client_key = "xxxxxxxxxxxxxxxxxxxxxxx"
# Create instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(client_id, client_key)
try:
#Convert PPTX to PDF
# Prepare request
request = groupdocs_conversion_cloud.ConvertDocumentDirectRequest("pdf", "C:/Temp/sample.pptx")
# Convert
result = convert_api.convert_document_direct(request)
copyfile(result, 'C:/Temp/sample.pdf')
print("Result {}".format(result))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception when calling get_supported_conversion_types: {0}".format(e.message))
thank you for your answer but still cant convert to pdf.
In my result print I receive something like this Result C:\Users\auxer\AppData\Local\Temp\ALE
My code adapted what you say is on this way:
def generate_and_save_pptx(self):
# Credenciales Api Group Docs
app_sid = settings.GROUP_DOCS_CLIENT_ID
app_key = settings.GROUP_DOCS_CLIENT_SECRET
# Rutas
pptx_template_path = ‘panel/templates/originals/Prueba.pptx’
pptx_filename = f"{self.client.name} - {self.type_submission.name}_tutorial.pptx"
pptx_path = submission_directory_path(self, pptx_filename)
pdf_filename = f'{self.client.name} - {self.type_submission.name}_tutorial.pdf'
pdf_path = submission_directory_path(self, pdf_filename)
# Modificación PPTX
presentation = Presentation(pptx_template_path)
self.modify_presentation(presentation)
presentation.save(pptx_path)
# Create instance of the API
convert_api = groupdocs_conversion_cloud.ConvertApi.from_keys(app_sid, app_key)
try:
#Convert PPTX to PDF
# Prepare request
request = groupdocs_conversion_cloud.ConvertDocumentDirectRequest("pdf", pptx_path)
# Convert
result = convert_api.convert_document_direct(request)
copyfile(result, pdf_path)
print("Result {}".format(result))
except groupdocs_conversion_cloud.ApiException as e:
print("Exception when calling get_supported_conversion_types: {0}".format(e.message))
@holaauxers
My above code is working fine with the latest SDK of GroupDocs.Conversion Cloud for Python. However, I am afraid I could not test your code due to missing references. Please share your sample working script file for testing.