Exemplo n.º 1
0
        static void Main(string[] args)
        {
            try
            {
                // ** Make sure an api key has been entered
                if (API_KEY == string.Empty)
                {
                    Console.WriteLine("[ERROR] Please update the sample code and enter the API Key that came with your subscription.");
                    return;
                }

                // ** Specify the API key associated with your subscription.
                Configuration.Default.AddApiKey("api_key", API_KEY);

                // ** Accept all SSL Certificates, this makes life under mono a lot easier. This line is not needed on Windows
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                // ** The service's host name is already set, but for debugging purposes you may want to switch between 'http' and 'https'.'
                Configuration.Default.ApiClient.RestClient.BaseUrl = new Uri("https://api.muhimbi.com/api");

                // ** We are dealing with merging, so instantiate the relevant class
                MergeApi mergeApi = new MergeApi();

                // ** Specify details about the SharePoint environment, and the files to merge
                SharepointFile spf = new SharepointFile(
                    SiteUrl: "https://acme.sharepoint.com/sites/SomeSite",                  // ** URL to the site collection, e.g. https://acme.sharepoint.com/sites/SomeSite
                    SourceFileUrl:                                                          // ** List of files to merge including optional ';' separated parameters.
                                                                                            // **   filepath;generate bookmarks (optional);name of bookmark (Optional)
                    @"Shared Documents\SomeFolder\SomeFile.docx;true;My Bookmark
                          Shared Documents\SomeFolder\SomeFile.xlsx;false",
                    DestinationFileUrl: @"Shared Documents\MergedFile.pdf",                 // ** Path and filename to write the results to. See http://goo.gl/YqKXM
                    Username: null,                                                         // ** If the Muhimbi App is installed on the site collection then there is no
                    Password: null                                                          // ** no need to specify credentials. If App is not present, specify login details.
                    );

                // ** Fill out the data for the merge operation.
                MergeToPdfData inputData = new MergeToPdfData(
                    SharepointFile: spf,                                                    // ** Details for the merge operation, see above.
                    SharepointFieldName: "Title",                                           // ** SharePoint field name to use to automatically create a bookmark for each file
                    DocumentStartPage: MergeToPdfData.DocumentStartPageEnum.Nextpage,       // ** On what page should each merged document start (important for double sided docs and printing).
                    SourceFileName1: "",                                                    // ** Mandatory field, so specify empty data
                    SourceFileContent1: new byte[] { 0 },                                   // ** Mandatory field, so specify empty data
                    SourceFileName2: "",                                                    // ** Mandatory field, so specify empty data
                    SourceFileContent2: new byte[] { 0 }                                    // ** Mandatory field, so specify empty data
                    );

                // ** Carry out the merge operation
                Console.WriteLine("[INFO] Merging...");
                var response = mergeApi.MergeToPdf(inputData);

                Console.WriteLine("[INFO] Operation completed - " + response.ResultCode);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            string testFile = null;

            try
            {
                // ** Make sure an api key has been entered
                if (API_KEY == string.Empty)
                {
                    Console.WriteLine("[ERROR] Please update the sample code and enter the API Key that came with your subscription.");
                    return;
                }

                // ** Was a 'file to merge' specified on the command line?
                if (args.Count() == 0)
                {
                    Console.WriteLine("[INFO] No file to merge specified, using default file.");
                    testFile = Directory.GetFiles(".", "*.doc")[0];
                }
                else
                {
                    testFile = args[0];
                }

                // ** Specify the API key associated with your subscription.
                Configuration.Default.AddApiKey("api_key", API_KEY);

                // ** Accept all SSL Certificates, this makes life under mono a lot easier. This line is not needed on Windows
                ServicePointManager.ServerCertificateValidationCallback = delegate { return(true); };

                // ** The service's host name is already set, but for debugging purposes you may want to switch between 'http' and 'https'.'
                Configuration.Default.ApiClient.RestClient.BaseUrl = new Uri("https://api.muhimbi.com/api");

                // ** We are dealing with merging, so instantiate the relevant class
                MergeApi mergeApi = new MergeApi();

                // ** Read the file we wish to Merge
                byte[] sourceFile = File.ReadAllBytes(testFile);

                // ** Fill out the data for the merge operation.
                MergeToPdfData inputData = new MergeToPdfData(
                    SourceFileName1: testFile + ";true;" + testFile,                                            // ** The name of the file to merge, always include the correct extension.
                                                                                                                //    Optionally add ';true' to auto generate PDF bookmarks based on document structure,
                                                                                                                //    optionally followed by a ';' and the PDF bookmark name of the document.
                    SourceFileContent1: sourceFile,                                                             // ** Content of the file to merge.
                    SourceFileName2: "test.html;true;Some HTML content",                                        // ** The same again, but as we are merging in HTML content, use a name with '.html' extension.
                    SourceFileContent2: System.Text.Encoding.Unicode.GetBytes("<h1>Merged HTML Content</h1>"),  // ** HTML or URL to convert and merge.
                    SourceFileName3: testFile + ";true;" + testFile + " (again).",                              // ** The same again for the 3rd file.
                    SourceFileContent3: sourceFile,                                                             // ** Content of the 3rd file to merge.
                    DocumentStartPage: MergeToPdfData.DocumentStartPageEnum.Nextpage                            // ** On what page should each merged document start (important for double sided docs and printing).
                    );

                // ** Carry out the merge operation
                Console.WriteLine("[INFO] Merging...");
                var response = mergeApi.MergeToPdf(inputData);

                // ** Write the results back to the file system
                File.WriteAllBytes(@"result.pdf", response.ProcessedFileContent);

                Console.WriteLine("[INFO] 'result.pdf' written to output folder.");

                // ** On Windows open the generated file in the system PDF viewer
                Process.Start(@"result.pdf");
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Merge documents Merge multiple files into a single PDF.
        /// </summary>
        /// <exception cref="Muhimbi.PDF.Online.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="inputData"></param>
        /// <returns>Task of OperationResponse</returns>
        public async System.Threading.Tasks.Task <OperationResponse> MergeToPdfAsync(MergeToPdfData inputData)
        {
            ApiResponse <OperationResponse> localVarResponse = await MergeToPdfAsyncWithHttpInfo(inputData);

            return(localVarResponse.Data);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Merge documents Merge multiple files into a single PDF.
        /// </summary>
        /// <exception cref="Muhimbi.PDF.Online.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="inputData"></param>
        /// <returns>Task of ApiResponse (OperationResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <OperationResponse> > MergeToPdfAsyncWithHttpInfo(MergeToPdfData inputData)
        {
            // verify the required parameter 'inputData' is set
            if (inputData == null)
            {
                throw new ApiException(400, "Missing required parameter 'inputData' when calling MergeApi->MergeToPdf");
            }

            var    localVarPath         = "/v1/operations/merge_to_pdf";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new Dictionary <String, String>();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "application/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            // set "format" to json by default
            // e.g. /pet/{petId}.{format} becomes /pet/{petId}.json
            localVarPathParams.Add("format", "json");
            if (inputData != null && inputData.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(inputData); // http body (model) parameter
            }
            else
            {
                localVarPostBody = inputData; // byte array
            }

            // authentication (oauth2_auth) required
            // oauth required
            if (!String.IsNullOrEmpty(Configuration.AccessToken))
            {
                localVarHeaderParams["Authorization"] = "Bearer " + Configuration.AccessToken;
            }
            // authentication (api_key) required
            if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("api_key")))
            {
                localVarHeaderParams["api_key"] = Configuration.GetApiKeyWithPrefix("api_key");
            }

            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("MergeToPdf", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <OperationResponse>(localVarStatusCode,
                                                       localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                       (OperationResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(OperationResponse))));
        }
Exemplo n.º 5
0
        /// <summary>
        /// Merge documents Merge multiple files into a single PDF.
        /// </summary>
        /// <exception cref="Muhimbi.PDF.Online.Client.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="inputData"></param>
        /// <returns>OperationResponse</returns>
        public OperationResponse MergeToPdf(MergeToPdfData inputData)
        {
            ApiResponse <OperationResponse> localVarResponse = MergeToPdfWithHttpInfo(inputData);

            return(localVarResponse.Data);
        }