static void Main() { //Configure the logging ConfigureLogging(); Stream inputStream = File.OpenRead(@"createPdfInput.docx"); 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); CreatePDFOperation createPdfOperation = CreatePDFOperation.CreateNew(); // Set operation input from the source stream by specifying the stream media type. FileRef source = FileRef.CreateFromStream(inputStream, CreatePDFOperation.SupportedSourceFormat.DOCX.GetMediaType()); createPdfOperation.SetInput(source); // Execute the operation. FileRef result = createPdfOperation.Execute(executionContext); // Save the result to the specified location. result.SaveAs(Directory.GetCurrentDirectory() + "/output/createPDFFromDOCXStream.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); } finally { inputStream.Close(); } }