コード例 #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 the ConvertApi, so instantiate the relevant class
                ConvertApi convertAPI = new ConvertApi();

                // ** Fill out the data for the conversion operation.
                ConvertHtmlData inputData = new ConvertHtmlData(
                    SourceUrlOrHtml: "http://blog.muhimbi.com/2017/01/the-how-and-why-of-ocr-providing.html",   // ** The URL or raw HTML fragment, to convert
                    PageOrientation: ConvertHtmlData.PageOrientationEnum.Portrait,                              // ** The page orientation of the generated page
                    Username: null,                                                                             // ** Optional user name to authenticate using the specified AuthenticationType
                    Password: null,                                                                             // ** Optional password to authenticate using the specified AuthenticationType
                    AuthenticationType: ConvertHtmlData.AuthenticationTypeEnum.Basic                            // ** The type of authentication to use
                    );

                // ** Carry out the conversion
                Console.WriteLine("[INFO] Converting HTML...");
                var response = convertAPI.ConvertHtml(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());
            }
        }
コード例 #2
0
        /// <summary>
        /// Convert HTML to PDF Convert URLs or HTML to 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> > ConvertHtmlAsyncWithHttpInfo(ConvertHtmlData inputData)
        {
            // verify the required parameter 'inputData' is set
            if (inputData == null)
            {
                throw new ApiException(400, "Missing required parameter 'inputData' when calling ConvertApi->ConvertHtml");
            }

            var    localVarPath         = "/v1/operations/convert_html";
            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("ConvertHtml", 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))));
        }
コード例 #3
0
        /// <summary>
        /// Convert HTML to PDF Convert URLs or HTML to 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> ConvertHtmlAsync(ConvertHtmlData inputData)
        {
            ApiResponse <OperationResponse> localVarResponse = await ConvertHtmlAsyncWithHttpInfo(inputData);

            return(localVarResponse.Data);
        }
コード例 #4
0
        /// <summary>
        /// Convert HTML to PDF Convert URLs or HTML to 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 ConvertHtml(ConvertHtmlData inputData)
        {
            ApiResponse <OperationResponse> localVarResponse = ConvertHtmlWithHttpInfo(inputData);

            return(localVarResponse.Data);
        }