Getting 'Error response received for the request: A connection attempt failed
- April 16, 2024
- 1 reply
- 294 views
I am getting the below error when trying to convert PDF to Excel.
Adobe.PDFServicesSDK.exception.ServiceApiException: 'Error response received for the request: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. (pdf-services.adobe.io:443)'
i am using below code to convert the data with free tier of Adobe credentials.
using Adobe.PDFServicesSDK;
using Adobe.PDFServicesSDK.auth;
using Adobe.PDFServicesSDK.exception;
using Adobe.PDFServicesSDK.io;
using Adobe.PDFServicesSDK.options.exportpdf;
using Adobe.PDFServicesSDK.pdfops;
using System;
using System.IO;
using System.Reflection;
try
{
// Initial setup, create credentials instance.
Credentials credentials = Credentials.ServicePrincipalCredentialsBuilder()
.WithClientId("1dc3e457fe79489897cc229d57ae107c")
.WithClientSecret("p8e-UM_dJ_0l_Seb0dTRi4Oi6voIAhGWXiJb")
.Build();
string fileName = "P123879.pdf";
string filePath = System.IO.Path.Combine("E:\\AdobePDF\\PDF Scrapping\\ConsoleApp1", @"Files\", fileName);
//Create an ExecutionContext using credentials and create a new operation instance.
Adobe.PDFServicesSDK.ExecutionContext executionContext = Adobe.PDFServicesSDK.ExecutionContext.Create(credentials);
ExportPDFOperation exportPdfOperation = ExportPDFOperation.CreateNew(ExportPDFTargetFormat.DOCX);
// Set operation input from a local PDF file
FileRef sourceFileRef = FileRef.CreateFromLocalFile(filePath);
exportPdfOperation.SetInput(sourceFileRef);
// Execute the operation.
FileRef result = exportPdfOperation.Execute(executionContext);
//Generating a file name
String outputFilePath = CreateOutputFilePath();
// Save the result to the specified location.
result.SaveAs(Directory.GetCurrentDirectory() + outputFilePath);
}
catch (ServiceUsageException ex)
{
Console.WriteLine("Exception encountered while executing operation", ex);
}
catch (ServiceApiException ex)
{
Console.WriteLine("Exception encountered while executing operation", ex);
}
catch (SDKException ex)
{
Console.WriteLine("Exception encountered while executing operation", ex);
}
catch (IOException ex)
{
Console.WriteLine("Exception encountered while executing operation", ex);
}
catch (Exception ex)
{
Console.WriteLine("Exception encountered while executing operation", ex);
}
static string CreateOutputFilePath()
{
String timeStamp = DateTime.Now.ToString("yyyy'-'MM'-'dd'T'HH'-'mm'-'ss");
return ("/output/export" + timeStamp + ".docx");
}
getting the issue in the highlighted red line of code.
we have whitelisted both the required URLs :
1) https://developer.adobe.com/document-services/docs/overview/pdf-extract-api/
2) https://pdf-services.adobe.io/
please let us know why we are getting the above issue as we are using same code which is being provided in the zip file with free tier.
