Exemplo n.º 1
0
        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);
                CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

                // Create a FileRef instance from a local file.
                FileRef    firstFileToCombine     = FileRef.CreateFromLocalFile(@"combineFileWithPageRangeInput1.pdf");
                PageRanges pageRangesForFirstFile = GetPageRangeForFirstFile();
                // Add the first file as input to the operation, along with its page range.
                combineFilesOperation.AddInput(firstFileToCombine, pageRangesForFirstFile);

                // Create a second FileRef instance using a local file.
                FileRef    secondFileToCombine     = FileRef.CreateFromLocalFile(@"combineFileWithPageRangeInput2.pdf");
                PageRanges pageRangesForSecondFile = GetPageRangeForSecondFile();
                // Add the second file as input to the operation, along with its page range.
                combineFilesOperation.AddInput(secondFileToCombine, pageRangesForSecondFile);

                // Execute the operation.
                FileRef result = combineFilesOperation.Execute(executionContext);

                // Save the result to the specified location.
                result.SaveAs(Directory.GetCurrentDirectory() + "/output/combineFilesOutput.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() + "/pdftools-api-credentials.json")
                                          .Build();

                //Create an ExecutionContext using credentials and create a new operation instance.
                ExecutionContext      executionContext      = ExecutionContext.Create(credentials);
                CombineFilesOperation combineFilesOperation = CombineFilesOperation.CreateNew();

                // Add operation input from source files.
                FileRef combineSource1 = FileRef.CreateFromLocalFile(@"combineFilesInput1.pdf");
                FileRef combineSource2 = FileRef.CreateFromLocalFile(@"combineFilesInput2.pdf");
                combineFilesOperation.AddInput(combineSource1);
                combineFilesOperation.AddInput(combineSource2);

                // Execute the operation.
                FileRef result = combineFilesOperation.Execute(executionContext);

                // Save the result to the specified location.
                result.SaveAs(Directory.GetCurrentDirectory() + "/output/combineFilesOutput.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);
            }
        }