private byte[] ConvertHtml(string html) { try { // enter your Pdfcrowd credentials to the converter's constructor pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient( "demo", "ce544b6ea52a5621fb9d55f8b542d14d"); if(partForConversion.SelectedValue != "all") { // convert just selected part of the page client.setElementToConvert(partForConversion.SelectedValue); } // run the conversion and write the result to a file return client.convertString(html); } catch (pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // handle the exception here or rethrow and handle it at a higher level throw new HttpException(why.ToString()); } }
private byte[] ConvertHtml(string html) { try { // enter your Pdfcrowd credentials to the converter's constructor pdfcrowd.HtmlToPdfClient client = new pdfcrowd.HtmlToPdfClient( "your_username", "your_apikey"); // run the conversion and write the result to a file return(client.convertString(html)); } catch (pdfcrowd.Error why) { // report the error System.Console.Error.WriteLine("Pdfcrowd Error: " + why); // handle the exception here or rethrow and handle it at a higher level throw new HttpException(why.ToString()); } }
private async Task <IEndpointResult> ProcessPushToEmailRequestAsync(HttpContext context) { _logger.LogDebug("Start register request"); string users; using (var reader = new StreamReader(context.Request.Body)) { users = reader.ReadToEnd(); // Do something else } var message = JsonConvert.DeserializeObject <MessageEmail>(users); var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("*****@*****.**", "dtech2020cgoindonesia"), EnableSsl = true }; var msg = new MailMessage("*****@*****.**", message.To, message.Subject, message.Message) { IsBodyHtml = true }; string pathFile = ""; if (message.Attachment != null) { foreach (var attach in message.Attachment) { StringReader sr = new StringReader(attach.AttachmentFileUrl); //Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); //HTMLWorker htmlparser = new HTMLWorker(pdfDoc); FileStream file; using (MemoryStream memoryStream = new MemoryStream()) { //PdfWriter writer = PdfWriter.GetInstance(pdfDoc, memoryStream); //pdfDoc.Open(); //try //{ // htmlparser.Parse(sr); //} //catch (Exception e) //{ //} //pdfDoc.Close(); // create the API client instance PRD //pdfcrowd.HtmlToPdfClient clientPdfCrowd = // new pdfcrowd.HtmlToPdfClient("cgoindonesia", "cef1b4478dac7cf83c26cac11340fbd4"); // create the API client instance DEV pdfcrowd.HtmlToPdfClient clientPdfCrowd = new pdfcrowd.HtmlToPdfClient("demo", "ce544b6ea52a5621fb9d55f8b542d14d"); // configure the conversion clientPdfCrowd.setPageSize("A4"); clientPdfCrowd.setNoMargins(true); //PaperSize size = PaperSize.A4; //var pdf = Pdf.From(message.AttachmentFileUrl).OfSize(size); byte[] bytes = clientPdfCrowd.convertString(attach.AttachmentFileUrl); //byte[] bytes = memoryStream.ToArray(); memoryStream.Close(); using (var fs = new FileStream(attach.FileName, FileMode.Create, FileAccess.Write)) { fs.Write(bytes, 0, bytes.Length); file = fs; } } //File.WriteAllBytes("C:\\Test.pdf", content); System.Net.Mail.Attachment attachment = new System.Net.Mail.Attachment(file.Name); msg.Attachments.Add(attachment); pathFile = file.Name; file.Dispose(); } } client.Send(msg); msg.Attachments.Dispose(); if (pathFile != "") { try { File.Delete(pathFile); } catch (Exception e) { throw e; } } //File.Delete("ticket.pdf"); return(new SendingEmailResult(message)); }