static void Main() { //Configure the logging ConfigureLogging(); try { // Initial setup, create credentials instance. Credentials credentials = Credentials.ServiceAccountCredentialsBuilder() .FromFile(Directory.GetCurrentDirectory() + "/pdftools-api-credentials.json") .Build(); //Create an ExecutionContext using credentials and create a new operation instance. ExecutionContext executionContext = ExecutionContext.Create(credentials); OCROperation ocrOperation = OCROperation.CreateNew(); // Set operation input from a source file. FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"ocrWithOptionsInput.pdf"); ocrOperation.SetInput(sourceFileRef); // Build OCR options from supported locales and OCR-types and set them into the operation OCROptions ocrOptions = OCROptions.OCROptionsBuilder() .WithOcrLocale(OCRSupportedLocale.EN_US) .WithOcrType(OCRSupportedType.SEARCHABLE_IMAGE_EXACT) .Build(); ocrOperation.SetOptions(ocrOptions); // Execute the operation. FileRef result = ocrOperation.Execute(executionContext); // Save the result to the specified location. result.SaveAs(Directory.GetCurrentDirectory() + "/output/ocrOperationWithOptionsOutput.pdf"); } catch (ServiceUsageException ex) { log.Error("Exception encountered while executing operation", ex); } catch (ServiceApiException ex) { log.Error("Exception encountered while executing operation", ex); } catch (SDKException ex) { log.Error("Exception encountered while executing operation", ex); } catch (IOException ex) { log.Error("Exception encountered while executing operation", ex); } catch (Exception ex) { log.Error("Exception encountered while executing operation", ex); } }
static void Main() { //Configure the logging ConfigureLogging(); try { // Initial setup, create credentials instance. Credentials credentials = Credentials.ServiceAccountCredentialsBuilder() .FromFile(Directory.GetCurrentDirectory() + "/pdfservices-api-credentials.json") .Build(); //Create an ExecutionContext using credentials and create a new operation instance. ExecutionContext executionContext = ExecutionContext.Create(credentials); OCROperation ocrOperation = OCROperation.CreateNew(); // Set operation input from a source file. FileRef sourceFileRef = FileRef.CreateFromLocalFile(@"ocrInput.pdf"); ocrOperation.SetInput(sourceFileRef); // Execute the operation. FileRef result = ocrOperation.Execute(executionContext); // Save the result to the specified location. result.SaveAs(Directory.GetCurrentDirectory() + "/output/ocrOperationOutput.pdf"); } catch (ServiceUsageException ex) { log.Error("Exception encountered while executing operation", ex); } catch (ServiceApiException ex) { log.Error("Exception encountered while executing operation", ex); } catch (SDKException ex) { log.Error("Exception encountered while executing operation", ex); } catch (IOException ex) { log.Error("Exception encountered while executing operation", ex); } catch (Exception ex) { log.Error("Exception encountered while executing operation", ex); } }