public async Task <IActionResult> MakePdf([FromBody] HtmlToPdfRequest htmlToPdfRequest) { var cacheId = Guid.NewGuid(); var pdfArguments = new PdfArguments("someFileName.pdf") { Orientation = htmlToPdfRequest.Orientation, ViewModel = htmlToPdfRequest.PdfBody, Margins = htmlToPdfRequest.Margins }; if (!string.IsNullOrWhiteSpace(htmlToPdfRequest.PdfHeader)) { CacheHeader(cacheId, htmlToPdfRequest.PdfHeader); pdfArguments.Header = new PdfHeader() { HtmlSourcePath = Url.Action(nameof(GetHeader), ControllerName, new { cacheId = cacheId }, Request.Scheme) }; } if (!string.IsNullOrWhiteSpace(htmlToPdfRequest.PdfFooter)) { CacheFooter(cacheId, htmlToPdfRequest.PdfFooter); pdfArguments.Footer = new PdfFooter() { HtmlSourcePath = Url.Action(nameof(GetFooter), ControllerName, new { cacheId = cacheId }, Request.Scheme) }; } var fileData = await PdfGenerator.GeneratePdfAsync(pdfArguments, ControllerContext); return(Ok(fileData)); }
public byte[] Web_HtmlToPdf(HtmlToPdfRequest req) { HttpClient httpClient = new HttpClient(); MultipartFormDataContent form = new MultipartFormDataContent(); //form.Add(new ByteArrayContent(inputBytes, 0, inputBytes.Length), "inputFile", fileName); httpClient.DefaultRequestHeaders.Add("Apikey", Apikey); string stringPayload = JsonConvert.SerializeObject(req); var httpContent = new StringContent(stringPayload, Encoding.UTF8, "application/json"); HttpResponseMessage response = httpClient.PostAsync("https://api.cloudmersive.com/convert/web/html/to/pdf", httpContent).Result; response.EnsureSuccessStatusCode(); httpClient.Dispose(); var sd = response.Content.ReadAsByteArrayAsync().Result;// ReadAsStringAsync().Result; return(sd); }
public IActionResult PreviewPdf([FromBody] HtmlToPdfRequest htmlToPdfRequest) { ViewData["Layout"] = htmlToPdfRequest.Orientation == Orientation.Landscape ? SCREEN_LAYOUT_LANDSCAPE : SCREEN_LAYOUT_PORTRAIT; return(View(htmlToPdfRequest)); }
/// <summary> /// Convert HTML string to PDF Fully renders a website and returns a PDF of the HTML. Javascript, HTML5, CSS and other advanced features are all supported. /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="input">HTML to PDF request parameters</param> /// <returns>Task of ApiResponse (Object)</returns> public async System.Threading.Tasks.Task <ApiResponse <Object> > ConvertWebHtmlToPdfAsyncWithHttpInfo(HtmlToPdfRequest input) { // verify the required parameter 'input' is set if (input == null) { throw new ApiException(400, "Missing required parameter 'input' when calling ConvertWebApi->ConvertWebHtmlToPdf"); } var localVarPath = "/convert/web/html/to/pdf"; var localVarPathParams = new Dictionary <String, String>(); var localVarQueryParams = new List <KeyValuePair <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", "text/json", "application/xml", "text/xml", "application/x-www-form-urlencoded" }; String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes); // to determine the Accept header String[] localVarHttpHeaderAccepts = new String[] { "application/json", "text/json", "application/xml", "text/xml" }; String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts); if (localVarHttpHeaderAccept != null) { localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept); } if (input != null && input.GetType() != typeof(byte[])) { localVarPostBody = Configuration.ApiClient.Serialize(input); // http body (model) parameter } else { localVarPostBody = input; // byte array } // authentication (Apikey) required if (!String.IsNullOrEmpty(Configuration.GetApiKeyWithPrefix("Apikey"))) { localVarHeaderParams["Apikey"] = Configuration.GetApiKeyWithPrefix("Apikey"); } // 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("ConvertWebHtmlToPdf", localVarResponse); if (exception != null) { throw exception; } } return(new ApiResponse <Object>(localVarStatusCode, localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()), (Object)Configuration.ApiClient.Deserialize(localVarResponse, typeof(Object)))); }
/// <summary> /// Convert HTML string to PDF Fully renders a website and returns a PDF of the HTML. Javascript, HTML5, CSS and other advanced features are all supported. /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="input">HTML to PDF request parameters</param> /// <returns>Task of Object</returns> public async System.Threading.Tasks.Task <Object> ConvertWebHtmlToPdfAsync(HtmlToPdfRequest input) { ApiResponse <Object> localVarResponse = await ConvertWebHtmlToPdfAsyncWithHttpInfo(input); return(localVarResponse.Data); }
/// <summary> /// Convert HTML string to PDF Fully renders a website and returns a PDF of the HTML. Javascript, HTML5, CSS and other advanced features are all supported. /// </summary> /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception> /// <param name="input">HTML to PDF request parameters</param> /// <returns>Object</returns> public Object ConvertWebHtmlToPdf(HtmlToPdfRequest input) { ApiResponse <Object> localVarResponse = ConvertWebHtmlToPdfWithHttpInfo(input); return(localVarResponse.Data); }