Copy link to clipboard
I am using the virtually standard code below to create a PDF from Url.
It is working perfectly when the targetUrl is my app in production (https://ffpro.ca/index) but failing at FileRef.CreateFromURI with an ServiceApiException when the targetUrl is my localhost (https://localhost:xxxxx/index )
Am I missing something? My Service Account credentials are clearly ok for production. I suspect that Adobe does not have access to my localhost but I don't know what to do to make this work in my development environment. I tried to disable Norton 360 or safe browser protection without success.
Thanks in advance
// Initial setup, create credentials instance.
Credentials credentials = Credentials.ServiceAccountCredentialsBuilder()
.FromFile(Directory.GetCurrentDirectory() + "/pdfservices-api-credentials.json")
//Create an ExecutionContext using credentials and create a new operation instance.
ExecutionContext executionContext = ExecutionContext.Create(credentials);
CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();
// Set operation input from a source URL.
//FileRef source = FileRef.CreateFromURI(new Uri("https://ffpro.ca/index")); // Working properly
FileRef source = FileRef.CreateFromURI(new Uri("https://localhost:xxxxx/index" )); // Failing properlyhtmlToPDFOperation.SetInput(source);
// Provide any custom configuration options for the operation.
// Execute the operation.
FileRef result = htmlToPDFOperation.Execute(executionContext);
// Save the result to the specified location.
string targetFile = Directory.GetCurrentDirectory() + "/wwwroot" + PDFReportPathName+PDFReportFileName;
catch (ServiceApiException ex)
log.Error("Exception encountered while executing operation", ex);}
Copy link to clipboard
The Adobe server needs access to a public URL. You won't be able to use localhost. If you need to generate PDF from HTML and alsio need to have a local dev environment, I recommend zipping the HTML payload and sending it using that method.
Thank you very much Joel for your reply and suggesstion. It makes a lot of sense.
I actually decided to use the converter from html to pdf from Syncfusion, one of my existing provider. I did not realize initially that they had such a service. I was able to implement both in my local environment and Azure production environment.