/// <summary> /// Export to PDF on Button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void Exportbutton_Click(object sender, EventArgs e) { var converter = new GridPDFConverter(); var lowest = 0; //Adding PageBreaks to a list. var rows = new List <int> { 30, 63, 90, 130, 150 }; var pdfDocument = new PdfDocument(); pdfDocument.Save("Sample.pdf"); foreach (var rownumber in rows) { var pdf = new PdfDocument(); var maximumRow = rownumber; converter.ExportToPdf(pdf, gridControl1, GridRangeInfo.Rows(lowest, maximumRow)); var stream = new MemoryStream(); pdf.Save(stream); var loadedDocument = new PdfLoadedDocument("Sample.pdf"); loadedDocument = PdfDocumentBase.Merge(loadedDocument, new PdfLoadedDocument(stream)) as PdfLoadedDocument; loadedDocument.Save("Sample.pdf"); loadedDocument.Close(true); stream.Dispose(); lowest = maximumRow + 1; } var loadedDocument1 = new PdfLoadedDocument("Sample.pdf"); loadedDocument1.Pages.RemoveAt(0); loadedDocument1.Save("Sample.pdf"); Process.Start("Sample.pdf"); }
public MemoryStream GetPdf(string html) { HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(HtmlRenderingEngine.WebKit); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = @"../../QtBinariesDotNetCore/"; settings.Margin = new Syncfusion.Pdf.Graphics.PdfMargins { All = 30 }; settings.PdfPageSize = new SizeF(512, 692); settings.WebKitViewPort = new Size(800, 0); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF PdfDocument document = htmlConverter.Convert(html, ""); string filePath = "D:\\DemoProjects\\Movers\\MoversApi\\temp\\RevisedEstimate_back.pdf"; FileStream fileStream = new FileStream(filePath, FileMode.Open); PdfLoadedDocument loadedDocument = new PdfLoadedDocument(fileStream); //Save and close the PDF document MemoryStream stream = new MemoryStream(); PdfDocumentBase.Merge(document, loadedDocument); document.Save(stream); document.Close(true); return(stream); }
private static void Merger(PdfLoadedDocument doc, object[] dobj) { if (dobj != null && dobj.Length > 0) { PdfDocumentBase.Merge(doc, dobj); } }
//method to get menu for restaurant private void PopulateMenuTab(JObject json) { if (json["Menus"].Type == JTokenType.Null || string.IsNullOrEmpty(json["Menus"].ToString()) || !json["Menus"].Any()) { pdfViewerControl.IsVisible = false; MenuLabel.Text = "No Menus Currently Available."; } else { int menuLength = json["Menus"].Count(); //Create a new PDF document PdfDocument document = new PdfDocument(); var listMenu = new List <byte[]>(); for (int i = 0; i < menuLength; i++) { //Provide the PDF document URL in the below overload. var pdfUrl = json["Menus"][i]["StorageUrl"].ToString(); try { //Returns the PDF document from the given URL var documenStream = DownloadPdfStream(pdfUrl); listMenu.Add(documenStream); } catch (WebException wex) { if (wex.Source != null) { Console.WriteLine("WebException source: {0}", wex.Source); } throw; } } PdfMergeOptions mergeOptions = new PdfMergeOptions { //Enable Optimize Resources OptimizeResources = true }; //Merge the documents PdfDocumentBase.Merge(document, mergeOptions, listMenu.ToArray()); //Save the PDF document to stream MemoryStream stream = new MemoryStream(); document.Save(stream); //Close the documents document.Close(true); pdfViewerControl.LoadDocument(stream); } }
public IActionResult pdf(int id) { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(hosting.ContentRootPath, "QtBinariesWindows"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF Application mrki = _db.Application.Where(a => a.ApplicationId == id).Include(b => b.Applicant).ThenInclude(c => c.ApplicationUser).Include(d => d.Infos).ThenInclude(q => q.Citizenship).Include(e => e.HomeInstitutions).Include(f => f.Languages).Include(g => g.Contacts).ThenInclude(z => z.Country).Include(h => h.Documents).Include(i => i.Others).FirstOrDefault(); PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. PdfPage pdfPage = pdfDocument.Pages.Add(); PdfPage pdfPage2 = pdfDocument.Pages.Add(); //Create a PDF Template. PdfTemplate template = new PdfTemplate(900, 900); PdfTemplate template2 = new PdfTemplate(900, 900); //Draw a rectangle on the template graphics template.Graphics.DrawRectangle(PdfBrushes.White, new Syncfusion.Drawing.RectangleF(0, 0, 900, 900)); template2.Graphics.DrawRectangle(PdfBrushes.White, new Syncfusion.Drawing.RectangleF(0, 0, 900, 900)); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); PdfFont font2 = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfFont font3 = new PdfStandardFont(PdfFontFamily.Helvetica, 16); PdfBrush brush = new PdfSolidBrush(Color.Black); //Draw a string using the graphics of the template. RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 52); PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); //Load the PDF document FileStream imageStream = new FileStream("unmo_logo.png", FileMode.Open, FileAccess.Read); PdfImage image = new PdfBitmap(imageStream); //Draw the image in the header. header.Graphics.DrawImage(image, new PointF(75, 0), new SizeF(137, 52)); header.Graphics.DrawString("Application number " + mrki.ApplicationId, font2, brush, 205, 12); //Add the header at the top. pdfDocument.Template.Top = header; template.Graphics.DrawString("About", font3, brush, 10, 17); template.Graphics.DrawString("Full name: ", font, brush, 32, 42); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Name + " " + mrki.Applicant.ApplicationUser.Surname, font, brush, 280, 42); template.Graphics.DrawString("Account created: ", font, brush, 32, 57); template.Graphics.DrawString(mrki.Applicant.CreatedProfile.ToString(), font, brush, 280, 57); template.Graphics.DrawString("Application created: ", font, brush, 32, 72); template.Graphics.DrawString(mrki.CreatedApp.ToString(), font, brush, 280, 72); template.Graphics.DrawString("Application submitted: ", font, brush, 32, 87); template.Graphics.DrawString(mrki.FinishedTime.ToString(), font, brush, 280, 87); template.Graphics.DrawString("Information", font3, brush, 10, 107); template.Graphics.DrawString("Gender: ", font, brush, 32, 132); template.Graphics.DrawString(mrki.Infos.Gender, font, brush, 280, 132); template.Graphics.DrawString("Date of birth: ", font, brush, 32, 149); template.Graphics.DrawString(mrki.Infos.DateOfBirth.ToShortDateString(), font, brush, 280, 149); template.Graphics.DrawString("Place of birth: ", font, brush, 32, 166); template.Graphics.DrawString(mrki.Infos.PlaceOfBirth.ToString(), font, brush, 280, 166); template.Graphics.DrawString("Citizenship: ", font, brush, 32, 183); template.Graphics.DrawString(mrki.Infos.Citizenship.Name.ToString(), font, brush, 280, 183); template.Graphics.DrawString("Passport number: ", font, brush, 32, 200); template.Graphics.DrawString(mrki.Infos.PassportNumber.ToString(), font, brush, 280, 200); template.Graphics.DrawString("Passport issue date: ", font, brush, 32, 217); template.Graphics.DrawString(mrki.Infos.PassportIssueDate.ToShortDateString(), font, brush, 280, 217); template.Graphics.DrawString("Passport expiry date: ", font, brush, 32, 234); template.Graphics.DrawString(mrki.Infos.PassportExpiryDate.ToShortDateString(), font, brush, 280, 234); template.Graphics.DrawString("Contacts", font3, brush, 10, 259); template.Graphics.DrawString("E-mail: ", font, brush, 32, 284); template.Graphics.DrawString(mrki.Contacts.Email.ToString(), font, brush, 280, 284); template.Graphics.DrawString("Phone number: ", font, brush, 32, 301); template.Graphics.DrawString(mrki.Contacts.Telephone.ToString(), font, brush, 280, 301); template.Graphics.DrawString("Street name: ", font, brush, 32, 318); template.Graphics.DrawString(mrki.Contacts.StreetName.ToString(), font, brush, 280, 318); template.Graphics.DrawString("City, town, village: ", font, brush, 32, 335); template.Graphics.DrawString(mrki.Contacts.PlaceName.ToString(), font, brush, 280, 335); template.Graphics.DrawString("Postal code: ", font, brush, 32, 352); template.Graphics.DrawString(mrki.Contacts.PostalCode.ToString(), font, brush, 280, 352); template.Graphics.DrawString("Country of residence: ", font, brush, 32, 369); template.Graphics.DrawString(mrki.Contacts.Country.Name.ToString(), font, brush, 280, 369); template.Graphics.DrawString("Languages", font3, brush, 10, 394); template.Graphics.DrawString("Native language: ", font, brush, 32, 419); template.Graphics.DrawString(mrki.Languages.Native.ToString(), font, brush, 280, 419); template.Graphics.DrawString("First foreign language: ", font, brush, 32, 436); string ff = mrki.Languages.ForeignFirst + " | " + mrki.Languages.ForeignFirstProficiency; template.Graphics.DrawString(ff, font, brush, 280, 436); template.Graphics.DrawString("Second foreign language: ", font, brush, 32, 453); string sf = mrki.Languages.ForeignSecond + " | " + mrki.Languages.ForeignSecondProficiency; template.Graphics.DrawString(sf, font, brush, 280, 453); template.Graphics.DrawString("Third foreign language: ", font, brush, 32, 470); string tf = mrki.Languages.ForeignThird + " | " + mrki.Languages.ForeignThirdProficiency; template.Graphics.DrawString(tf, font, brush, 280, 470); template.Graphics.DrawString("Number of foreign experiences: ", font, brush, 32, 487); template.Graphics.DrawString(mrki.Languages.ForeignExperienceNumber.ToString(), font, brush, 280, 487); template.Graphics.DrawString("Home institution", font3, brush, 10, 512); template.Graphics.DrawString("University: ", font, brush, 32, 537); template.Graphics.DrawString(mrki.HomeInstitutions.OfficialName.ToString(), font, brush, 280, 537); //template.Graphics.DrawString("Faculty: ", font, brush, 5, 335); //template.Graphics.DrawString(mrki.Applicant.FacultyName.ToString(), font, brush, 280, 335); template.Graphics.DrawString("Department name: ", font, brush, 32, 554); template.Graphics.DrawString(mrki.HomeInstitutions.DepartmentName.ToString(), font, brush, 280, 554); template.Graphics.DrawString("Study programme: ", font, brush, 32, 571); template.Graphics.DrawString(mrki.HomeInstitutions.StudyProgramme.ToString(), font, brush, 280, 571); template.Graphics.DrawString("Study cycle: ", font, brush, 32, 588); template.Graphics.DrawString(mrki.Applicant.StudyCycle, font, brush, 280, 588); template.Graphics.DrawString("Current term/year: ", font, brush, 32, 605); template.Graphics.DrawString(mrki.HomeInstitutions.CurrentTermOrYear.ToString(), font, brush, 280, 605); template.Graphics.DrawString("Coordinator full name: ", font, brush, 32, 622); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorFullName.ToString(), font, brush, 280, 622); template.Graphics.DrawString("Coordinator e-mail: ", font, brush, 32, 639); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorEmail.ToString(), font, brush, 280, 639); template.Graphics.DrawString("Coordinator phone number: ", font, brush, 32, 656); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorPhoneNum.ToString(), font, brush, 280, 656); template.Graphics.DrawString("Coordinator address: ", font, brush, 32, 673); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorAddress.ToString(), font, brush, 280, 673); template.Graphics.DrawString("Coordinator position: ", font, brush, 32, 690); template.Graphics.DrawString(mrki.HomeInstitutions.CoordinatorPosition.ToString(), font, brush, 280, 690); template2.Graphics.DrawString("Others", font3, brush, 10, 5); template2.Graphics.DrawString("Medical info: ", font, brush, 32, 30); template2.Graphics.DrawString(mrki.Others.MedicalInfo.ToString(), font, brush, 280, 30); template2.Graphics.DrawString("Additional requests: ", font, brush, 32, 47); template2.Graphics.DrawString(mrki.Others.AdditionalRequests.ToString(), font, brush, 280, 47); var path1 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.LearningAgreement); var path2 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.CV); var path3 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.EngProficiency); var path4 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.TranscriptOfRecords); var path5 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.MotivationLetter); var path6 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Documents.ReferenceLetter); FileStream stream1 = new FileStream(path1, FileMode.Open, FileAccess.Read); FileStream stream2 = new FileStream(path2, FileMode.Open, FileAccess.Read); FileStream stream3 = new FileStream(path3, FileMode.Open, FileAccess.Read); FileStream stream4 = new FileStream(path4, FileMode.Open, FileAccess.Read); FileStream stream5 = new FileStream(path5, FileMode.Open, FileAccess.Read); //FileStream stream6 = new FileStream(path6, FileMode.Open, FileAccess.Read); // Creates a PDF stream for merging Stream[] streams = { stream1, stream2, stream3, stream4, stream5 };// stream6 }; // Merges PDFDocument. PdfDocumentBase.Merge(pdfDocument, streams); ////Draw the template on the page graphics of the document. pdfPage.Graphics.DrawPdfTemplate(template, PointF.Empty); pdfPage2.Graphics.DrawPdfTemplate(template2, PointF.Empty); //Save the document into stream MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); stream.Position = 0; pdfDocument.Close(true); //Define the file name FileStreamResult nova = new FileStreamResult(stream, "application/pdf"); string nameOfFile = "Application_" + mrki.ApplicationId + "_" + mrki.Applicant.ApplicationUser.Name + "_" + mrki.Applicant.ApplicationUser.Surname + ".pdf"; nova.FileDownloadName = nameOfFile; return(nova); }
public IActionResult pdf(int id) { //Initialize HTML to PDF converter HtmlToPdfConverter htmlConverter = new HtmlToPdfConverter(); WebKitConverterSettings settings = new WebKitConverterSettings(); //Set WebKit path settings.WebKitPath = Path.Combine(hosting.ContentRootPath, "QtBinariesWindows"); //Assign WebKit settings to HTML converter htmlConverter.ConverterSettings = settings; //Convert URL to PDF Nomination mrki = _db.Nomination.Where(a => a.NominationId == id).Include(b => b.Applicant).ThenInclude(q => q.University).Include(b => b.Applicant).ThenInclude(c => c.ApplicationUser).ThenInclude(x => x.Country).FirstOrDefault(); PdfDocument pdfDocument = new PdfDocument(); //Add a page to the PDF document. PdfPage pdfPage = pdfDocument.Pages.Add(); //Create a PDF Template. PdfTemplate template = new PdfTemplate(900, 900); //Draw a rectangle on the template graphics template.Graphics.DrawRectangle(PdfBrushes.White, new Syncfusion.Drawing.RectangleF(0, 0, 900, 900)); PdfFont font = new PdfStandardFont(PdfFontFamily.Helvetica, 12); PdfFont font2 = new PdfStandardFont(PdfFontFamily.Helvetica, 20); PdfFont font3 = new PdfStandardFont(PdfFontFamily.Helvetica, 16); PdfBrush brush = new PdfSolidBrush(Color.Black); //Draw a string using the graphics of the template. RectangleF bounds = new RectangleF(0, 0, pdfDocument.Pages[0].GetClientSize().Width, 52); //dirao PdfPageTemplateElement header = new PdfPageTemplateElement(bounds); //Load the PDF document FileStream imageStream = new FileStream("unmo_logo.png", FileMode.Open, FileAccess.Read); PdfImage image = new PdfBitmap(imageStream); //Draw the image in the header. header.Graphics.DrawImage(image, new PointF(75, 0), new SizeF(137, 52)); header.Graphics.DrawString("Nomination number " + mrki.NominationId, font2, brush, 205, 12); //Add the header at the top. pdfDocument.Template.Top = header; template.Graphics.DrawString("Full name: ", font, brush, 32, 15); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Name + " " + mrki.Applicant.ApplicationUser.Surname, font, brush, 280, 15); template.Graphics.DrawString("Account created: ", font, brush, 32, 30); template.Graphics.DrawString(mrki.Applicant.CreatedProfile.ToString(), font, brush, 280, 30); template.Graphics.DrawString("Nomination created: ", font, brush, 32, 45); template.Graphics.DrawString(mrki.CreatedNom.ToString(), font, brush, 280, 45); template.Graphics.DrawString("Nomination submitted: ", font, brush, 32, 60); template.Graphics.DrawString(mrki.FinishedTime.ToString(), font, brush, 280, 60); template.Graphics.DrawString("Information", font3, brush, 10, 87); template.Graphics.DrawString("E-mail: ", font, brush, 32, 112); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Email.ToString(), font, brush, 280, 112); template.Graphics.DrawString("Phone number: ", font, brush, 32, 127); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.PhoneNumber.ToString(), font, brush, 280, 127); template.Graphics.DrawString("Nationality: ", font, brush, 32, 142); template.Graphics.DrawString(mrki.Applicant.ApplicationUser.Country.Name.ToString(), font, brush, 280, 142); template.Graphics.DrawString("Faculty: ", font, brush, 32, 157); template.Graphics.DrawString(mrki.Applicant.FacultyName.ToString(), font, brush, 280, 157); template.Graphics.DrawString("University: ", font, brush, 32, 172); template.Graphics.DrawString(mrki.Applicant.University.Name.ToString(), font, brush, 280, 172); template.Graphics.DrawString("Student/staff: ", font, brush, 32, 187); template.Graphics.DrawString(mrki.Applicant.TypeOfApplication.ToString(), font, brush, 280, 187); var path1 = ""; if (mrki.LearningAgreement != null) { path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.LearningAgreement); } else if (mrki.WorkPlan != null) { path1 = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.WorkPlan); } var path2 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.CV); var pathx = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.Passport); var path3 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.EngProficiency); var path4 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.TranscriptOfRecords); var path5 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.MotivationLetter); var path6 = Path.Combine( Directory.GetCurrentDirectory(), "wwwroot\\uploads\\", mrki.ReferenceLetter); FileStream stream1 = new FileStream(path1, FileMode.Open, FileAccess.Read); FileStream stream2 = new FileStream(path2, FileMode.Open, FileAccess.Read); FileStream streamx = new FileStream(pathx, FileMode.Open, FileAccess.Read); FileStream stream3 = new FileStream(path3, FileMode.Open, FileAccess.Read); FileStream stream4 = new FileStream(path4, FileMode.Open, FileAccess.Read); FileStream stream5 = new FileStream(path5, FileMode.Open, FileAccess.Read); // Creates a PDF stream for merging Stream[] streams = { stream1, stream2, stream3, streamx, stream4, stream5 }; // Merges PDFDocument. PdfDocumentBase.Merge(pdfDocument, streams); ////Draw the template on the page graphics of the document. pdfPage.Graphics.DrawPdfTemplate(template, PointF.Empty); //Save the document into stream MemoryStream stream = new MemoryStream(); pdfDocument.Save(stream); stream.Position = 0; pdfDocument.Close(true); //Define the file name FileStreamResult nova = new FileStreamResult(stream, "nomination/pdf"); string nameOfFile = "Nomination_" + mrki.NominationId + "_" + mrki.Applicant.ApplicationUser.Name + "_" + mrki.Applicant.ApplicationUser.Surname + ".pdf"; nova.FileDownloadName = nameOfFile; return(nova); }