Unable to convert PDF

Hello Team,

We are currently unable to convert documents into PDF. Although no changes have been made at the code level, we are unfortunately encountering the mentioned error frequently. Could you kindly verify on your side to ensure everything is functioning as expected?

Note: Specifically, we are seeing only the “504 Gateway Time-out” error during the conversion process, and we have not been able to identify the root cause from our side.

Could you kindly check on your end to see if any related logs are being generated during the conversion? Additionally, we would appreciate scheduling a short meeting to discuss and take the necessary steps toward resolving this issue.

Thank you for your support.
Log (1).zip (537 Bytes)

Hi, @Manish7320
Can you please share your sample document and code to reproduce the issue? We will further proceed to assist you accordingly.

Hello @kirill.novinskiy

let me share the piece of code where we used to convert the documents into pdf. kindly refer and update

package com.nissan.ask2.aspose.core.operations;

import com.nissan.ask2.aspose.core.services.AsposeService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.nuxeo.ecm.automation.core.Constants;
import org.nuxeo.ecm.automation.core.annotations.Context;
import org.nuxeo.ecm.automation.core.annotations.Operation;
import org.nuxeo.ecm.automation.core.annotations.OperationMethod;
import org.nuxeo.ecm.automation.core.annotations.Param;
import org.nuxeo.ecm.automation.core.util.Properties;
import org.nuxeo.ecm.core.api.*;
import org.nuxeo.ecm.core.api.blobholder.BlobHolder;
import org.nuxeo.ecm.core.api.blobholder.SimpleBlobHolder;
import org.nuxeo.ecm.platform.audit.api.AuditLogger;
import org.nuxeo.ecm.platform.audit.api.LogEntry;
import org.nuxeo.runtime.api.Framework;

import java.io.Serializable;
import java.util.*;

import static com.nissan.ask2.aspose.core.Ask2Constants.*;
import static com.nissan.ask2.aspose.core.Ask2Constants.PDF_SCHEMA_CONTENT_PROPERTY;

@Operation(id = AsposeToPDFOp.ID, category = Constants.CAT_CONVERSION, label = “Convert to PDF with ASPOSE”, description = “Convert to PDF with ASPOSE (on NUXEO server).”)
public class AsposeToPDFOp {

private static final Logger LOGGER = LogManager.getLogger(AsposeToPDFOp.class);
public static final String ID = "Aspose.ToPDF";

@Context
protected AsposeService service;

@Context
protected CoreSession session;

@Param(name = "namedParameters", required = false, description = "Named parameters to pass to aspose convert options")
protected Properties namedParameters = new Properties();

@Param(name = "uidForAudit", required = false, description = "UID of document for audit (used if blob)")
protected String uidForAudit;


@OperationMethod
public Blob run(Blob blob) {

    LOGGER.info("========== Aspose.ToPDF Operation Started (Blob) ==========");
    LOGGER.info("Input Blob Name      : {}", blob != null ? blob.getFilename() : "NULL");
    LOGGER.info("Input Blob MimeType  : {}", blob != null ? blob.getMimeType() : "NULL");
    LOGGER.info("Input Blob Length    : {}", blob != null ? blob.getLength() : "NULL");
    LOGGER.info("Audit UID            : {}", uidForAudit);

    return convertToPDF(blob, uidForAudit);
}


@OperationMethod
public Blob run(DocumentModel document) {

    LOGGER.info("========== Aspose.ToPDF Operation Started (Document) ==========");
    LOGGER.info("Document Id      : {}", document.getId());
    LOGGER.info("Document Name    : {}", document.getName());
    LOGGER.info("Document Title   : {}", document.getTitle());
    LOGGER.info("Document Type    : {}", document.getType());
    LOGGER.info("Document Path    : {}", document.getPathAsString());


    Blob sourceBlob = (Blob) document.getPropertyValue(FILE_SCHEMA_CONTENT_PROPERTY);

    if (sourceBlob == null) {
        LOGGER.error("Source blob is NULL.");
        return null;
    }

    LOGGER.info("Source Blob Filename : {}", sourceBlob.getFilename());
    LOGGER.info("Source Blob MimeType : {}", sourceBlob.getMimeType());
    LOGGER.info("Source Blob Length   : {}", sourceBlob.getLength());
    LOGGER.info("Source Blob Digest   : {}", sourceBlob.getDigest());

    Serializable conversionEnabled = document.getPropertyValue(PDF_SCHEMA_CONVERSION_ENABLED_PROPERTY);
    LOGGER.info("PDF Conversion Enabled Property : {}", conversionEnabled);

    if (conversionEnabled != null && !Boolean.parseBoolean(conversionEnabled.toString())) {
        LOGGER.warn("No converter {} document, the conversion PDF is disabled.", document.getId());
        return null;
    }

    String nativeDigest = sourceBlob.getDigest();
    Serializable pdfNativeDigest = document.getPropertyValue(PDF_SCHEMA_NATIVE_DIGEST_PROPERTY);
    LOGGER.info("Current Native Digest : {}", nativeDigest);
    LOGGER.info("Stored PDF Digest     : {}", pdfNativeDigest);
    if (pdfNativeDigest != null && nativeDigest.equalsIgnoreCase(pdfNativeDigest.toString())) {
        LOGGER.info("Skipping conversion because digests are identical.");
        LOGGER.warn("No converter {} document with same digest {}.", document.getId(), nativeDigest);
        return (Blob) document.getPropertyValue(PDF_SCHEMA_CONTENT_PROPERTY);
    }

    return convertToPDF(sourceBlob, document.getId());
}

private Blob convertToPDF(Blob sourceBlob, String documentId) {

    LOGGER.info("----------------------------------------------------");
    LOGGER.info("Entering convertToPDF()");
    LOGGER.info("Document Id : {}", documentId);

    if (sourceBlob != null) {
        LOGGER.info("Blob Name      : {}", sourceBlob.getFilename());
        LOGGER.info("Blob MimeType  : {}", sourceBlob.getMimeType());
        LOGGER.info("Blob Length    : {}", sourceBlob.getLength());
        LOGGER.info("Blob Digest    : {}", sourceBlob.getDigest());
    }

    if (documentId == null || documentId.isEmpty()) {
        LOGGER.error("No documentId provided!");
    }


    SimpleBlobHolder blobHolder = new SimpleBlobHolder(sourceBlob);
    AuditLogger auditLogger = Framework.getService(AuditLogger.class);
    List<LogEntry> entries = new ArrayList<>();
    LOGGER.warn("Conversion in progress for document: {}", documentId);

    if (documentId != null ) {
        addAuditEntry(auditLogger, entries, documentId, "Conversion in progress");
    }

        try {
            Map<String, Serializable> parameters = new HashMap<>(namedParameters);
            LOGGER.info("Calling AsposeService.convert()");
            LOGGER.info("Named Parameters : {}", parameters);
            BlobHolder serviceResult = service.convert(blobHolder, parameters);
            Blob resultBlob = serviceResult.getBlob();
            if (resultBlob != null) {
                LOGGER.info("Aspose conversion successful.");
                LOGGER.info("Result Filename : {}", resultBlob.getFilename());
                LOGGER.info("Result MimeType : {}", resultBlob.getMimeType());
                LOGGER.info("Result Length   : {}", resultBlob.getLength());
            }
            else {
                LOGGER.warn("Aspose returned NULL Blob.");
            }
            if (documentId != null) {
                LOGGER.warn("Conversion done for document: {}", documentId);
                addAuditEntry(auditLogger, entries, documentId, "Conversion done");
            }

            return resultBlob;

        } catch (Exception e) {
            if (documentId != null) {
                String errorMessage = "Conversion failed for document: " + documentId + ". Error: " + e.getMessage();
                LOGGER.error(errorMessage, e);
                LOGGER.error("Exception Class : {}", e.getClass().getName());
                LOGGER.error("Exception Message : {}", e.getMessage());

                for (StackTraceElement element : e.getStackTrace()) {
                    LOGGER.error(element.toString());
                }
                addAuditEntry(auditLogger, entries, documentId, "Conversion failed: " + e.getMessage());
                LOGGER.info("Adding audit entry...");
                LOGGER.info("Repository  : default");
                LOGGER.info("Document Id : {}", documentId);
                LOGGER.info("User        : {}", session.getPrincipal().getName());
            }

            String errorMessage = "Conversion failed : " + e.getMessage();
            LOGGER.error(errorMessage, e);
            return null;
        }
    }

private void addAuditEntry(AuditLogger auditLogger, List<LogEntry> entries,
                           String documentId, String message) {
    LogEntry entry = auditLogger.newLogEntry();
    entry.setRepositoryId("default");
    entry.setEventId("documentConversion");
    entry.setCategory("eventDocumentCategory");
    entry.setPrincipalName(session.getPrincipal().getName());
    entry.setEventDate(new Date());
    entry.setDocUUID(documentId);
    entry.setComment(message);
    entries.add(entry);
    auditLogger.addLogEntries(entries);

    LOGGER.info("Audit entry successfully stored.");
    LOGGER.warn("Audit log added: Document ID: {}, Event: {}", documentId, message);

}

Hi, @Manish7320
Please provide a code snippet showing the specific Aspose Cloud API method being called and the parameters passed, and also attach a sample file for conversion.

Hello @kirill.novinskiy

Thank you for your response.

We have reviewed our source code and could not find any usage of the Aspose Cloud API methods in our implementation.

However, since this issue is having a significant impact on our business users, we would appreciate your guidance on the following:

  1. Based on the information available so far, what potential root causes are currently being considered by your team?
  2. Could you please provide an approximate timeline for the investigation and resolution, if available?

Your assistance and any updates you can share would be greatly appreciated, as this is a high-priority issue for our business.

Thank you for your support.

Hi, @Manish7320
We need you to provide a code example of the API method call and a sample document that reproduces the error. Once you provide the necessary information, we will investigate the issue.