Question
Compressed pdf file size is undefined
I am trying to compress a PDF, and after compressing it, I need to get its file size. So, I tried the following code:
Node JS
// Initial setup, create credentials instance.
const credentials =
PDFServicesSdk.Credentials.servicePrincipalCredentialsBuilder()
.withClientId(clientId)
.withClientSecret(clientSecret)
.build();
// Create an ExecutionContext using credentials and create a new operation instance.
const executionContext =
PDFServicesSdk.ExecutionContext.create(credentials);
const compressPDF = PDFServicesSdk.CompressPDF;
const compressPDFOperation = compressPDF.Operation.createNew();
// Set operation input from a source file.
const input = PDFServicesSdk.FileRef.createFromLocalFile(fullFilePath);
compressPDFOperation.setInput(input);
// Provide any custom configuration options for the initial compression.
let compressionLevel =
PDFServicesSdk.CompressPDF.options.CompressionLevel.LOW;
const initialOptions = new compressPDF.options.CompressPDFOptions.Builder()
.withCompressionLevel(compressionLevel)
.build();
compressPDFOperation.setOptions(initialOptions);
// Execute the initial compression operation
const initialResult = await compressPDFOperation.execute(executionContext);
// Get the file size from the initial result without saving it
const initialFileSizeInBytes = initialResult.outputFileLength;
When I try to console.log initialResult, I get {}. Then, I tried initialFileSizeInBytes, but I get undefined. The file path is valid, but I didn't get the file size. Any help would be appreciated.
