public static void createPdfDocument(DataTable dt) { CURR_Y = Y_START; PAGE_COUNTER = 0; TOTAL_PAGE_NUMBER = 0; ROW_COUNTER = 0; string fileName = "OCTTReportMasterTimetable" + ".pdf"; PDFDOCUMENT = new PdfDocument(); PDFDOCUMENT.Info.Title = "OCTT Master Timetable Report"; PDFDOCUMENT.Info.Author = "Open Course Timetabler"; PDFDOCUMENT.Info.Subject = "Generated by Open Course Timetabler"; PdfPage myPage = createNewPage(); PAGE_COUNTER = 1; XGraphics gfx = XGraphics.FromPdfPage(myPage); double dab = System.Convert.ToDouble(dt.Rows.Count / 5.0);//5 rows per page double dde = Math.Ceiling(dab); TOTAL_PAGE_NUMBER = System.Convert.ToInt32(dde); createPageHeader(gfx, myPage); foreach (DataRow dr in dt.Rows) { //Console.WriteLine((string)dr[0]); ROW_COUNTER++; if (CURR_Y > 500) { myPage = createNewPage(); PAGE_COUNTER++; gfx = XGraphics.FromPdfPage(myPage); CURR_Y = Y_START; createPageHeader(gfx, myPage); } createTableRow(gfx, myPage, dr); } try { PDFDOCUMENT.Save(fileName); Process.Start(Settings.PDF_READER_APPLICATION, fileName); } catch (Exception e) { try { Process.Start(fileName); } catch (Exception e2) { MessageBox.Show(e2.Message); } } }
public void GetGraficObjectToDrawing(PdfPage page) { gfx = XGraphics.FromPdfPage(page); }
/// <summary> /// TODO: Separa função de PDF em helper de Demandas /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnPdf_Click(object sender, EventArgs e) { var linkButton = sender as LinkButton; if (linkButton == null) { return; } var idProcessoResposta = int.Parse(linkButton.CommandArgument); var listaProcesso = new Sebrae.Academico.BP.Services.SgusWebService.ManterProcesso().ObterDetalhamentoProcesso(idProcessoResposta); // Create a new PDF document var document = new PdfDocument(); var qtdEtapa = 0; var alturaLinha = 20; var margin = 30; var tamanhoTituloEtapa = 70; var posicaoInicialEtapa = 100; var padding = margin + 5; var alturaMaximaBlocoCampos = 700; foreach (var etapa in listaProcesso.Etapas) { // Create an empty page var page = document.AddPage(); page.Size = PdfSharp.PageSize.A4; page.Orientation = PdfSharp.PageOrientation.Portrait; // Get an XGraphics object for drawing var gfx = XGraphics.FromPdfPage(page); // Create a font var font = new XFont("Verdana", 10); var textFormatter = new XTextFormatter(gfx); var gruposCampos = new List <DTOBlocoCampo>(); var grupoIndex = 0; var alturaBloco = 0; foreach (var campo in etapa.ListaCampos) { var alturaCampo = CalcularAlturaCampo(gfx.MeasureString(campo.Titulo + ": " + campo.Resposta, font).Width, (int)page.Width, alturaLinha); alturaBloco += alturaCampo; // Atualizar a altura do bloco. if (gruposCampos.Any() && gruposCampos[grupoIndex] != null) { var altura = gruposCampos[grupoIndex].AlturaBloco; var novaAltura = alturaBloco + (gruposCampos[grupoIndex].PossuiEspacoAntes ? tamanhoTituloEtapa : 0); gruposCampos[grupoIndex].AlturaBloco = altura > novaAltura ? altura : novaAltura; } // Verificar se o bloco possui espaço antes, para as informações da Etapa. var possuiEspacoAntes = true; // Se os campos atingirem o limite da exibição, pular para a próxima página. // Dá um espaço em cima de 3 linhas para o conteúdo da etapa. if (alturaBloco > (alturaMaximaBlocoCampos - (alturaLinha * 3))) { alturaBloco = 0; grupoIndex++; possuiEspacoAntes = false; } if (gruposCampos.Count() != grupoIndex + 1) { gruposCampos.Add(new DTOBlocoCampo(possuiEspacoAntes, tamanhoTituloEtapa + alturaBloco)); } gruposCampos[grupoIndex].Campos.Add(campo); } foreach (var grupoCampos in gruposCampos) { gfx.DrawRectangle(XPens.Black, XBrushes.White, new XRect(alturaLinha, grupoCampos.PossuiEspacoAntes ? posicaoInicialEtapa : 20, page.Width - 45, grupoCampos.AlturaBloco)); if (gruposCampos.IndexOf(grupoCampos) == 0) { EscreverHeaderEtapa(textFormatter, idProcessoResposta, listaProcesso, page, font, qtdEtapa, etapa, padding, grupoCampos.PossuiEspacoAntes ? posicaoInicialEtapa : 20, alturaLinha, gfx); } //Campos var qtdCampos = 0; foreach (var campo in grupoCampos.Campos) { // Escrever dados do Campo. EscreverCampo(campo, gfx, font, page, alturaLinha, textFormatter, padding, posicaoInicialEtapa, qtdCampos, tamanhoTituloEtapa, grupoCampos.PossuiEspacoAntes); qtdCampos++; } // Se não for a última página, adiciona mais uma página ao PDF. if (gruposCampos.IndexOf(grupoCampos) != gruposCampos.Count() - 1) { page = document.AddPage(); gfx = XGraphics.FromPdfPage(page); textFormatter = new XTextFormatter(gfx); } } // Dar continuidade ao número da etapa. qtdEtapa++; } var streamOutput = new MemoryStream(); document.Save(streamOutput, false); Response.AddHeader("Content-Disposition", "attachment; filename=historicoDemanda_" + idProcessoResposta + ".pdf"); Response.ContentType = "application/pdf"; Response.BinaryWrite(streamOutput.ToArray()); Response.Flush(); }
public Pdf() { document = new PdfDocument(); page = document.AddPage(); gfx = XGraphics.FromPdfPage(page); }
public void newPage() { page = pdf.AddPage(); graph = XGraphics.FromPdfPage(page); yposition = 30; }
//int listItemHeight = 20; public string CreatePdf(PdfData pdfData) { Log l = new Log(); try { if (GlobalFontSettings.FontResolver == null) { GlobalFontSettings.FontResolver = new FontResolver(_resourcesPath); } var document = new PdfDocument(); var page = document.AddPage(); var gfx = XGraphics.FromPdfPage(page); AddTitleLogo(gfx, page, $"{_imagesPath}\\logo.png", 10, 10); AddTitleAndFooter(page, gfx, pdfData.DocumentTitle, document, pdfData); //AddDescription(gfx, pdfData); l.CreatedOn = System.DateTime.UtcNow; l.ShortDescription = "Adding User Detail"; l.FullDescription = "AAdding User Detail"; _ILog.InsertLog(l); AddUserDetails(gfx, pdfData); if (pdfData.Aspiration.Count > 0) { AddAspiration(gfx, pdfData); } if (pdfData.Training.Count > 0) { AddTraining(gfx, pdfData); } //AddList(gfx, pdfData); if (pdfData.Mentor.Count > 0) { AddMentor(gfx, pdfData); } if (pdfData.Allocation.Count > 0) { AddAllocation(gfx, pdfData); } if (pdfData.IInternal.Count > 0) { AddInternal(gfx, pdfData); } //l.CreatedOn = System.DateTime.UtcNow; //l.ShortDescription = "Creating docname"; //l.FullDescription = "Creating docname"; //_ILog.InsertLog(l); string docName = $"{_createdDocsPath}/{pdfData.DocumentName + "-" + pdfData.User.Name}-{DateTime.UtcNow.ToOADate()}.pdf"; //string docName = $"{_createdDocsPath}/{pdfData.DocumentName + "-" + pdfData.User.Name}.pdf"; document.Save(docName); return(docName); } catch (Exception ex) { l.CreatedOn = System.DateTime.UtcNow; l.ShortDescription = ex.Message; l.FullDescription = ex.InnerException.ToString(); _ILog.InsertLog(l); throw ex; } }
public void PdfReport(PictureViewModel pvm) { // Create a new PDF document PdfDocument document = new PdfDocument(); document.Info.Title = pvm.FileName; // Create an empty page PdfPage page = document.AddPage(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont font = new XFont("Verdana", 10); // Create Image var image = XImage.FromFile(pvm.FilePath); // Draw the text gfx.DrawString("Filename: " + pvm.FileName, font, XBrushes.Black, new XRect(10, 0, page.Width, 10), XStringFormats.TopLeft); gfx.DrawString("Photographer: ", font, XBrushes.Black, new XRect(10, 20, page.Width, 20), XStringFormats.TopLeft); gfx.DrawString("Name: " + pvm.Photographer.FirstName + " " + pvm.Photographer.LastName, font, XBrushes.Black, new XRect(10, 30, page.Width, 30), XStringFormats.TopLeft); gfx.DrawString("Birthday: " + pvm.Photographer.BirthDay, font, XBrushes.Black, new XRect(10, 40, page.Width, 40), XStringFormats.TopLeft); gfx.DrawString("Notes: " + pvm.Photographer.Notes, font, XBrushes.Black, new XRect(10, 50, page.Width, 50), XStringFormats.TopLeft); gfx.DrawImage(image, 100, 100, page.Width - 200, 200); gfx.DrawString("IPTC: ", font, XBrushes.Black, new XRect(10, 410, page.Width, 420), XStringFormats.TopLeft); gfx.DrawString("ByLine: " + pvm.IPTC.ByLine + " " + pvm.Photographer.LastName, font, XBrushes.Black, new XRect(10, 420, page.Width, 430), XStringFormats.TopLeft); gfx.DrawString("Caption: " + pvm.IPTC.Caption + " " + pvm.Photographer.LastName, font, XBrushes.Black, new XRect(10, 430, page.Width, 440), XStringFormats.TopLeft); gfx.DrawString("Headline: " + pvm.IPTC.Headline, font, XBrushes.Black, new XRect(10, 440, page.Width, 250), XStringFormats.TopLeft); gfx.DrawString("CopyrightNotice: " + pvm.IPTC.CopyrightNotice, font, XBrushes.Black, new XRect(10, 450, page.Width, 260), XStringFormats.TopLeft); gfx.DrawString("Keywords: " + pvm.IPTC.Keywords, font, XBrushes.Black, new XRect(10, 460, page.Width, 270), XStringFormats.TopLeft); gfx.DrawString("EXIF: ", font, XBrushes.Black, new XRect(10, 490, page.Width, 420), XStringFormats.TopLeft); gfx.DrawString("ExposureProgram: " + pvm.EXIF.ExposureProgram, font, XBrushes.Black, new XRect(10, 500, page.Width, 430), XStringFormats.TopLeft); gfx.DrawString("ExposureProgramResource: " + pvm.EXIF.ExposureProgramResource + " " + pvm.Photographer.LastName, font, XBrushes.Black, new XRect(10, 510, page.Width, 440), XStringFormats.TopLeft); gfx.DrawString("ExposureTime: " + pvm.EXIF.ExposureTime, font, XBrushes.Black, new XRect(10, 520, page.Width, 250), XStringFormats.TopLeft); gfx.DrawString("Flash: " + pvm.EXIF.Flash, font, XBrushes.Black, new XRect(10, 530, page.Width, 260), XStringFormats.TopLeft); gfx.DrawString("FNumber: " + pvm.EXIF.FNumber, font, XBrushes.Black, new XRect(10, 540, page.Width, 270), XStringFormats.TopLeft); gfx.DrawString("ISORating: " + pvm.EXIF.ISORating, font, XBrushes.Black, new XRect(10, 550, page.Width, 270), XStringFormats.TopLeft); gfx.DrawString("ISOValue: " + pvm.EXIF.ISOValue, font, XBrushes.Black, new XRect(10, 560, page.Width, 270), XStringFormats.TopLeft); gfx.DrawString("Make: " + pvm.EXIF.Make, font, XBrushes.Black, new XRect(10, 570, page.Width, 270), XStringFormats.TopLeft); document.Save(GlobalInformation.Path + "\\Reports\\report" + pvm.ID + ".pdf"); }
private void bgdWorker_DoWork(object sender, DoWorkEventArgs e) { try { string source = (e.Argument as string[])[0]; string destinaton = (e.Argument as string[])[1]; string worktype = (e.Argument as string[])[2]; switch (worktype) { case "Tif": SplitTiffImages(source, destinaton); success = true; break; case "Pdf": PdfDocument doc = new PdfDocument(); Image image = Image.FromFile(source); string filename = System.IO.Path.GetFileNameWithoutExtension(source); int frames = 0; Guid[] guid = image.FrameDimensionsList; FrameDimension fd = new FrameDimension(guid[0]); frames = image.GetFrameCount(fd); for (int i = 0; i < frames; i++) { doc.AddPage(); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[i]); image.SelectActiveFrame(fd, i); XImage img = XImage.FromGdiPlusImage(image); doc.Pages[i].Width = img.Width; doc.Pages[i].Height = img.Height; xgr.DrawImage(img, new Rectangle(0, 0, img.Width, img.Height)); } doc.Save(destinaton + "\\" + filename + ".pdf"); doc.Close(); success = true; break; } /* * PdfPage[] pp = new PdfPage[frames]; * for (int i = 0; i < frames; i++) * { * pp[i] = new PdfPage(); * doc.AddPage(pp[i]); * } * Stream stream = ToStream(image,ImageFormat.Tiff); * Parallel.For(0, frames, i => * { * Image imageTemp = Image.FromStream(stream); * XGraphics xgr = XGraphics.FromPdfPage(pp[i]); * imageTemp.SelectActiveFrame(fd, i); * XImage img = XImage.FromGdiPlusImage(imageTemp); * xgr.DrawImage(img,new Rectangle(0,0,img.Width,img.Height)); * imageTemp.Dispose(); * } * ); * * * * * * */ } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btn_pdf_Click(object sender, EventArgs e) { PdfDocument doc = new PdfDocument(); doc.Info.Title = "Created with PDFsharp"; PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XFont font = new XFont("Times New Roman", 8, XFontStyle.Bold); XPen pen = new XPen(XColors.Black, 0.8); gfx.DrawRectangle(pen, 75, 70, 150, 65); gfx.DrawRectangle(pen, 400, 70, 125, 65); gfx.DrawString("Lycée Pasteur Mont Roland", font, XBrushes.Black, 100, 80); gfx.DrawString("Enseignement Supérieur", font, XBrushes.Black, 107, 90); font = new XFont("Times New Roman", 8, XFontStyle.Regular); gfx.DrawString("9 avenue Rockefeller", font, XBrushes.Black, 117, 100); gfx.DrawString("BP 24", font, XBrushes.Black, 139, 110); gfx.DrawString("39107 Dole Cedex", font, XBrushes.Black, 120, 120); gfx.DrawString("03 84 79 75 00", font, XBrushes.Black, 127, 130); gfx.DrawString("En partenariat avec :", font, XBrushes.Black, 429, 80); font = new XFont("Times New Roman", 8, XFontStyle.Bold); gfx.DrawString("CFA ASPECT", font, XBrushes.Black, 438, 100); font = new XFont("Times New Roman", 8, XFontStyle.Regular); gfx.DrawString("20 rue Megevand", font, XBrushes.Black, 435, 110); gfx.DrawString("25041 Besançon", font, XBrushes.Black, 436, 120); gfx.DrawString("03 81 25 03 75", font, XBrushes.Black, 439, 130); gfx.DrawImage(XImage.FromFile("lpmr.png"), 230, 75, 80, 50); gfx.DrawImage(XImage.FromFile("aspect.jpg"), 318, 75, 80, 50); font = new XFont("Times New Roman", 10, XFontStyle.Bold); gfx.DrawString("RELEVE DE NOTES - Promotion 2019 2021 - Première année", font, XBrushes.Black, 184, 160); gfx.DrawString("Administrateur de Systèmes d'Information", font, XBrushes.Black, 222, 180); font = new XFont("Times New Roman", 8, XFontStyle.Bold); gfx.DrawString("TITRE RNCP de Niveau 6 - N° de certification 26E32601 - Code NSF 326 n", font, XBrushes.Black, 186, 195); font = new XFont("Times New Roman", 8, XFontStyle.Regular); gfx.DrawString("Nom de l'apprenti : DIZIERE Emma", font, XBrushes.Black, 90, 220); pen = new XPen(XColors.Black, 1); XBrush brush = new XSolidBrush(XColor.FromArgb(240, 240, 240)); gfx.DrawRectangle(pen, brush, 50, 225, 450, 15); font = new XFont("Times New Roman", 8, XFontStyle.Bold); gfx.DrawString("Envaluation au sein du centre de formation ", font, XBrushes.Black, 228, 235); pen = new XPen(XColors.Black, 0.8); font = new XFont("Times New Roman", 8, XFontStyle.Regular); gfx.DrawRectangle(pen, 50, 240, 105, 20); gfx.DrawString("Matières ", font, XBrushes.Black, 60, 252); gfx.DrawRectangle(pen, 155, 240, 180, 10); gfx.DrawString("Moyennes sur 20", font, XBrushes.Black, 222, 248); gfx.DrawString("Coef", font, XBrushes.Black, 164, 258); gfx.DrawRectangle(pen, 191, 250, 36, 10); gfx.DrawString("Ctrl Cont", font, XBrushes.Black, 194, 258); gfx.DrawRectangle(pen, 227, 250, 36, 10); gfx.DrawString("Examen", font, XBrushes.Black, 232, 258); gfx.DrawRectangle(pen, 263, 250, 36, 10); gfx.DrawString("Total", font, XBrushes.Black, 272, 258); gfx.DrawRectangle(pen, 299, 250, 36, 10); gfx.DrawString("Classe", font, XBrushes.Black, 307, 258); gfx.DrawRectangle(pen, 335, 240, 165, 20); gfx.DrawString("Notes sur 20", font, XBrushes.Black, 395, 255); gfx.DrawString("1", font, XBrushes.Black, 164, 268); gfx.DrawRectangle(pen, 155, 260, 180, 10); gfx.DrawRectangle(pen, 155, 260, 36, 10); gfx.DrawRectangle(pen, 227, 260, 36, 10); gfx.DrawRectangle(pen, 263, 260, 36, 10); gfx.DrawString("Anglais Professionel ", font, XBrushes.Black, 55, 268); gfx.DrawRectangle(pen, 50, 260, 450, 10); gfx.DrawString("1", font, XBrushes.Black, 164, 278); gfx.DrawRectangle(pen, 155, 270, 180, 10); gfx.DrawRectangle(pen, 155, 270, 36, 10); gfx.DrawRectangle(pen, 227, 270, 36, 10); gfx.DrawRectangle(pen, 263, 270, 36, 10); gfx.DrawString("Outil mathématique", font, XBrushes.Black, 55, 278); gfx.DrawRectangle(pen, 50, 270, 450, 10); gfx.DrawString("1", font, XBrushes.Black, 164, 288); gfx.DrawRectangle(pen, 155, 280, 180, 10); gfx.DrawRectangle(pen, 155, 280, 36, 10); gfx.DrawRectangle(pen, 227, 280, 36, 10); gfx.DrawRectangle(pen, 263, 280, 36, 10); gfx.DrawString("Droit informatique ", font, XBrushes.Black, 55, 288); gfx.DrawRectangle(pen, 50, 280, 450, 10); gfx.DrawString("2", font, XBrushes.Black, 164, 298); gfx.DrawRectangle(pen, 155, 290, 180, 10); gfx.DrawRectangle(pen, 155, 290, 36, 10); gfx.DrawRectangle(pen, 227, 290, 36, 10); gfx.DrawRectangle(pen, 263, 290, 36, 10); gfx.DrawString("Management Budgetisation", font, XBrushes.Black, 55, 298); gfx.DrawRectangle(pen, 50, 290, 450, 10); gfx.DrawString("Evalué en première année ", font, XBrushes.Black, 370, 298); gfx.DrawString("3", font, XBrushes.Black, 164, 308); gfx.DrawRectangle(pen, 155, 300, 180, 10); gfx.DrawRectangle(pen, 155, 300, 36, 10); gfx.DrawRectangle(pen, 227, 300, 36, 10); gfx.DrawRectangle(pen, 263, 300, 36, 10); gfx.DrawString("Génie Logiciel ", font, XBrushes.Black, 55, 308); gfx.DrawRectangle(pen, 50, 300, 450, 10); gfx.DrawString("3", font, XBrushes.Black, 164, 318); gfx.DrawRectangle(pen, 155, 310, 180, 10); gfx.DrawRectangle(pen, 155, 310, 36, 10); gfx.DrawRectangle(pen, 227, 310, 36, 10); gfx.DrawRectangle(pen, 263, 310, 36, 10); gfx.DrawString("Réseaux, Systèmes et Sécurité ", font, XBrushes.Black, 55, 318); gfx.DrawRectangle(pen, 50, 310, 450, 10); gfx.DrawString("1", font, XBrushes.Black, 164, 328); gfx.DrawRectangle(pen, 155, 320, 180, 10); gfx.DrawRectangle(pen, 155, 320, 36, 10); gfx.DrawRectangle(pen, 227, 320, 36, 10); gfx.DrawRectangle(pen, 263, 320, 36, 10); gfx.DrawString("BD ", font, XBrushes.Black, 55, 328); gfx.DrawRectangle(pen, 50, 320, 450, 10); gfx.DrawString("Evalué en projet tutoré", font, XBrushes.Black, 370, 328); gfx.DrawString("3", font, XBrushes.Black, 164, 338); gfx.DrawRectangle(pen, 155, 330, 180, 10); gfx.DrawRectangle(pen, 155, 330, 36, 10); gfx.DrawRectangle(pen, 227, 330, 36, 10); gfx.DrawRectangle(pen, 263, 330, 36, 10); gfx.DrawString("Conduite de Projet ", font, XBrushes.Black, 55, 338); gfx.DrawRectangle(pen, 50, 330, 450, 10); gfx.DrawString("Evalué en première année ", font, XBrushes.Black, 370, 338); gfx.DrawString("3", font, XBrushes.Black, 164, 348); gfx.DrawRectangle(pen, 155, 340, 180, 10); gfx.DrawRectangle(pen, 155, 340, 36, 10); gfx.DrawRectangle(pen, 227, 340, 36, 10); gfx.DrawRectangle(pen, 263, 340, 36, 10); gfx.DrawString("Projet Tutoré ", font, XBrushes.Black, 55, 348); gfx.DrawRectangle(pen, 50, 340, 450, 10); gfx.DrawString("Evalué en projet tutoré ", font, XBrushes.Black, 370, 348); gfx.DrawString("Moyenne", font, XBrushes.Black, 164, 358); gfx.DrawRectangle(pen, 50, 350, 450, 10); gfx.DrawRectangle(pen, 263, 350, 36, 10); gfx.DrawRectangle(pen, 299, 350, 36, 10); gfx.DrawString("Moyenne informatique ", font, XBrushes.Black, 360, 358); gfx.DrawRectangle(pen, 450, 350, 50, 10); font = new XFont("Times New Roman", 8, XFontStyle.Bold); gfx.DrawString("Evaluation en entreprise", font, XBrushes.Black, 228, 378); pen = new XPen(XColors.Black, 0.8); font = new XFont("Times New Roman", 8, XFontStyle.Regular); gfx.DrawRectangle(pen, 50, 370, 450, 10); gfx.DrawString("Livret de Suivi", font, XBrushes.Black, 80, 388); gfx.DrawString("12", font, XBrushes.Black, 164, 388); gfx.DrawRectangle(pen, 50, 380, 450, 10); gfx.DrawRectangle(pen, 155, 380, 180, 10); gfx.DrawRectangle(pen, 155, 380, 36, 10); gfx.DrawRectangle(pen, 263, 380, 36, 10); gfx.DrawString("Projet Entreprise", font, XBrushes.Black, 80, 398); gfx.DrawRectangle(pen, 50, 390, 450, 10); gfx.DrawRectangle(pen, 155, 390, 180, 10); gfx.DrawRectangle(pen, 155, 390, 36, 10); gfx.DrawRectangle(pen, 263, 390, 36, 10); gfx.DrawString("Moyenne", font, XBrushes.Black, 164, 408); gfx.DrawRectangle(pen, 50, 400, 450, 10); gfx.DrawRectangle(pen, 263, 400, 36, 10); gfx.DrawRectangle(pen, 299, 400, 36, 10); font = new XFont("Times New Roman", 8, XFontStyle.Bold); gfx.DrawString("Appréciation du conseil de promotion et du responsable de dispositif", font, XBrushes.Black, 198, 428); pen = new XPen(XColors.Black, 0.8); font = new XFont("Times New Roman", 8, XFontStyle.Regular); gfx.DrawRectangle(pen, 50, 420, 450, 10); gfx.DrawRectangle(pen, 50, 430, 450, 100); gfx.DrawString("Rappel Moyenne année 1", font, XBrushes.Black, 134, 448); gfx.DrawRectangle(pen, 284, 440, 30, 10); gfx.DrawString("Moyenne année 2 1er semestre", font, XBrushes.Black, 134, 458); gfx.DrawRectangle(pen, 284, 450, 30, 10); gfx.DrawString("A Dole le 10 mars 2021 ", font, XBrushes.Black, 290, 470); gfx.DrawString("Le responsable de dispositif : Julian COURBEZ", font, XBrushes.Black, 290, 480); const string filename = "Bulletin-notes-2annee.pdf"; document.Save(filename); Process.Start(filename); }
public ActionResult TestMigraDocMixPdfSharp() { PdfDocument doc = new PdfDocument(); doc.Info.Title = "Member information"; doc.Info.Author = "PalangPanya"; doc.Info.Subject = "Member information"; doc.Info.Keywords = "PalangPanya"; PdfPage page = doc.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; XFont font = new XFont("Cordia New", 16, XFontStyle.Bold); gfx.DrawString("The following paragraph was rendered using ภาษาภ", font, XBrushes.Black, new XRect(100, 100, page.Width - 200, 300), XStringFormats.Center); XPen pen = new XPen(XColors.Navy, Math.PI); gfx.DrawRectangle(pen, 10, 0, 100, 60); gfx.DrawRectangle(XBrushes.DarkOrange, 130, 0, 100, 60); gfx.DrawRectangle(pen, XBrushes.DarkOrange, 10, 80, 100, 60); gfx.DrawRectangle(pen, XBrushes.DarkOrange, 150, 80, 60, 60); Document document = new Document(); Section sec = document.AddSection(); //Paragraph para = sec.AddParagraph(); //para.Format.Alignment = ParagraphAlignment.Justify; //para.Format.Font.Name = "Times New Roman"; //para.Format.Font.Size = 12; //para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; //para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; //para.AddText("Duisism odigna acipsum delesenisl "); //para.AddFormattedText("ullum in velenit", TextFormat.Bold); //para.AddText(" ipit iurero dolum zzriliquisis nit wis dolore vel et nonsequipit, velendigna " + // "auguercilit lor se dipisl duismod tatem zzrit at laore magna feummod oloborting ea con vel " + // "essit augiati onsequat luptat nos diatum vel ullum illummy nonsent nit ipis et nonsequis " + // "niation utpat. Odolobor augait et non etueril landre min ut ulla feugiam commodo lortie ex " + // "essent augait el ing eumsan hendre feugait prat augiatem amconul laoreet. ≤≥≈≠"); //para.Format.Borders.Distance = "5pt"; //para.Format.Borders.Color = Colors.Gold; Paragraph paragraph = sec.AddParagraph(); paragraph.Format.Font.Color = Color.FromCmyk(100, 30, 20, 50); paragraph.AddFormattedText("Hello,ไทย World!", TextFormat.Bold); paragraph.AddFormattedText("ทดสอบการใช้ภาษา", TextFormat.Italic); var logoPath = Path.Combine(_env.WebRootPath, "images"); logoPath = Path.Combine(logoPath, "logo_t.png"); Image imgLogo = sec.AddImage(logoPath); imgLogo.Height = "2cm"; imgLogo.LockAspectRatio = true; var memberPicPath = Path.Combine(_env.WebRootPath, "images_member"); memberPicPath = Path.Combine(memberPicPath, "_2_1365148227.jpg"); //memberPicPath = Path.Combine(memberPicPath, "_677138-topic-ix-1.jpg"); Image imgMember = sec.AddImage(memberPicPath); imgMember.Height = "5cm"; imgMember.LockAspectRatio = true; imgMember.RelativeVertical = RelativeVertical.Line; imgMember.RelativeHorizontal = RelativeHorizontal.Margin; imgMember.Top = ShapePosition.Top; imgMember.Left = ShapePosition.Right; imgMember.WrapFormat.Style = WrapStyle.Through; //document.UseCmykColor = true; const bool unicode = true; const PdfFontEmbedding embedding = PdfFontEmbedding.Always; PdfDocumentRenderer pdfRenderer = new PdfDocumentRenderer(unicode, embedding); pdfRenderer.Document = document; pdfRenderer.RenderDocument(); //MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(document); //MigraDoc.Rendering.DocumentRenderer docRenderer = pdfRenderer.DocumentRenderer; //docRenderer.PrepareDocument(); //docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(10), "12cm", paragraph); MemoryStream m = new MemoryStream(); doc.Save(m, false); return(new FileStreamResult(m, "application/pdf")); }
private async void downloadCharts() { //get parameters bool blFileHDSelect = chkHighDef.Checked; string[] strSaveLocations = createSaveDirectories(txtSaveLocation.Text); lblFileDownloading.Text = "Collecting download information..."; List <chartInfo> lstChartInfo = getDownloadAddresses(); //create objects and vars int intTotalFiles = lstChartInfo.Count; PdfDocument doc = new PdfDocument(); int intPdfPageNo = 0; //download files and create PDF chartInfo previousChart = new chartInfo(); for (int i = 0; i < intTotalFiles; i++) { WebClient wc = new WebClient(); //set headers and security wc.Headers.Add("Accept: text/html, application/xhtml+xml, */*"); wc.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:86.0) Gecko/20100101 Firefox/86.0"); ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //wc.Headers.Add("user-agent", "Mozilla/5.0 (compatible, MSIE 11, Windows NT 6.3; Trident/7.0; rv:11.0) like Gecko"); //set applicable charts chartInfo currentChart = lstChartInfo[i].setFileParameters(blFileHDSelect); //get file type string strFileType = Path.GetExtension(currentChart.FileLocation); string strFileSaveName = strSaveLocations[1] + "\\" + i.ToString(); //show file being downloaded string strFileInfo = currentChart.Name + " - " + currentChart.SubGroup + " - " + currentChart.Group + " "; int intIndexLengthRemove = 30; if (strFileInfo.Length < 31) { intIndexLengthRemove = strFileInfo.Length - 1; } lblFileDownloading.Text = strFileInfo.Remove(intIndexLengthRemove) + "..."; //download, if download fails move to next file try { await wc.DownloadFileTaskAsync(currentChart.FileLocation, strFileSaveName + strFileType); } catch { continue; } //process images to pdf int intPagesAdded = 0; if (strFileType == ".pdf") { //get downloaded pdf and add to output pdf PdfDocument inputDocument = PdfReader.Open(strFileSaveName + strFileType, PdfDocumentOpenMode.Import); foreach (PdfPage page in inputDocument.Pages) { page.Rotate = currentChart.FileRotation; doc.AddPage(page); intPagesAdded++; } } else { //turn downloaded image into pdf and add to output pdf PdfPage page = new PdfPage(); XImage img = XImage.FromFile(strFileSaveName + strFileType); page.Width = img.PointWidth; page.Height = img.PointHeight; doc.Pages.Add(page); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[intPdfPageNo]); xgr.DrawImage(img, 0, 0); doc.Pages[intPdfPageNo].Rotate = currentChart.FileRotation; intPagesAdded++; } //add outline PdfOutlineCollection outlines = doc.Outlines; //check whether new group level is required and add sub group outline if required if (currentChart.Group != previousChart.Group) { outlines.Add(currentChart.Group, doc.Pages[intPdfPageNo]); } if (currentChart.SubGroup.Length > 0) { //using count -1 gives the outline that was just created outlines = outlines[outlines.Count - 1].Outlines; if (currentChart.SubGroup != previousChart.SubGroup) { outlines.Add(currentChart.SubGroup, doc.Pages[intPdfPageNo]); } } //create and add final level outlines = outlines[outlines.Count - 1].Outlines; outlines.Add(lstChartInfo[i].Name, doc.Pages[intPdfPageNo]); //update page count intPdfPageNo += intPagesAdded; previousChart = currentChart; //give progress int intCompletedPercentage = Convert.ToInt16((((double)i + 1.0) / (double)intTotalFiles) * 100); pgrDownloadPerc.Value = intCompletedPercentage; } //save and close pdf doc.Save(strSaveLocations[2]); doc.Close(); //add clone with common name try { File.Copy(strSaveLocations[2], strSaveLocations[0] + @"\Met Charts.pdf", true); } catch { MessageBox.Show("Could not update the common file, ensure the file is not in use"); } //upload to cloud?? / email?? if (chkEmail.Checked) { try { lblFileDownloading.Text = "Sending email..."; MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("*****@*****.**"); mail.To.Add("*****@*****.**"); mail.Subject = "Met & NOTAMs"; mail.Body = "See weather charts attached"; mail.Attachments.Add(new Attachment(strSaveLocations[2])); SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("*****@*****.**", "XX"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); } catch (Exception ex) { MessageBox.Show(ex.ToString()); } } //re-enable download button and complete message lblFileDownloading.Text = "Download complete."; enableControls(true); }
public bool export(Match matchData, DateTime fileName, System.Drawing.Image logo) { //TODO this is for testing only!! try { if (matchData.getGame(0).getRally(0) != null) { Console.WriteLine("Using user data"); } } catch (Exception e) { // no matchData data matchData = this.generateSampleMatchData(matchData); Console.WriteLine("Using random data"); } // Create a new PDF document PdfDocument document = new PdfDocument(); document.Info.Title = "Match Intensity Sheet, " + fileName.ToLongDateString(); // Create an empty page PdfPage page = document.AddPage(); // landscape letter page.Size = PageSize.Letter; page.Orientation = PageOrientation.Landscape; // now dims are 792 x 612 if at 72dpi // Get an XGraphics object for drawing this.gfx = XGraphics.FromPdfPage(page); // draw the Logo //XImage image = XImage.FromFile(IMAGE_logo); XImage image = XImage.FromGdiPlusImage(logo); // Left position in point double x = (250 - image.PixelWidth * 72 / image.HorizontalResolution) / 2; gfx.DrawImage(image, 35, 38, 100, 65); // Page Title XFont font_title = new XFont("Arial", 22, XFontStyle.Bold); gfx.DrawString( "Match Intensity Sheet", font_title, XBrushes.Black, new XRect(144, 36, 226, 16), XStringFormats.TopLeft ); // TODO Date, Enterer, Location, Players, XFont font_headerFields = new XFont("Arial", 12, XFontStyle.Regular); // Date gfx.DrawString( "Date " + matchData.data_date.ToShortDateString(), font_headerFields, XBrushes.Black, new XRect(390, 46, 100, 8), XStringFormats.TopLeft ); // Enterer gfx.DrawString( "Enterer: " + matchData.data_enterer, font_headerFields, XBrushes.Black, new XRect(505, 46, 233, 10), XStringFormats.TopLeft ); if (matchData.data_enterer == null || matchData.data_enterer.Length < 1) { gfx.DrawLine(XPens.Black, 550, 57, 744, 57); } // Event gfx.DrawString( "Event: " + matchData.data_event, font_headerFields, XBrushes.Black, new XRect(144, 68, 311, 11), XStringFormats.TopLeft ); if (matchData.data_event == null || matchData.data_event.Length < 1) { gfx.DrawLine(XPens.Black, 180, 81, 460, 81); } // Location gfx.DrawString( "Location: " + matchData.data_location, font_headerFields, XBrushes.Black, new XRect(480, 68, 250, 11), XStringFormats.TopLeft ); if (matchData.data_event == null || matchData.data_event.Length < 1) { gfx.DrawLine(XPens.Black, 538, 81, 744, 81); } // Players, label gfx.DrawString( "Players:", font_headerFields, XBrushes.Black, new XRect(144, 89, 125, 11), XStringFormats.TopLeft ); // Players, vs. gfx.DrawString( "vs.", font_headerFields, XBrushes.Black, new XRect(469, 89, 30, 11), XStringFormats.TopLeft ); // Players, player A if (matchData.data_playerA == null || matchData.data_playerA.Length < 1) { gfx.DrawLine(XPens.Black, 192, 102, 460, 102); } else { gfx.DrawString( matchData.data_playerA, font_headerFields, XBrushes.Black, new XRect(192, 89, 250, 11), XStringFormats.Center ); } // player B line if (matchData.data_playerB == null || matchData.data_playerB.Length < 1) { gfx.DrawLine(XPens.Black, 490, 102, 744, 102); } else { gfx.DrawString( matchData.data_playerB, font_headerFields, XBrushes.Black, new XRect(490, 89, 250, 11), XStringFormats.Center ); } // Match Summary gfx.DrawString( "MATCH SUMMARY", new XFont("Arial", 12, XFontStyle.Bold), XBrushes.Black, new XRect(35, 110, 109, 10), XStringFormats.TopLeft ); XFont font_summaryFields = new XFont("Arial", 10, XFontStyle.Regular); //Match Start Time gfx.DrawString( "Match Start Time: " + matchData.getStartTime(), font_summaryFields, XBrushes.Black, new XRect(35, 129, 150, 10), XStringFormats.TopLeft ); //Finish Time gfx.DrawString( "Finish Time: " + matchData.getFinishTime(), font_summaryFields, XBrushes.Black, new XRect(165, 129, 150, 10), XStringFormats.TopLeft ); //# Games gfx.DrawString( "# Games: " + matchData.getCurrentGameNumber(), font_summaryFields, XBrushes.Black, new XRect(275, 129, 75, 10), XStringFormats.TopLeft ); //# Shots gfx.DrawString( "# Shots: " + matchData.getTotalShotCount(), font_summaryFields, XBrushes.Black, new XRect(335, 129, 75, 10), XStringFormats.TopLeft ); //# Rallies: gfx.DrawString( "# Rallies: " + matchData.getTotalRallyCount(), font_summaryFields, XBrushes.Black, new XRect(395, 129, 75, 10), XStringFormats.TopLeft ); //Ave Shots/Rally gfx.DrawString( "Ave Shots/Rally: " + (matchData.getTotalShotCount() / (float)matchData.getTotalRallyCount()).ToString("0.0"), font_summaryFields, XBrushes.Black, new XRect(460, 129, 75, 10), XStringFormats.TopLeft ); List <Rally> longestRallies = matchData.getLongestRallies(); //Longest Rally: gfx.DrawString( "Longest Rally: " + (longestRallies[0].getShots() / (float)1000).ToString("0.00"), font_summaryFields, XBrushes.Black, new XRect(570, 129, 75, 10), XStringFormats.TopLeft ); //* Second Line *// //Total Match Time gfx.DrawString( "Total Match Time: " + matchData.getTotalMatchTime(), font_summaryFields, XBrushes.Black, new XRect(35, 148, 150, 10), XStringFormats.TopLeft ); //(Total) Play Time gfx.DrawString( "Play Time: " + (matchData.getTotalPlayTime() / (float)1000).ToString("00.00"), font_summaryFields, XBrushes.Black, new XRect(145, 148, 150, 10), XStringFormats.TopLeft ); //(Total) Rally Break Time gfx.DrawString( "Rally Break Time: " + (matchData.getTotalBreakTime() / (float)1000).ToString("00.00"), font_summaryFields, XBrushes.Black, new XRect(245, 148, 150, 10), XStringFormats.TopLeft ); //Avg Rally Break Time gfx.DrawString( "Ave Rally Break Time: " + ((matchData.getTotalBreakTime() / (float)1000) / (float)matchData.getTotalRallyCount()).ToString("0.00"), font_summaryFields, XBrushes.Black, new XRect(365, 148, 150, 10), XStringFormats.TopLeft ); //* Third Line *// //MATCH INTENSITY VALUE gfx.DrawString( "MATCH INTENSITY VALUE: NaN", new XFont("Arial", 10, XFontStyle.Bold), XBrushes.Black, new XRect(35, 167, 150, 10), XStringFormats.TopLeft ); //# Shots/Rally-- gfx.DrawString( "# Shots/Rally--", new XFont("Arial", 10, XFontStyle.Italic), XBrushes.Black, new XRect(204, 167, 150, 10), XStringFormats.TopLeft ); //30+: 00 gfx.DrawString( "30+: " + matchData.getShotsPerRally(30, Int32.MaxValue), font_summaryFields, XBrushes.Black, new XRect(274, 167, 150, 10), XStringFormats.TopLeft ); //20-29 gfx.DrawString( "20-29: " + matchData.getShotsPerRally(20, 29), font_summaryFields, XBrushes.Black, new XRect(320, 167, 150, 10), XStringFormats.TopLeft ); //10-19 gfx.DrawString( "10-19: " + matchData.getShotsPerRally(10, 19), font_summaryFields, XBrushes.Black, new XRect(370, 167, 150, 10), XStringFormats.TopLeft ); //5-9 gfx.DrawString( "5-9: " + matchData.getShotsPerRally(5, 9), font_summaryFields, XBrushes.Black, new XRect(420, 167, 150, 10), XStringFormats.TopLeft ); //1-4 gfx.DrawString( "1-4: " + matchData.getShotsPerRally(1, 4), font_summaryFields, XBrushes.Black, new XRect(455, 167, 150, 10), XStringFormats.TopLeft ); //2nd Longest gfx.DrawString( "2nd Longest: " + (longestRallies[1].getShots() / (float)1000).ToString("0.00"), font_summaryFields, XBrushes.Black, new XRect(490, 167, 150, 10), XStringFormats.TopLeft ); //3rd Longest gfx.DrawString( "3rd Longest: " + (longestRallies[2].getShots() / (float)1000).ToString("0.00"), font_summaryFields, XBrushes.Black, new XRect(585, 167, 150, 10), XStringFormats.TopLeft ); //4th Longest gfx.DrawString( "4th Longest: " + (longestRallies[3].getShots() / (float)1000).ToString("0.00"), font_summaryFields, XBrushes.Black, new XRect(680, 167, 150, 10), XStringFormats.TopLeft ); // Draw each game this.font_gameLabel = new XFont("Arial", 10, XFontStyle.Bold); this.font_gameText = new XFont("Arial", 8, XFontStyle.Regular); this.font_RallyNumber = new XFont("Arial", 8, XFontStyle.Underline); int gameY = 194; for (int gameIndex = 0; gameIndex < matchData.getCurrentGameNumber(); gameIndex++) { drawGame(matchData.getGame(gameIndex), gameIndex, 35, gameY); gameY += 130; } // Save the document... try { this.savedPath = fileName.Year + "." + fileName.Month + "." + fileName.Day + "_" + fileName.Hour + "." + fileName.Minute + ".pdf"; // TODO don't overwrite document.Save(savedPath); // ...and start a viewer. Process.Start(savedPath); return(true); } catch (NotSupportedException e) { Console.WriteLine("ERROR! NotSupportedException (bad filename?): ", e); } catch (Exception e) { Console.WriteLine("ERROR! General Exception: ", e); } return(false); }
//pagrindine pdf piesimo funkcija public void Generate(MySqlConnection conn) { conn.Open(); PdfDocument document = new PdfDocument(); PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); //spalvos XBrush lblue = new XSolidBrush(XColor.FromArgb(158, 217, 252)); XBrush pblue = new XSolidBrush(XColor.FromArgb(21, 112, 247)); //fonts XFont header = new XFont("Arial", 13, XFontStyle.BoldItalic, options); XFont small = new XFont("Arial", 8, XFontStyle.Regular, options); XFont normal = new XFont("Arial", 10, XFontStyle.Regular, options); XFont normalBold = new XFont("Arial", 10, XFontStyle.Bold, options); XFont normalItalic = new XFont("Arial", 10, XFontStyle.Italic, options); XFont normalBoldItalic = new XFont("Arial", 10, XFontStyle.BoldItalic, options); //'piestukai' XPen black = new XPen(XColors.Black, 1); XPen gray = new XPen(XColors.Gray, 1); XPen neutralRect = new XPen(XColors.Gray, 1); XPen goodRect = new XPen(XColors.Aqua, 1); string sql = "SELECT ob_addr FROM objektai WHERE obid=" + this.obid + ";"; MySqlCommand comm = new MySqlCommand(sql, conn); MySqlDataReader data = comm.ExecuteReader(); string buf; //HEADER string addr = ""; while (data.Read()) { addr = data["ob_addr"].ToString(); } buf = addr + " mokesčiai"; gfx.DrawString(buf, header, XBrushes.Black, new XRect(0, 0, page.Width, 100), XStringFormats.Center); gfx.DrawLine(black, 40, 90, page.Width - 40, 90); //DATA buf = "Data: " + DateTime.Now.ToString("MM-yyyy"); gfx.DrawRectangle(black, XBrushes.Beige, 40, 95, 100, 20); gfx.DrawString(buf, normalBold, XBrushes.Black, new XRect(45, 100, page.Width - 80, 19), XStringFormats.TopLeft); //BENDRIJA //title buf = "Bendrijos mokesčiai"; gfx.DrawRectangle(neutralRect, XBrushes.Beige, 40, 130, page.Width - 80, 18); gfx.DrawString(buf, normalBoldItalic, XBrushes.Black, new XRect(40, 130, page.Width - 80, 18), XStringFormats.Center); //tableheader buf = "Mokestis"; gfx.DrawString(buf, normalBold, XBrushes.Black, new XRect(40, 155, 455, 18), XStringFormats.Center); buf = "Kaina"; gfx.DrawString(buf, normalBold, XBrushes.Black, new XRect(495, 155, 60, 18), XStringFormats.Center); //table int lineheight = 16; double ypoint = 155 + 16 * (bendrpav.Count + 1); for (int i = 0; i < bendrpav.Count; i++) { int ycoords = lineheight * (i + 1); gfx.DrawRectangle(gray, 40, 155 + ycoords, 455, lineheight); gfx.DrawRectangle(gray, 495, 155 + ycoords, 60, lineheight); gfx.DrawString(bendrpav[i], small, XBrushes.Black, new XRect(45, 155 + ycoords + 3.5, 455, lineheight), XStringFormats.TopLeft); gfx.DrawString(bendrkain[i].ToString(), small, XBrushes.Black, new XRect(500, 155 + ycoords + 3.5, 60, lineheight), XStringFormats.TopLeft); } //sum buf = "Bendrijos mokesčių suma:"; ypoint += lineheight; gfx.DrawRectangle(black, lblue, 40, ypoint, 150, 18); gfx.DrawString(buf, normalBold, pblue, new XRect(45, ypoint + 3, 150, 18), XStringFormats.TopLeft); gfx.DrawRectangle(black, lblue, 190, ypoint, 60, 18); gfx.DrawString(bendrkain.Sum().ToString(), normalBold, XBrushes.Black, new XRect(195, ypoint + 3, 60, 18), XStringFormats.TopLeft); ypoint += 28; gfx.DrawLine(black, 40, ypoint, page.Width - 40, ypoint); ypoint += 10; //KOMUNALINIAI //header buf = "Komunaliniai patarnavimai (vanduo, šiluma, internetas bei pan.)"; gfx.DrawRectangle(neutralRect, XBrushes.Beige, 40, ypoint, page.Width - 80, 18); gfx.DrawString(buf, normalBoldItalic, XBrushes.Black, new XRect(40, ypoint, page.Width - 80, 18), XStringFormats.Center); ypoint += 23; //table gfx.DrawRectangle(black, XBrushes.LightGray, 170, ypoint, 128, lineheight); gfx.DrawString("Išnaudota", small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawRectangle(black, XBrushes.LightGray, 298, ypoint, 128, lineheight); gfx.DrawString("Kaina/Vnt.", small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawRectangle(black, XBrushes.LightGray, 426, ypoint, 129, lineheight); gfx.DrawString("Suma", small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center); ypoint += lineheight; double rate = 0; double komsum = 0; for (int i = 0; i < 4; i++) { gfx.DrawRectangle(black, XBrushes.LightGray, 40, ypoint, 130, lineheight); gfx.DrawRectangle(black, 170, ypoint, 128, lineheight); gfx.DrawRectangle(black, 298, ypoint, 128, lineheight); gfx.DrawRectangle(black, 426, ypoint, 129, lineheight); if (i == 0) { gfx.DrawString("Elektra (kW/h)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center); rate = getOperatorRate("e"); gfx.DrawString(elek.ToString(), small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString((elek * rate).ToString(), small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center); komsum += elek * rate; } if (i == 1) { gfx.DrawString("Dujos (MW/h)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center); rate = getOperatorRate("d"); gfx.DrawString(duj.ToString(), small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString((duj * rate).ToString(), small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center); komsum += duj * rate; } if (i == 2) { gfx.DrawString("Vanduo (m^3)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center); rate = getOperatorRate("v"); gfx.DrawString(vand.ToString(), small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString((vand * rate).ToString(), small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center); komsum += vand * rate; } if (i == 3) { gfx.DrawString("Internetas (Eur/mėn)", small, XBrushes.Black, new XRect(40, ypoint, 130, lineheight), XStringFormats.Center); rate = getOperatorRate("i"); gfx.DrawString("---", small, XBrushes.Black, new XRect(170, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString(rate.ToString(), small, XBrushes.Black, new XRect(298, ypoint, 129, lineheight), XStringFormats.Center); gfx.DrawString("---", small, XBrushes.Black, new XRect(426, ypoint, 129, lineheight), XStringFormats.Center); komsum += rate; } ypoint += lineheight; } buf = "Komunalinių mokesčių suma:"; ypoint += lineheight; gfx.DrawRectangle(black, lblue, 40, ypoint, 150, 18); gfx.DrawString(buf, normalBold, pblue, new XRect(45, ypoint + 3, 150, 18), XStringFormats.TopLeft); gfx.DrawRectangle(black, lblue, 190, ypoint, 60, 18); gfx.DrawString(komsum.ToString(), normalBold, XBrushes.Black, new XRect(195, ypoint + 3, 60, 18), XStringFormats.TopLeft); ypoint += 18; buf = "Visų mokesčių suma:"; gfx.DrawRectangle(black, lblue, 40, ypoint, 150, 18); gfx.DrawString(buf, normalBold, pblue, new XRect(45, ypoint + 3, 150, 18), XStringFormats.TopLeft); gfx.DrawRectangle(black, lblue, 190, ypoint, 60, 18); gfx.DrawString((komsum + bendrkain.Sum()).ToString(), normalBold, XBrushes.Black, new XRect(195, ypoint + 3, 60, 18), XStringFormats.TopLeft); //GALAS gfx.DrawRectangle(black, XBrushes.Beige, 306, 95, 50, 20); gfx.DrawRectangle(black, lblue, 356, 95, 50, 20); gfx.DrawRectangle(black, lblue, 405, 95, 150, 20); double nuom = getNuom(); gfx.DrawString("Nuoma:", normalBoldItalic, XBrushes.Black, new XRect(306, 95, 50, 20), XStringFormats.Center); gfx.DrawString(nuom.ToString(), normalBold, XBrushes.Black, new XRect(356, 95, 50, 20), XStringFormats.Center); gfx.DrawString("Nuoma + Mokesčiai:" + (nuom + komsum + bendrkain.Sum()).ToString(), normalBold, XBrushes.Black, new XRect(405, 95, 150, 20), XStringFormats.Center); conn.Close(); document.Save(filename); Process.Start(filename); }
/// <summary> /// Used to export offertes /// </summary> /// <param name="title"> Title of the document</param> /// <param name="documentName">Name of the document when saved</param> /// <param name="description">Despription of the offerte</param> /// <param name="price"></param> public bool Export(QuotationViewModel vm, string title) { using (PdfDocument document = new PdfDocument()) { PdfPage page = document.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(page); // Title font XFont fontTitle = new XFont("Arial", 20, XFontStyle.Bold); // Text font XFont fontText = new XFont("Arial", 14, XFontStyle.Regular); XPen lineBlack = new XPen(XColors.Black, 0.3); PdfPage currentPage = page; document.Info.Title = "Offertes"; string documentName = ""; string[] lines = null; int y = 140, lineY = 160, linesOnPage = 0, pageCount = 1; DrawBase(gfx, currentPage, fontTitle, fontText, title, pageCount); // Jobs gfx.DrawString(" Opdracht: " + vm.Job, fontText, XBrushes.Black, new XRect(20, 100, currentPage.Width, currentPage.Height), XStringFormats.TopLeft); gfx.DrawLine(lineBlack, 20, 120, 400, 120); if (vm.Description.Length > 80) { lines = GetLines(vm.Description); for (int i = 0; i < lines.Length; i++) { gfx.DrawString(lines[i], fontText, XBrushes.Black, new XRect(20, y, currentPage.Width, currentPage.Height), XStringFormats.TopLeft); gfx.DrawLine(lineBlack, 20, lineY, 550, lineY); lineY += 40; y += 40; linesOnPage++; if (linesOnPage == 17) { PdfPage newPage = document.AddPage(); currentPage = newPage; gfx = XGraphics.FromPdfPage(currentPage); linesOnPage = 0; pageCount++; y = 140; lineY = 160; DrawBase(gfx, currentPage, fontTitle, fontText, title, pageCount); } } } else { gfx.DrawString(vm.Description, fontText, XBrushes.Black, new XRect(20, y, currentPage.Width, currentPage.Height), XStringFormats.TopLeft); gfx.DrawLine(lineBlack, 20, 160, 550, 160); } // Price gfx.DrawString("Prijs: " + vm.Price + "€", fontText, XBrushes.Black, new XRect(20, -60, currentPage.Width, currentPage.Height), XStringFormats.BottomLeft); gfx.DrawLine(lineBlack, 20, 760, 400, 760); SaveFileDialog saveFileDialog = new SaveFileDialog { Title = "Save", Filter = "PDF Files (*.pdf) " + "|" }; if (saveFileDialog.ShowDialog() == DialogResult.OK) { documentName = saveFileDialog.FileName; } if (!documentName.Contains(".pdf")) { documentName += ".pdf"; } if (!DidSaveFailed(document, documentName)) { StartPDF(documentName); } else { return(false); } return(true); } }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { if (on_off == 1) { var index = new List <double>(); DA.GetDataList("index", index); DA.GetDataTree("element_node_relationship", out GH_Structure <GH_Number> _ij); var ij = _ij.Branches; DA.GetDataTree("sectional_force", out GH_Structure <GH_Number> _sec_f); DA.GetDataTree("fk", out GH_Structure <GH_Number> _fk); DA.GetDataTree("ft", out GH_Structure <GH_Number> _ft); DA.GetDataTree("fb(inner)", out GH_Structure <GH_Number> _fbi); DA.GetDataTree("fs(inner)", out GH_Structure <GH_Number> _fsi); DA.GetDataTree("fb(outer)", out GH_Structure <GH_Number> _fbo); DA.GetDataTree("fs(outer)", out GH_Structure <GH_Number> _fso); List <double> Lambda = new List <double>(); DA.GetDataList("lambda", Lambda); List <double> A = new List <double>(); DA.GetDataList("section area", A); List <double> Zy = new List <double>(); DA.GetDataList("Section modulus around y-axis", Zy); List <double> Zz = new List <double>(); DA.GetDataList("Section modulus around z-axis", Zz); var fk = _fk.Branches[0]; var ft = _ft.Branches[0]; var fbi = _fbi.Branches[0]; var fsi = _fsi.Branches[0]; var fbo = _fbo.Branches[0]; var fso = _fso.Branches[0]; var fk2 = _fk.Branches[0]; var ft2 = _ft.Branches[0]; var fbi2 = _fbi.Branches[0]; var fsi2 = _fsi.Branches[0]; var fbo2 = _fbo.Branches[0]; var fso2 = _fso.Branches[0]; if (_sec_f.Branches.Count / ij.Count == 5) { fk2 = _fk.Branches[1]; ft2 = _ft.Branches[1]; fbi2 = _fbi.Branches[1]; fsi2 = _fsi.Branches[1]; fbo2 = _fbo.Branches[1]; fso2 = _fso.Branches[1]; } double alpha = 1.0; DA.GetData("safe factor", ref alpha); DA.GetDataTree("kentei_hi", out GH_Structure <GH_Number> _kentei); List <string> secname = new List <string>(); DA.GetDataList("secname", secname); var pdfname = "CLTCheck"; DA.GetData("outputname", ref pdfname); int Digit(int num)//数字の桁数を求める関数 { // Mathf.Log10(0)はNegativeInfinityを返すため、別途処理する。 return((num == 0) ? 1 : ((int)Math.Log10(num) + 1)); } XColor RGB(double h, double s, double l)//convert HSL to RGB { var max = 0.0; var min = 0.0; var r = 0.0; var g = 0.0; var b = 0.0; if (l < 0.5) { max = l + l * s; min = l - l * s; } else { max = l + (1 - l) * s; min = l - (1 - l) * s; } var HUE_MAX = 360.0; var RGB_MAX = 255; var hp = HUE_MAX / 6.0; h *= HUE_MAX; var q = h / hp; if (q <= 1) { r = max; g = (h / hp) * (max - min) + min; b = min; } else if (q <= 2) { r = ((hp * 2 - h) / hp) * (max - min) + min; g = max; b = min; } else if (q <= 3) { r = min; g = max; b = ((h - hp * 2) / hp) * (max - min) + min; } else if (q <= 4) { r = min; g = ((hp * 4 - h) / hp) * (max - min) + min; b = max; } else if (q <= 5) { r = ((h - hp * 4) / hp) * (max - min) + min; g = min; b = max; } else { r = max; g = min; b = ((HUE_MAX - h) / hp) * (max - min) + min; } r *= RGB_MAX; g *= RGB_MAX; b *= RGB_MAX; return(XColor.FromArgb((int)r, (int)g, (int)b)); } if (index[0] == -9999) { index = new List <double>(); for (int e = 0; e < ij.Count; e++) { index.Add(e); } } // フォントリゾルバーのグローバル登録 if (PdfCreate.JapaneseFontResolver.fontset == 0) { PdfSharp.Fonts.GlobalFontSettings.FontResolver = fontresolver; PdfCreate.JapaneseFontResolver.fontset = 1; } // PDFドキュメントを作成。 PdfDocument document = new PdfDocument(); document.Info.Title = pdfname; document.Info.Author = "Shinnosuke Fujita, Assoc. Prof., The Univ. of Kitakyushu"; // フォントを作成。 XFont font = new XFont("Gen Shin Gothic", 9, XFontStyle.Regular); XFont fontbold = new XFont("Gen Shin Gothic", 9, XFontStyle.Bold); var pen = XPens.Black; var burnB = new List <double>(); var burnD = new List <double>(); if (!DA.GetDataList("burnB", burnB)) { } ; if (!DA.GetDataList("burnD", burnD)) { } ; var labels = new List <string> { "部材番号", "部材断面", "λ", "A[cm2]", "α(低減率)", "Zy[cm3]", "Zz[cm3]", "", "fk[N/mm2]", "ft[N/mm2]", "fb(面内)[N/mm2]", "fs(面内)[N/mm2]", "fb(面外)[N/mm2]", "fs(面外)[N/mm2]", "", "節点番号", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定" }; if (burnB.Count != 0 && burnD.Count != 0) { labels = new List <string> { "部材番号", "部材断面", "燃えしろB[mm]", "燃えしろD[mm]", "λ", "A[cm2]", "α(低減率)", "Zy[cm3]", "Zz[cm3]", "", "fk[N/mm2]", "ft[N/mm2]", "fb[N/mm2]", "fs[N/mm2]", "", "節点番号", "", "N[kN]", "My[kNm]", "Mz[kNm]", "Qy[kN]", "Qz[kN]", "軸+曲げ検定比", "せん断検定比", "判定" }; } var label_width = 75; var offset_x = 25; var offset_y = 25; var pitchy = 13; var text_width = 25; PdfPage page = new PdfPage(); page.Size = PageSize.A4; for (int e = 0; e < index.Count; e++)// { int ni = (int)ij[e][0].Value; int nj = (int)ij[e][1].Value; int sec = (int)ij[e][3].Value; var ele_text = ((int)index[e]).ToString(); var ni_text = ni.ToString(); var nj_text = nj.ToString(); var name_text = secname[sec]; var lambda_text = Lambda[e].ToString("F").Substring(0, Digit((int)Lambda[e])); var A_text = (A[sec] * 1e+4).ToString("F").Substring(0, Digit((int)(A[sec] * 1e+4))); var b = 0.0; var d = 0.0; if (burnB.Count != 0 && burnD.Count != 0) { b = Math.Pow(6 * Math.Pow(Zz[sec], 2) / Zy[sec], 1.0 / 3.0); d = Math.Pow(6 * Math.Pow(Zy[sec], 2) / Zz[sec], 1.0 / 3.0); } if (burnB.Count != 0 && burnD.Count != 0) { A_text = (b * d * 1e+4).ToString("F").Substring(0, Digit((int)(b * d * 1e+4))); } var alpha_text = alpha.ToString("F"); alpha_text = alpha_text.Substring(0, Math.Min(4, alpha_text.Length)); var Zy_text = (Zy[sec] * 1e+6).ToString("F"); Zy_text = Zy_text.Substring(0, Math.Min(Digit((int)(Zy[sec] * 1e+6)), Zy_text.Length)); var Zz_text = (Zz[sec] * 1e+6).ToString("F"); Zz_text = Zz_text.Substring(0, Math.Min(Digit((int)(Zz[sec] * 1e+6)), Zz_text.Length)); if (burnB.Count != 0 && burnD.Count != 0) { var zy = b * Math.Pow(d, 2) / 6.0; var zz = d * Math.Pow(b, 2) / 6.0; Zy_text = (zy * 1e+6).ToString("F"); Zy_text = Zy_text.Substring(0, Math.Min(Digit((int)(zy * 1e+6)), Zy_text.Length)); Zz_text = (zz * 1e+6).ToString("F"); Zy_text = Zy_text.Substring(0, Math.Min(Digit((int)(zz * 1e+6)), Zy_text.Length)); } var fk_text = fk[e].Value.ToString("F"); fk_text = fk_text.Substring(0, Math.Min(5, fk_text.Length)); var fk2_text = ""; var ft_text = ft[e].Value.ToString("F"); ft_text = ft_text.Substring(0, Math.Min(5, ft_text.Length)); var ft2_text = ""; var fbi_text = fbi[e].Value.ToString("F"); fbi_text = fbi_text.Substring(0, Math.Min(5, fbi_text.Length)); var fbi2_text = ""; var fsi_text = fsi[e].Value.ToString("F"); fsi_text = fsi_text.Substring(0, Math.Min(5, fsi_text.Length)); var fsi2_text = ""; var fbo_text = fbo[e].Value.ToString("F"); fbo_text = fbo_text.Substring(0, Math.Min(5, fbo_text.Length)); var fbo2_text = ""; var fso_text = fso[e].Value.ToString("F"); fso_text = fso_text.Substring(0, Math.Min(5, fso_text.Length)); var fso2_text = ""; if (_fk.Branches.Count == 2) { fk2_text = fk2[e].Value.ToString("F"); fk2_text = fk2_text.Substring(0, Math.Min(5, fk2_text.Length)); } if (_ft.Branches.Count == 2) { ft2_text = ft2[e].Value.ToString("F"); ft2_text = ft2_text.Substring(0, Math.Min(5, ft2_text.Length)); } if (_fbi.Branches.Count == 2) { fbi2_text = fbi2[e].Value.ToString("F"); fbi2_text = fbi2_text.Substring(0, Math.Min(5, fbi2_text.Length)); } if (_fsi.Branches.Count == 2) { fsi2_text = fsi2[e].Value.ToString("F"); fsi2_text = fsi2_text.Substring(0, Math.Min(5, fsi2_text.Length)); } if (_fbo.Branches.Count == 2) { fbo2_text = fbo2[e].Value.ToString("F"); fbo2_text = fbo2_text.Substring(0, Math.Min(5, fbo2_text.Length)); } if (_fso.Branches.Count == 2) { fso2_text = fso2[e].Value.ToString("F"); fso2_text = fso2_text.Substring(0, Math.Min(5, fso2_text.Length)); } var sec_f = _sec_f.get_Branch(new GH_Path(new int[] { 0, e })); var Ni_text = double.Parse(sec_f[0].ToString()).ToString("F"); Ni_text = Ni_text.Substring(0, Math.Min(4, Ni_text.Length)); var Qyi_text = Math.Abs(double.Parse(sec_f[1].ToString())).ToString("F"); Qyi_text = Qyi_text.Substring(0, Math.Min(4, Qyi_text.Length)); var Qzi_text = Math.Abs(double.Parse(sec_f[2].ToString())).ToString("F"); Qzi_text = Qzi_text.Substring(0, Math.Min(4, Qzi_text.Length)); var Myi_text = Math.Abs(double.Parse(sec_f[4].ToString())).ToString("F"); Myi_text = Myi_text.Substring(0, Math.Min(4, Myi_text.Length)); var Mzi_text = Math.Abs(double.Parse(sec_f[5].ToString())).ToString("F"); Mzi_text = Mzi_text.Substring(0, Math.Min(4, Mzi_text.Length)); var Nj_text = (-double.Parse(sec_f[6].ToString())).ToString("F"); Nj_text = Nj_text.Substring(0, Math.Min(4, Nj_text.Length)); var Qyj_text = Math.Abs(double.Parse(sec_f[7].ToString())).ToString("F"); Qyj_text = Qyj_text.Substring(0, Math.Min(4, Qyj_text.Length)); var Qzj_text = Math.Abs(double.Parse(sec_f[8].ToString())).ToString("F"); Qzj_text = Qzj_text.Substring(0, Math.Min(4, Qzj_text.Length)); var Myj_text = Math.Abs(double.Parse(sec_f[10].ToString())).ToString("F"); Myj_text = Myj_text.Substring(0, Math.Min(4, Myj_text.Length)); var Mzj_text = Math.Abs(double.Parse(sec_f[11].ToString())).ToString("F"); Mzj_text = Mzj_text.Substring(0, Math.Min(4, Mzj_text.Length)); var Nc_text = (double.Parse(sec_f[12].ToString())).ToString("F"); Nc_text = Nc_text.Substring(0, Math.Min(4, Nc_text.Length)); var Qyc_text = Math.Abs(double.Parse(sec_f[13].ToString())).ToString("F"); Qyc_text = Qyc_text.Substring(0, Math.Min(4, Qyc_text.Length)); var Qzc_text = Math.Abs(double.Parse(sec_f[14].ToString())).ToString("F"); Qzc_text = Qzc_text.Substring(0, Math.Min(4, Qzc_text.Length)); var Myc_text = Math.Abs(double.Parse(sec_f[16].ToString())).ToString("F"); Myc_text = Myc_text.Substring(0, Math.Min(4, Myc_text.Length)); var Mzc_text = Math.Abs(double.Parse(sec_f[17].ToString())).ToString("F"); Mzc_text = Mzc_text.Substring(0, Math.Min(4, Mzc_text.Length)); var klist = _kentei.get_Branch(new GH_Path(new int[] { 0, e })); var Mki_color = new List <XSolidBrush>(); var Mkj_color = new List <XSolidBrush>(); var Mkc_color = new List <XSolidBrush>(); var Qki_color = new List <XSolidBrush>(); var Qkj_color = new List <XSolidBrush>(); var Qkc_color = new List <XSolidBrush>(); var Mki = (Math.Max(double.Parse(klist[3].ToString()), double.Parse(klist[4].ToString())) + double.Parse(klist[0].ToString())); var Mki_text = Mki.ToString("F").Substring(0, 4); Mki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mki, 1.0)) * 1.9 / 3.0, 1, 0.5))); var Mkj = (Math.Max(double.Parse(klist[8].ToString()), double.Parse(klist[9].ToString())) + double.Parse(klist[5].ToString())); var Mkj_text = Mkj.ToString("F").Substring(0, 4); Mkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkj, 1.0)) * 1.9 / 3.0, 1, 0.5))); var Mkc = (Math.Max(double.Parse(klist[13].ToString()), double.Parse(klist[14].ToString())) + double.Parse(klist[10].ToString())); var Mkc_text = Mkc.ToString("F").Substring(0, 4); Mkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkc, 1.0)) * 1.9 / 3.0, 1, 0.5))); var Qki = Math.Max(double.Parse(klist[1].ToString()), double.Parse(klist[2].ToString())); var Qki_text = Qki.ToString("F").Substring(0, 4); Qki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qki, 1.0)) * 1.9 / 3.0, 1, 0.5))); var Qkj = Math.Max(double.Parse(klist[6].ToString()), double.Parse(klist[7].ToString())); var Qkj_text = Qkj.ToString("F").Substring(0, 4); Qkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkj, 1.0)) * 1.9 / 3.0, 1, 0.5))); var Qkc = Math.Max(double.Parse(klist[11].ToString()), double.Parse(klist[12].ToString())); var Qkc_text = Qkc.ToString("F").Substring(0, 4); Qkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkc, 1.0)) * 1.9 / 3.0, 1, 0.5))); var OKi_text = "O.K."; var OKj_text = "O.K."; var OKc_text = "O.K."; if (Mki > 1 || Qki > 1) { OKi_text = "N.G."; } if (Mkj > 1 || Qkj > 1) { OKc_text = "N.G."; } if (Mkc > 1 || Qkc > 1) { OKj_text = "N.G."; } var values = new List <List <string> >(); values.Add(new List <string> { ele_text }); values.Add(new List <string> { name_text }); if (burnB.Count != 0 && burnD.Count != 0) { values.Add(new List <string> { ((int)(burnB[e] * 1000)).ToString() }); values.Add(new List <string> { ((int)(burnD[e] * 1000)).ToString() }); } values.Add(new List <string> { lambda_text }); values.Add(new List <string> { A_text }); values.Add(new List <string> { alpha_text }); values.Add(new List <string> { Zy_text }); values.Add(new List <string> { Zz_text }); values.Add(new List <string> { "長期", "", "短期" }); if (burnB.Count == 0 && burnD.Count == 0) { values.Add(new List <string> { fk_text, "", fk2_text }); } else { values.Add(new List <string> { "", "", fk_text }); } values.Add(new List <string> { ft_text, "", ft2_text }); values.Add(new List <string> { fbi_text, "", fbi2_text }); values.Add(new List <string> { fsi_text, "", fsi2_text }); values.Add(new List <string> { fbo_text, "", fbo2_text }); values.Add(new List <string> { fso_text, "", fso2_text }); values.Add(new List <string> { "i端", "中央", "j端" }); values.Add(new List <string> { ni_text, "", nj_text }); if (burnB.Count == 0 && burnD.Count == 0) { values.Add(new List <string> { "長期検討" }); } else { values.Add(new List <string> { "短期検討" }); } values.Add(new List <string> { Ni_text, Nc_text, Nj_text }); values.Add(new List <string> { Myi_text, Myc_text, Myj_text }); values.Add(new List <string> { Mzi_text, Mzc_text, Mzj_text }); values.Add(new List <string> { Qyi_text, Qyc_text, Qyj_text }); values.Add(new List <string> { Qzi_text, Qzc_text, Qzj_text }); values.Add(new List <string> { Mki_text, Mkc_text, Mkj_text }); values.Add(new List <string> { Qki_text, Qkc_text, Qkj_text }); values.Add(new List <string> { OKi_text, OKc_text, OKj_text }); int N = _sec_f.Branches.Count / ij.Count; if (N == 5) { var text = new List <string> { "短期(L+X)検討", "短期(L+Y)検討", "短期(L-X)検討", "短期(L-Y)検討" }; for (int i = 0; i < 4; i++) { values.Add(new List <string> { text[i] }); var sec_f1 = _sec_f.get_Branch(new GH_Path(new int[] { i + 1, e })); Ni_text = (double.Parse(sec_f[0].ToString()) + double.Parse(sec_f1[0].ToString())).ToString("F"); Ni_text = Ni_text.Substring(0, Math.Min(4, Ni_text.Length)); Qyi_text = Math.Abs(double.Parse(sec_f[1].ToString()) + double.Parse(sec_f1[1].ToString())).ToString("F"); Qyi_text = Qyi_text.Substring(0, Math.Min(4, Qyi_text.Length)); Qzi_text = Math.Abs(double.Parse(sec_f[2].ToString()) + double.Parse(sec_f1[2].ToString())).ToString("F"); Qzi_text = Qzi_text.Substring(0, Math.Min(4, Qzi_text.Length)); Myi_text = Math.Abs(double.Parse(sec_f[4].ToString()) + double.Parse(sec_f1[4].ToString())).ToString("F"); Myi_text = Myi_text.Substring(0, Math.Min(4, Myi_text.Length)); Mzi_text = Math.Abs(double.Parse(sec_f[5].ToString()) + double.Parse(sec_f1[5].ToString())).ToString("F"); Mzi_text = Mzi_text.Substring(0, Math.Min(4, Mzi_text.Length)); Nj_text = (-double.Parse(sec_f[6].ToString()) - double.Parse(sec_f1[6].ToString())).ToString("F"); Nj_text = Nj_text.Substring(0, Math.Min(4, Nj_text.Length)); Qyj_text = Math.Abs(double.Parse(sec_f[7].ToString()) + double.Parse(sec_f1[7].ToString())).ToString("F"); Qyj_text = Qyj_text.Substring(0, Math.Min(4, Qyj_text.Length)); Qzj_text = Math.Abs(double.Parse(sec_f[8].ToString()) + double.Parse(sec_f1[8].ToString())).ToString("F"); Qzj_text = Qzj_text.Substring(0, Math.Min(4, Qzj_text.Length)); Myj_text = Math.Abs(double.Parse(sec_f[10].ToString()) + double.Parse(sec_f1[10].ToString())).ToString("F"); Myj_text = Myj_text.Substring(0, Math.Min(4, Myj_text.Length)); Mzj_text = Math.Abs(double.Parse(sec_f[11].ToString()) + double.Parse(sec_f1[11].ToString())).ToString("F"); Mzj_text = Mzj_text.Substring(0, Math.Min(4, Mzj_text.Length)); Nc_text = (double.Parse(sec_f[12].ToString()) + double.Parse(sec_f1[12].ToString())).ToString("F"); Nc_text = Nc_text.Substring(0, Math.Min(4, Nc_text.Length)); Qyc_text = Math.Abs(double.Parse(sec_f[13].ToString()) + double.Parse(sec_f1[13].ToString())).ToString("F"); Qyc_text = Qyc_text.Substring(0, Math.Min(4, Qyc_text.Length)); Qzc_text = Math.Abs(double.Parse(sec_f[14].ToString()) + double.Parse(sec_f1[14].ToString())).ToString("F"); Qzc_text = Qzc_text.Substring(0, Math.Min(4, Qzc_text.Length)); Myc_text = Math.Abs(double.Parse(sec_f[16].ToString()) + double.Parse(sec_f1[16].ToString())).ToString("F"); Myc_text = Myc_text.Substring(0, Math.Min(4, Myc_text.Length)); Mzc_text = Math.Abs(double.Parse(sec_f[17].ToString()) + double.Parse(sec_f1[17].ToString())).ToString("F"); Mzc_text = Mzc_text.Substring(0, Math.Min(4, Mzc_text.Length)); klist = _kentei.get_Branch(new GH_Path(new int[] { i + 1, e })); Mki = (Math.Max(double.Parse(klist[3].ToString()), double.Parse(klist[4].ToString())) + double.Parse(klist[0].ToString())); Mki_text = Mki.ToString("F").Substring(0, 4); Mki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mki, 1.0)) * 1.9 / 3.0, 1, 0.5))); Mkj = (Math.Max(double.Parse(klist[8].ToString()), double.Parse(klist[9].ToString())) + double.Parse(klist[5].ToString())); Mkj_text = Mkj.ToString("F").Substring(0, 4); Mkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkj, 1.0)) * 1.9 / 3.0, 1, 0.5))); Mkc = (Math.Max(double.Parse(klist[13].ToString()), double.Parse(klist[14].ToString())) + double.Parse(klist[10].ToString())); Mkc_text = Mkc.ToString("F").Substring(0, 4); Mkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Mkc, 1.0)) * 1.9 / 3.0, 1, 0.5))); Qki = Math.Max(double.Parse(klist[1].ToString()), double.Parse(klist[2].ToString())); Qki_text = Qki.ToString("F").Substring(0, 4); Qki_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qki, 1.0)) * 1.9 / 3.0, 1, 0.5))); Qkj = Math.Max(double.Parse(klist[6].ToString()), double.Parse(klist[7].ToString())); Qkj_text = Qkj.ToString("F").Substring(0, 4); Qkj_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkj, 1.0)) * 1.9 / 3.0, 1, 0.5))); Qkc = Math.Max(double.Parse(klist[11].ToString()), double.Parse(klist[12].ToString())); Qkc_text = Qkc.ToString("F").Substring(0, 4); Qkc_color.Add(new XSolidBrush(RGB((1 - Math.Min(Qkc, 1.0)) * 1.9 / 3.0, 1, 0.5))); OKi_text = "O.K."; OKj_text = "O.K."; OKc_text = "O.K."; if (Mki > 1 || Qki > 1) { OKi_text = "N.G."; } if (Mkj > 1 || Qkj > 1) { OKc_text = "N.G."; } if (Mkc > 1 || Qkc > 1) { OKj_text = "N.G."; } values.Add(new List <string> { Ni_text, Nc_text, Nj_text }); values.Add(new List <string> { Myi_text, Myc_text, Myj_text }); values.Add(new List <string> { Mzi_text, Mzc_text, Mzj_text }); values.Add(new List <string> { Qyi_text, Qyc_text, Qyj_text }); values.Add(new List <string> { Qzi_text, Qzc_text, Qzj_text }); values.Add(new List <string> { Mki_text, Mkc_text, Mkj_text }); values.Add(new List <string> { Qki_text, Qkc_text, Qkj_text }); values.Add(new List <string> { OKi_text, OKc_text, OKj_text }); } } if (e % 6 == 0) { // 空白ページを作成。 page = document.AddPage(); // 描画するためにXGraphicsオブジェクトを取得。 gfx = XGraphics.FromPdfPage(page); for (int i = 0; i < labels.Count; i++) //ラベル列************************************************************************** { gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width, offset_y + pitchy * i); //横線 gfx.DrawLine(pen, offset_x + label_width, offset_y + pitchy * i, offset_x + label_width, offset_y + pitchy * (i + 1)); //縦線 gfx.DrawString(labels[i], font, XBrushes.Black, new XRect(offset_x, offset_y + pitchy * i, label_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); if (i == labels.Count - 1) { i += 1; gfx.DrawLine(pen, offset_x, offset_y + pitchy * i, offset_x + label_width, offset_y + pitchy * i);//横線 } }//*********************************************************************************************************************** } for (int i = 0; i < values.Count; i++) { var j = e % 6; gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i); //横線 gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * (i + 1)); //縦線 if (values[i].Count == 1) { gfx.DrawString(values[i][0], font, XBrushes.Black, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, text_width * 3, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); } else { var color1 = XBrushes.Black; var color2 = XBrushes.Black; var color3 = XBrushes.Black; var f = font; if (burnB.Count == 0 && burnD.Count == 0) { if (i == 22) { color1 = Mki_color[0]; color2 = Mkc_color[0]; color3 = Mkj_color[0]; f = fontbold; } else if (i == 23) { color1 = Qki_color[0]; color2 = Qkc_color[0]; color3 = Qkj_color[0]; f = fontbold; } else if (i == 31) { color1 = Mki_color[1]; color2 = Mkc_color[1]; color3 = Mkj_color[1]; f = fontbold; } else if (i == 32) { color1 = Qki_color[1]; color2 = Qkc_color[1]; color3 = Qkj_color[1]; f = fontbold; } else if (i == 40) { color1 = Mki_color[2]; color2 = Mkc_color[2]; color3 = Mkj_color[2]; f = fontbold; } else if (i == 41) { color1 = Qki_color[2]; color2 = Qkc_color[2]; color3 = Qkj_color[2]; f = fontbold; } else if (i == 49) { color1 = Mki_color[3]; color2 = Mkc_color[3]; color3 = Mkj_color[3]; f = fontbold; } else if (i == 50) { color1 = Qki_color[3]; color2 = Qkc_color[3]; color3 = Qkj_color[3]; f = fontbold; } else if (i == 58) { color1 = Mki_color[4]; color2 = Mkc_color[4]; color3 = Mkj_color[4]; f = fontbold; } else if (i == 59) { color1 = Qki_color[4]; color2 = Qkc_color[4]; color3 = Qkj_color[4]; f = fontbold; } } else { if (i == 24) { color1 = Mki_color[0]; color2 = Mkc_color[0]; color3 = Mkj_color[0]; f = fontbold; } else if (i == 25) { color1 = Qki_color[0]; color2 = Qkc_color[0]; color3 = Qkj_color[0]; f = fontbold; } } gfx.DrawString(values[i][0], f, color1, new XRect(offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, text_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); gfx.DrawString(values[i][1], f, color2, new XRect(offset_x + label_width + text_width * 3 * j + text_width, offset_y + pitchy * i, text_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); gfx.DrawString(values[i][2], f, color3, new XRect(offset_x + label_width + text_width * 3 * j + text_width * 2, offset_y + pitchy * i, text_width, offset_y + pitchy * (i + 1)), XStringFormats.TopCenter); } if (i == values.Count - 1) { i += 1; gfx.DrawLine(pen, offset_x + label_width + text_width * 3 * j, offset_y + pitchy * i, offset_x + label_width + text_width * 3 * (j + 1), offset_y + pitchy * i);//横線 } } } var dir = Path.GetDirectoryName(Rhino.RhinoDoc.ActiveDoc.Path); // ドキュメントを保存。 var filename = dir + "/" + pdfname + ".pdf"; document.Save(filename); // ビューアを起動。 Process.Start(filename); } }
void GenerateReport(PdfDocument document) { //PdfPage page = document.AddPage(); PdfPage page = document.Pages[0]; XGraphics gfx = XGraphics.FromPdfPage(page); // HACK² gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; XFont font = new XFont("Verdana", 4, XFontStyle.Regular); // map image origin //gfx.DrawString("O", font, XBrushes.Red, new XRect(20, 42, 12, 12), XStringFormats.Center); //gfx.DrawString("O", font, XBrushes.Blue, new XRect(220, 42, 12, 12), XStringFormats.Center); //gfx.DrawString("O", font, XBrushes.Green, new XRect(20, 120, 12, 12), XStringFormats.Center); //XPen penn = new XPen(XColors.DarkSeaGreen, 1.5); //gfx.DrawRectangle(penn, 420, 42, 153, 63); // ovmap image origin //gfx.DrawString("X", font, XBrushes.Red, new XRect(5, 5, 798, 1144), XStringFormats.Center); //gfx.DrawString("+", font, XBrushes.Red, new XRect(5, 5, 100, 1299), XStringFormats.Center); XPen pen = new XPen(XColors.DarkTurquoise, 0.5); //gfx.DrawRectangle(pen, 20, 42, 150, 40); Document doc = new Document(); // Create a renderer and prepare (=layout) the document MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); int numlabels = label_al.Count; int pagenum = 1; double xp = 0; double yp = 0; double x_marg = 20.0; double y_marg = 42.0; double w_inc = 200; double h_inc = 78; double label_width = 150.0; double rows = 3; double cols = 10; //Debug.Print(String.Format("{0} labels", numlabels)); for (int l = 0; l < numlabels; l++) { // get label MailingLabel ml = (MailingLabel)label_al[l]; // get col and row int irow = 1; int icol = 1; if ((l + 1) <= ((int)rows * (int)cols)) { try { irow = (((int)l / 3)); icol = (l % 3); } catch (Exception ex) { } //Debug.Print(String.Format("{0} -> {1} {2}", l, irow, icol)); } else if ((l + 1) > (((int)rows * (int)cols))) { //if ((l + 1) == (((int)rows * (int)cols) + 1)) int recpp = ((int)rows * (int)cols); int modpp = (l - 1) % (recpp); //Debug.Print(String.Format("{0} mod {1}", l, modpp)); if (modpp == 0) { // print second page page = document.Pages.Add(); //page = document.Pages[1]; gfx = XGraphics.FromPdfPage(page); // HACK² gfx.MUH = PdfFontEncoding.Unicode; gfx.MFEH = PdfFontEmbedding.Default; pagenum++; Debug.Print(String.Format(" pagenum {0}", pagenum)); } try { irow = (((l - ((pagenum - 1) * 30)) / 3)) - 1; icol = ((l - ((pagenum - 1) * 30)) % 3); } catch (Exception ex) { } } double xloc = x_marg + (icol * w_inc); double yloc = y_marg + (irow * h_inc); //Debug.Print(String.Format(" {0} {1}", xloc, yloc)); //gfx.DrawRectangle(pen, xloc, yloc, 150, 60); Section sec = doc.AddSection(); // Add a single paragraph with some text and format information. Paragraph para = sec.AddParagraph(); para.Format.Alignment = ParagraphAlignment.Justify; para.Format.KeepTogether = true; para.Format.Font.Name = "Verdana"; para.Format.Font.Size = Unit.FromPoint(6); para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black; para.Format.Font.Bold = true; //para.AddText("Duisism odigna acipsum delesenisl "); //para.AddFormattedText("ullum in velenit", TextFormat.Bold); //para.AddText(ml.lname + "\r\n" + ml.laddr); String lbltext = ""; lbltext += ml.lname; para.AddText(ml.lname); Paragraph para2 = sec.AddParagraph(); if (ml.laddr_1 != "") { lbltext += "\r\n" + ml.laddr_1; //para.AddText(ml.laddr_1); //para.AddLineBreak(); para2.Format.Alignment = ParagraphAlignment.Justify; para2.Format.KeepTogether = true; para2.Format.Font.Name = "Verdana"; para2.Format.Font.Size = Unit.FromPoint(6); para2.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black; para2.Format.Font.Bold = true; para2.AddText(ml.laddr_1); } if (ml.laddr_2 != "") { lbltext += "\r\n" + ml.laddr_2; } if (ml.laddr_3 != "") { lbltext += "\r\n" + ml.laddr_3; } if (ml.lcity != "") { lbltext += "\r\n" + ml.lcity + ", " + ml.lstate; } if (ml.lcntry != "") { lbltext += "\r\n" + ml.lcntry; } if (ml.zip != "") { lbltext += "\r\n" + ml.zip; } //para.AddText(ml.lcity + ", " + ml.lstate + " " + ml.zip); //para.AddLineBreak(); //para.AddText(lbltext); Paragraph para3 = sec.AddParagraph(); para3.Format.Alignment = ParagraphAlignment.Justify; para3.Format.KeepTogether = true; para3.Format.Font.Name = "Verdana"; para3.Format.Font.Size = Unit.FromPoint(6); para3.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.Black; para3.Format.Font.Bold = true; para3.AddText(ml.lcity + ", " + ml.lstate + " " + ml.zip); //para.Format.Borders.Distance = "1pt"; //para.Format.Borders.Color = Colors.Orange; // Create a renderer and prepare (=layout) the document //MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); docRenderer.PrepareDocument(); // Render the paragraph. You can render tables or shapes the same way. 29, 705, 555, 43 docRenderer.RenderObject(gfx, XUnit.FromPoint(xloc), XUnit.FromPoint(yloc + 15.0), XUnit.FromPoint((int)label_width), para); docRenderer.RenderObject(gfx, XUnit.FromPoint(xloc), XUnit.FromPoint(yloc + 23.0), XUnit.FromPoint((int)label_width), para2); docRenderer.RenderObject(gfx, XUnit.FromPoint(xloc), XUnit.FromPoint(yloc + 31.0), XUnit.FromPoint((int)label_width), para3); } // You always need a MigraDoc document for rendering. /* * Section sec = doc.AddSection(); * // Add a single paragraph with some text and format information. * Paragraph para = sec.AddParagraph(); * para.Format.Alignment = ParagraphAlignment.Justify; * para.Format.Font.Name = "Verdana"; * para.Format.Font.Size = Unit.FromPoint(6); * para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; * para.Format.Font.Color = MigraDoc.DocumentObjectModel.Colors.DarkGray; * //para.AddText("Duisism odigna acipsum delesenisl "); * //para.AddFormattedText("ullum in velenit", TextFormat.Bold); * * para.AddText("BillyBob\r\n123 Deep Elem Lane"); * * * //para.Format.Borders.Distance = "1pt"; * //para.Format.Borders.Color = Colors.Orange; * * // Create a renderer and prepare (=layout) the document * MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(doc); * docRenderer.PrepareDocument(); * * // Render the paragraph. You can render tables or shapes the same way. 29, 705, 555, 43 * docRenderer.RenderObject(gfx, XUnit.FromPoint(38), XUnit.FromPoint(710), XUnit.FromPoint(535), para); * */ /* * double xp = 0; * double yp = 0; * int numticks = 8; * * double w_inc = page.Width.Value / (double)numticks; * double h_inc = page.Height.Value / (double)numticks; * * for (int x = 0; x < numticks; x++) * { * for (int y = 0; y < numticks; y++) * { * * xp = (double)x * w_inc; * yp = (double)y * h_inc; * * XUnit xu_x = new XUnit(xp, XGraphicsUnit.Point); * XUnit xu_y = new XUnit(yp, XGraphicsUnit.Point); * * xu_x.ConvertType(XGraphicsUnit.Inch); * xu_y.ConvertType(XGraphicsUnit.Inch); * * gfx.DrawString("+", font, XBrushes.Red, new XRect( xp, yp, 5, 5), XStringFormats.Center); * //String lbl = String.Format("{0} \r\n{1} {2}\r\n {3}", (int)xp, (int)yp, xu_x.Value, xu_y.Value); * String lbl = String.Format("{0} {1}",xu_x.Value, xu_y.Value); * gfx.DrawString(lbl, font, XBrushes.Red, new XRect( xp + 5, yp + 5, 5, 5), XStringFormats.Center); * * * } * * } */ }
public static void createPdfDocumentTeacherHours() { CURR_Y = Y_START; PAGE_COUNTER = 0; TOTAL_PAGE_NUMBER = 0; ROW_COUNTER = 0; string fileName = "ReportTeacherHours" + ".pdf"; PDFDOCUMENT = new PdfDocument(); PDFDOCUMENT.Info.Title = "OCTT Teacher Hours Report"; PDFDOCUMENT.Info.Author = "Open Course Timetabler"; PDFDOCUMENT.Info.Subject = "Свободное расписание"; PdfPage newPage = createNewPage(); PAGE_COUNTER = 1; XGraphics gfx = XGraphics.FromPdfPage(newPage); double dab = System.Convert.ToDouble(AppForm.CURR_OCTT_DOC.TeachersRootNode.Nodes.Count / 34.0); double dde = Math.Ceiling(dab); TOTAL_PAGE_NUMBER = System.Convert.ToInt32(dde); createPageHeader(gfx); foreach (Teacher teacher in AppForm.CURR_OCTT_DOC.TeachersRootNode.Nodes) { ROW_COUNTER++; if (CURR_Y > 770) { newPage = createNewPage(); PAGE_COUNTER++; gfx = XGraphics.FromPdfPage(newPage); CURR_Y = Y_START; createPageHeader(gfx); } createTableRow(gfx, teacher); } try { PDFDOCUMENT.Save(fileName); Process.Start(Settings.PDF_READER_APPLICATION, fileName); } catch (Exception e) { try { Process.Start(fileName); } catch (Exception e2) { MessageBox.Show(e2.Message); } } }
/// <summary> /// Get the Certificate to be downloaded using ID /// </summary> /// <param name="id"></param> /// <returns></returns> public FileResult DownloadCertificate(int id) { IDAL dal = (new DALFactory()).GetInstance(); SharePointDAL spDal = new SharePointDAL(); try { string certificateHtml = string.Empty; MemoryStream workStream = new MemoryStream(); string strPDFFileName = string.Format("Certificate.pdf"); UserManager user = (UserManager)System.Web.HttpContext.Current.Session["CurrentUser"]; user = spDal.GetUserByEmail(user.EmailID); List <UserAssessment> userAssessments = dal.GetUserAssessmentsByID(id); foreach (UserAssessment userAssessment in userAssessments) { certificateHtml = "<HTML><HEAD><TITLE>Certificate of Completion</TITLE>" + "<META content='text/html; charset=utf-8' http-equiv=Content-Type> <META name=viewport content='width=device-width, initial-scale=1.0'> <META name=GENERATOR content='MSHTML 11.00.9600.18698'></HEAD>" + "<BODY> <TABLE style='PADDING: 5px; MARGIN: 10px 10%; BACKGROUND-COLOR: #fee2cf'>" + " <TR> <TD style='BORDER: #ff6600 10px solid; PADDING: 10px; margin:10px;'> <TABLE >" + " <TR> <TD style='BORDER: #ff6600 2px solid; BACKGROUND-COLOR: #fff;'> <TABLE>" + " <TR> <TD style=' BACKGROUND-COLOR: #ffffff'> <TABLE>" + " <TR> <TD style='WIDTH: 100%;'>" + " <TABLE style='WIDTH: 100%'>" + "<TR> <TD align=center> <TABLE> <TR> <TD style='FONT-SIZE: 25px; FONT-FAMILY: georgia'>ING Academy</TD></TR></TABLE></TD></TR>" + " <TR> <TD style='FONT-SIZE: 30px; FONT-FAMILY: Tahoma, Geneva, sans-serif; COLOR: #ff6200; TEXT-ALIGN: center; PADDING-TOP: 10px' align=center>Certificate of Completion</TD></TR>" + " <TR> <TD style='FONT-SIZE: 14px; FONT-FAMILY: Tahoma, Geneva, sans-serif; COLOR: #666; TEXT-ALIGN: center; PADDING-TOP: 20px'>This is certify that</TD></TR> " + "<TR> <TD style='FONT-SIZE: 18px; FONT-FAMILY: \"Times New Roman\", Times, serif; FONT-WEIGHT: bold; COLOR: #000; TEXT-ALIGN: center'>" + user.UserName + "</TD></TR>" + " <TR> <TD style='FONT-SIZE: 14px; FONT-FAMILY: Tahoma, Geneva, sans-serif; COLOR: #666; TEXT-ALIGN: center; PADDING-TOP: 10px'>has successfully completed</TD></TR>" + " <TR> <TD style='FONT-SIZE: 16px; FONT-FAMILY: \"Times New Roman\", Times, serif; COLOR: #000; PADDING-BOTTOM: 30px; TEXT-ALIGN: center'>" + userAssessment.TrainingAssessment + "</TD></TR>" + "</TABLE>" + " <TABLE style='WIDTH: 100%'> " + " <TR>" + "<TD style='HEIGHT: 50px; WIDTH: 150px; BACKGROUND-REPEAT: no-repeat; PADDING-LEFT: 10px'>" + " Your Score - " + userAssessment.MarksInPercentage + "%</TD> " + "<TD style='FONT-SIZE: 14px; FONT-FAMILY: Tahoma, Geneva, sans-serif; COLOR: #000; TEXT-ALIGN: right; PADDING-TOP: 0px; PADDING-RIGHT: 10px'>" + userAssessment.CompletedDate + "</TD></TR></TABLE>" + "</TD></TR>" + "</TABLE></TD></TR>" + "</TABLE></TD></TR>" + "</TABLE></TD></TR>" + "</TABLE></BODY></HTML>"; } Bitmap bitmap = new Bitmap(1800, 1800); Graphics g = Graphics.FromImage(bitmap); XGraphics xg = XGraphics.FromGraphics(g, new XSize(bitmap.Width, bitmap.Height)); TheArtOfDev.HtmlRenderer.PdfSharp.HtmlContainer c = new TheArtOfDev.HtmlRenderer.PdfSharp.HtmlContainer(); c.SetHtml(certificateHtml); PdfDocument pdf = new PdfDocument(); PdfPage page = new PdfPage(); XImage img = XImage.FromGdiPlusImage(bitmap); page.Size = PdfSharp.PageSize.A4; pdf.Pages.Add(page); XGraphics xgr = XGraphics.FromPdfPage(pdf.Pages[0]); c.PerformLayout(xgr); c.PerformPaint(xgr); xgr.DrawImage(img, 0, 0); pdf.Save(workStream, false); byte[] byteInfo = workStream.ToArray(); workStream.Write(byteInfo, 0, byteInfo.Length); workStream.Position = 0; return(File(workStream, "application/pdf", strPDFFileName)); } catch (Exception ex) { UserManager users = (UserManager)Session["CurrentUser"]; LogHelper.AddLog(new LogEntity(AppConstant.PartitionError, users.EmailID.ToString(), AppConstant.ApplicationName, "Home,DownloadCertificate", ex.Message, ex.StackTrace)); return(null); } }
public void PdfReport(string tags) { BusinessLayer bl = new BusinessLayer(); Dictionary <string, int> tagDict = bl.GetTagCount(); string[] tagArray = tags.Split(';'); for (int i = 0; i < tagArray.Length; i++) { tagArray[i] = tagArray[i].ToLower(); } // Create a new PDF document PdfDocument document = new PdfDocument(); document.Info.Title = tags; // Create an empty page PdfPage page = document.AddPage(); // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); // Create a font XFont font = new XFont("Verdana", 10); gfx.DrawString("Tag: Count", font, XBrushes.Black, new XRect(10, 0, page.Width, 10), XStringFormats.TopLeft); gfx.DrawString("____________________", font, XBrushes.Black, new XRect(10, 0, page.Width, 10), XStringFormats.TopLeft); int textHeight = 20; if (String.IsNullOrWhiteSpace(tags)) { foreach (KeyValuePair <string, int> valuePair in tagDict) { // Draw the text gfx.DrawString(valuePair.Key + ": " + valuePair.Value, font, XBrushes.Black, new XRect(10, textHeight, page.Width, 10), XStringFormats.TopLeft); textHeight += 10; } } else { foreach (KeyValuePair <string, int> valuePair in tagDict) { if (tagArray.Contains((valuePair.Key).ToLower())) { // Draw the text gfx.DrawString(valuePair.Key + ": " + valuePair.Value, font, XBrushes.Black, new XRect(10, textHeight, page.Width, 10), XStringFormats.TopLeft); textHeight += 10; } } } if (String.IsNullOrWhiteSpace(tags)) { document.Save(GlobalInformation.Path + "\\Reports\\reportalltags.pdf"); } else { document.Save(GlobalInformation.Path + "\\Reports\\report" + tags + ".pdf"); } }
public static void PDF() { //dont forget the imports // change to var name = SaveEmployee.name string empID = "testID"; string empName = "testName"; string empSurname = "testsurname"; string bankName = "testBankName"; string bankBranch = "testBranch"; string accountNumber = "testAccNo"; string accountType = "testAccType"; string branchCode = "testBranchCode"; //below are var that I created string basicSalary = "testBasicSalary"; string empAddress = "testAddress"; string payPeriod = "testPayPeriod"; string taxNumber = "testTaxNumber"; string comCompletedJobs = "testCom"; string bonus = "testBonus"; string totalRemuneration = "testTotalRem"; string comWeek1 = "testWeek1"; string comWeek2 = "testWeek2"; string comWeek3 = "testWeek3"; string comWeek4 = "testWeek4"; string comWeek5 = "testWeek5"; string comTotal = "testComTotal"; string totalEarnings = "TestTotalEarnings"; string travWeek1 = "testWeek1"; string travWeek2 = "testWeek2"; string travWeek3 = "testWeek3"; string travWeek4 = "testWeek4"; string travWeek5 = "testWeek5"; string travTotal = "testTravTotal"; string unpaidLeaveDays = "testDays"; string unpaidLeave = "testUnpaidLeave"; string payeTax = "testPayeTax"; string UIF = "testUIF"; string otherDeduct = "testOtherDeducts"; string totalDeducts = "testTotalDeducts"; string nettPay = "TestNettPay"; string leaveDaysDate = "testDate"; string leaveDaysAva = "testLeaveDays"; PdfDocument pdf = new PdfDocument(); pdf.Info.Title = "" + empSurname + " " + DateTime.Now.Date; PdfPage pdfPage = pdf.AddPage(); XGraphics gfx = XGraphics.FromPdfPage(pdfPage); XFont font = new XFont("Verdana", 6, XFontStyle.Regular); XFont fontTitles = new XFont("Verdana", 8, XFontStyle.Bold); XFont fontDetails = new XFont("Verdana", 6, XFontStyle.Bold); //colour boxes XRect empDetsBox = new XRect(98, 106, 400, 75); gfx.DrawRectangle(XBrushes.DarkBlue, empDetsBox); XRect empDetsBoxVars1 = new XRect(200, 120, 295, 8); gfx.DrawRectangle(XBrushes.White, empDetsBoxVars1); XRect empDetsBoxVars2 = new XRect(200, 130, 295, 8); gfx.DrawRectangle(XBrushes.White, empDetsBoxVars2); XRect empDetsBoxVars3 = new XRect(200, 140, 295, 8); gfx.DrawRectangle(XBrushes.White, empDetsBoxVars3); XRect empDetsBoxVars4 = new XRect(200, 150, 295, 8); gfx.DrawRectangle(XBrushes.White, empDetsBoxVars4); XRect empDetsBoxVars5 = new XRect(200, 160, 295, 8); gfx.DrawRectangle(XBrushes.White, empDetsBoxVars5); XRect empDetsBoxVars6 = new XRect(200, 170, 295, 8); gfx.DrawRectangle(XBrushes.White, empDetsBoxVars6); XRect RemDetsBox = new XRect(98, 185, 400, 10); gfx.DrawRectangle(XBrushes.DarkBlue, RemDetsBox); XRect RemDetsBoxVar = new XRect(98, 195, 400, 40); gfx.DrawRectangle(XBrushes.LightBlue, RemDetsBoxVar); XRect RemDetsBoxTot = new XRect(98, 229, 400, 12); gfx.DrawRectangle(XBrushes.BlueViolet, RemDetsBoxTot); XRect QuoteBox = new XRect(98, 245, 400, 10); gfx.DrawRectangle(XBrushes.DarkBlue, QuoteBox); XRect QuoteBoxVar = new XRect(98, 255, 400, 60); gfx.DrawRectangle(XBrushes.LightBlue, QuoteBoxVar); XRect QuoteBoxTot = new XRect(98, 309, 400, 12); gfx.DrawRectangle(XBrushes.BlueViolet, QuoteBoxTot); XRect EarnBox = new XRect(98, 324, 400, 12); gfx.DrawRectangle(XBrushes.BlueViolet, EarnBox); XRect TravelBox = new XRect(98, 340, 400, 10); gfx.DrawRectangle(XBrushes.DarkBlue, TravelBox); XRect TravelBoxVar = new XRect(98, 350, 400, 53); gfx.DrawRectangle(XBrushes.LightBlue, TravelBoxVar); XRect TravelBoxTot = new XRect(98, 399, 400, 12); gfx.DrawRectangle(XBrushes.BlueViolet, TravelBoxTot); XRect DeductsBox = new XRect(98, 415, 400, 10); gfx.DrawRectangle(XBrushes.DarkBlue, DeductsBox); XRect DeductsBoxVar = new XRect(98, 425, 400, 43); gfx.DrawRectangle(XBrushes.LightBlue, DeductsBoxVar); XRect DeductsBoxTot = new XRect(98, 464, 400, 12); gfx.DrawRectangle(XBrushes.BlueViolet, DeductsBoxTot); XRect NetBox = new XRect(98, 479, 400, 12); gfx.DrawRectangle(XBrushes.DarkBlue, NetBox); XRect LeaveBox = new XRect(98, 494, 400, 12); gfx.DrawRectangle(XBrushes.LightBlue, LeaveBox); //add logo . Note file path and to change gfx.DrawImage(XImage.FromFile(@"C:\Users\grant\Downloads\IMG-20190629-WA0009.jpg"), 120, 0);//! note jpg! //add text gfx.DrawString("TEL: 0861 2468 73 | FAX: 086 508 0770 | info@househoppers ", font, XBrushes.Blue, new XRect(0, 90, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("746 Ribbon Ave, Little Falls | PO Box 1334, Subensvalley 1375", font, XBrushes.Blue, new XRect(0, 96, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("EMPLOYEE DETAILS", fontTitles, XBrushes.White, new XRect(0, 107, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("NAME", fontTitles, XBrushes.White, new XRect(100, 120, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("" + empName + " " + empSurname, fontDetails, XBrushes.Blue, new XRect(70, 120, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("ID", fontTitles, XBrushes.White, new XRect(100, 130, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("" + empID, fontDetails, XBrushes.Blue, new XRect(70, 130, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("ADDRESS", fontTitles, XBrushes.White, new XRect(100, 140, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("" + empAddress, fontDetails, XBrushes.Blue, new XRect(70, 140, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("PAY PERIOD", fontTitles, XBrushes.White, new XRect(100, 150, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("" + payPeriod, fontDetails, XBrushes.Blue, new XRect(70, 150, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("BANKING DETAILS", fontTitles, XBrushes.White, new XRect(100, 160, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("" + bankName + ", " + bankBranch + ", " + accountNumber + ", " + accountType + ", " + branchCode, fontDetails, XBrushes.Blue, new XRect(70, 160, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("TAX NUMBER", fontTitles, XBrushes.White, new XRect(100, 170, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("" + taxNumber, fontDetails, XBrushes.Blue, new XRect(70, 170, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("BASIC SALARY", fontTitles, XBrushes.DarkBlue, new XRect(100, 200, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + basicSalary, fontDetails, XBrushes.Blue, new XRect(-100, 200, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("COMMISION ON JOBS COMPLETED", fontTitles, XBrushes.DarkBlue, new XRect(100, 210, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + comCompletedJobs, fontDetails, XBrushes.Blue, new XRect(-100, 210, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("BONUS", fontTitles, XBrushes.DarkBlue, new XRect(100, 220, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + bonus, fontDetails, XBrushes.Blue, new XRect(-100, 220, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("TOTAL REMUNERATION", fontTitles, XBrushes.DarkBlue, new XRect(100, 230, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + totalRemuneration, fontDetails, XBrushes.Blue, new XRect(-100, 230, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("COMMISSION EARNED ON QUOTES ACCEPTED", fontTitles, XBrushes.White, new XRect(0, 245, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("WEEK 1", fontTitles, XBrushes.DarkBlue, new XRect(100, 260, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + comWeek1, fontDetails, XBrushes.Blue, new XRect(-100, 260, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 2", fontTitles, XBrushes.DarkBlue, new XRect(100, 270, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + comWeek2, fontDetails, XBrushes.Blue, new XRect(-100, 270, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 3", fontTitles, XBrushes.DarkBlue, new XRect(100, 280, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + comWeek3, fontDetails, XBrushes.Blue, new XRect(-100, 280, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 4", fontTitles, XBrushes.DarkBlue, new XRect(100, 290, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + comWeek4, fontDetails, XBrushes.Blue, new XRect(-100, 290, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 5", fontTitles, XBrushes.DarkBlue, new XRect(100, 300, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + comWeek5, fontDetails, XBrushes.Blue, new XRect(-100, 300, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("TOTAL COMMISION", fontTitles, XBrushes.DarkBlue, new XRect(100, 310, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + comTotal, fontDetails, XBrushes.Blue, new XRect(-100, 310, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("TOTAL EARNINGS", fontTitles, XBrushes.DarkBlue, new XRect(100, 325, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + totalEarnings, fontDetails, XBrushes.Blue, new XRect(-100, 325, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("TRAVEL REIMBURSMENT", fontTitles, XBrushes.White, new XRect(0, 340, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("WEEK 1", fontTitles, XBrushes.DarkBlue, new XRect(100, 350, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + travWeek1, fontDetails, XBrushes.Blue, new XRect(-100, 350, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 2", fontTitles, XBrushes.DarkBlue, new XRect(100, 360, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + travWeek2, fontDetails, XBrushes.Blue, new XRect(-100, 360, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 3", fontTitles, XBrushes.DarkBlue, new XRect(100, 370, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + travWeek3, fontDetails, XBrushes.Blue, new XRect(-100, 370, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 4", fontTitles, XBrushes.DarkBlue, new XRect(100, 380, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + travWeek4, fontDetails, XBrushes.Blue, new XRect(-100, 380, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("WEEK 5", fontTitles, XBrushes.DarkBlue, new XRect(100, 390, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + travWeek5, fontDetails, XBrushes.Blue, new XRect(-100, 390, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("TOTAL COMMISION", fontTitles, XBrushes.DarkBlue, new XRect(100, 400, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + travTotal, fontDetails, XBrushes.Blue, new XRect(-100, 400, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("DEDUCTIONS", fontTitles, XBrushes.White, new XRect(0, 415, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("UNPAID LEAVE", fontTitles, XBrushes.DarkBlue, new XRect(100, 425, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("DAYS " + unpaidLeaveDays, fontDetails, XBrushes.DarkBlue, new XRect(0, 425, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopCenter); gfx.DrawString("R " + unpaidLeave, fontDetails, XBrushes.Blue, new XRect(-100, 425, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("PAYE TAX", fontTitles, XBrushes.DarkBlue, new XRect(100, 435, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + payeTax, fontDetails, XBrushes.Blue, new XRect(-100, 435, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("UIF CONTRIBUTION", fontTitles, XBrushes.DarkBlue, new XRect(100, 445, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + UIF, fontDetails, XBrushes.Blue, new XRect(-100, 445, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("OTHER DEDUCTIONS", fontTitles, XBrushes.DarkBlue, new XRect(100, 455, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + otherDeduct, fontDetails, XBrushes.Blue, new XRect(-100, 455, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("TOTAL DEDUCTIONS", fontTitles, XBrushes.DarkBlue, new XRect(100, 465, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + totalDeducts, fontDetails, XBrushes.Blue, new XRect(-100, 465, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("NETT PAY", fontTitles, XBrushes.White, new XRect(100, 480, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString("R " + nettPay, fontDetails, XBrushes.White, new XRect(-100, 480, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); gfx.DrawString("LEAVE DAYS AVAILABLE", fontTitles, XBrushes.DarkBlue, new XRect(100, 495, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopLeft); gfx.DrawString(leaveDaysDate + " " + leaveDaysAva, fontDetails, XBrushes.DarkBlue, new XRect(-100, 495, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.TopRight); //saving pdf . NOTE surname being the save name & check default save location string pdfFilename = empSurname + "-" + payPeriod + ".pdf"; pdf.Save(pdfFilename); //optional. displays pdf Process.Start(pdfFilename); //needed to close pdfSharp gtx to create another pdf gfx.Dispose(); }
/// <summary> /// Generates a user specific PDF file with its name and the specific articles. /// </summary> /// <param name="content">The user specific articles.</param> /// <param name="userName">The users full name.</param> /// <returns>A (memory) stream build out of the PDF file.</returns> public static MemoryStream GeneratePdf(IEnumerable <ShortArticle> content, string userName) { try { using (new PerfTracer(nameof(GeneratePdf))) { using (PdfDocument document = new PdfDocument()) { var page = document.AddPage(); using (var gfx = XGraphics.FromPdfPage(page)) { // Set position coordinates double y = 30; double x = 50; // Create a font XFont titleFont; XFont bigFont; XFont normalFont; XFont smallFont; // Create a Stringformat XStringFormat format; // Create a Textformatter XTextFormatter tf; lock (lockObj) { titleFont = new XFont("OpenSans", 18, XFontStyle.Bold); bigFont = new XFont("OpenSans", 14, XFontStyle.Bold); normalFont = new XFont("OpenSans", 11, XFontStyle.Regular); smallFont = new XFont("OpenSans", 9, XFontStyle.Bold); format = new XStringFormat(); tf = new XTextFormatter(gfx); } // Create header CreateWelcomeTitle(y, x, gfx, userName, titleFont, bigFont, format); y += ((titleFont.Height) * 2); x += 5; // Create each single article foreach (var shortArticle in content) { // Check page size if (CheckIfNewPageIsNeeded(y, page) == true) { page = document.AddPage(new PdfPage(document)); var gfx2 = XGraphics.FromPdfPage(page); y = 30; x = 50; CreateWelcomeTitle(y, x, gfx2, userName, titleFont, bigFont, format); tf = new XTextFormatter(gfx2); y += ((titleFont.Height) * 2); x += 5; } // Create article title var lineCounter = GetLineCounter(shortArticle.Title, 64.00); tf.DrawString(shortArticle.Title, bigFont, new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black)), new XRect(x, y, 490, bigFont.Height * lineCounter)); y += ((bigFont.Height) * lineCounter); // Create article date lineCounter = GetLineCounter(shortArticle.Published.ToLongDateString(), 84.00); tf.DrawString(shortArticle.Published.ToLongDateString(), smallFont, new XSolidBrush(XColor.FromKnownColor(XKnownColor.Gray)), new XRect(x, y, 490, smallFont.Height * lineCounter)); y += (smallFont.Height * lineCounter); // Create short article lineCounter = GetLineCounter(shortArticle.ShortText, 74.00); tf.DrawString(shortArticle.ShortText, normalFont, new XSolidBrush(XColor.FromKnownColor(XKnownColor.Black)), new XRect(x, y, 490, normalFont.Height * lineCounter)); y += (normalFont.Height * lineCounter); // Create article link lineCounter = GetLineCounter(shortArticle.Link, 74.00); tf.DrawString(shortArticle.Link, normalFont, new XSolidBrush(XColor.FromKnownColor(XKnownColor.Blue)), new XRect(x, y, 490, normalFont.Height * lineCounter)); y += (bigFont.Height * lineCounter); } var stream = new MemoryStream(); document.Save(stream); //document.Save(@"C:\Users\Selina\Documents\GitHub\JackTheClipper_DEV\implementation\release_v0.3\EndpointService\Test\pdf.pdf"); //TODO: For testing, choose path. document.Close(); return(stream); } } } } catch (Exception e) { Console.WriteLine(e); return(null); } }
public static void Main(string[] args) { Console.WriteLine("Cero"); var t = Task.Run(() => { PdfDocument pdf = new PdfDocument(); pdf.Info.Title = "My First PDF"; PdfPage pdfPage = pdf.AddPage(); XGraphics graph = XGraphics.FromPdfPage(pdfPage); XFont font = new XFont("Verdana", 20, XFontStyle.Bold); graph.DrawString("This is my first PDF document", font, XBrushes.Black, new XRect(0, 0, pdfPage.Width.Point, pdfPage.Height.Point), XStringFormats.Center); string pdfFilename = "firstpage.pdf"; pdf.Save(pdfFilename); Process.Start(pdfFilename); DateTime dat = DateTime.Now; if (dat == DateTime.MinValue) { throw new ArgumentException("The clock is not working."); } if (dat.Hour > 17) { return("evening"); } else if (dat.Hour > 12) { return("afternoon"); } else { return("morning"); } }); var c = t.ContinueWith((antecedent) => { if (t.Status == TaskStatus.RanToCompletion) { Console.WriteLine("Good {0}!", antecedent.Result); Console.WriteLine("And how are you this fine {0}?", antecedent.Result); } else if (t.Status == TaskStatus.Faulted) { Console.WriteLine(t.Exception.GetBaseException().Message); } }); //t.Start(); //PDFAsync(); Console.WriteLine("Uno"); Console.Read(); }
protected void btnExportPdf_Click(object sender, EventArgs e) { // Populate report PopulateGrid(); var documentDirectory = String.Format("{0}\\Temp\\", System.AppDomain.CurrentDomain.BaseDirectory); var logoDirectory = String.Format("{0}\\img\\", System.AppDomain.CurrentDomain.BaseDirectory); string destName = string.Format("ROV_{0}.pdf", DateTime.Now.ToString("yyyyMMddhhmmsss")); string destFile = string.Format("{0}{1}", documentDirectory, destName); string logoName = string.Format("SIAPS_USAID_Horiz.jpg"); string logoFile = string.Format("{0}{1}", logoDirectory, logoName); string fontFile = string.Format("{0}\\arial.ttf", System.AppDomain.CurrentDomain.BaseDirectory); var linePosition = 60; var columnPosition = 30; // Create document PdfDocument pdfDoc = new PdfDocument(); // Create a new page PdfPage page = pdfDoc.AddPage(); page.Orientation = PageOrientation.Landscape; // Get an XGraphics object for drawing XGraphics gfx = XGraphics.FromPdfPage(page); XTextFormatter tf = new XTextFormatter(gfx); XPen pen = new XPen(XColor.FromArgb(255, 0, 0)); // Logo XImage image = XImage.FromFile(logoFile); gfx.DrawImage(image, 10, 10); // Create a new font Uri fontUri = new Uri(fontFile); try { XPrivateFontCollection.Global.Add(fontUri, "#Arial"); } catch { } XFont fontb = new XFont("Calibri", 10, XFontStyle.Bold | XFontStyle.Underline); XFont fontr = new XFont("Calibri", 10, XFontStyle.Regular); // Write header pdfDoc.Info.Title = "Outstanding Visit Report for " + DateTime.Now.ToString("yyyy-MM-dd HH:mm"); gfx.DrawString("Outstanding Visit Report for " + DateTime.Now.ToString("yyyy-MM-dd HH:mm"), fontb, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft); // Write filter linePosition += 24; //gfx.DrawString("Range From : " + txtSearchFrom.Value, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft); linePosition += 24; //gfx.DrawString("Range To : " + txtSearchTo.Value, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft); // Write content var pageCount = 1; var rowCount = 0; var cellCount = 0; ArrayList headerArray = new ArrayList(); ArrayList widthArray = new ArrayList(); foreach (TableRow row in dt_basic.Rows) { rowCount += 1; cellCount = 0; linePosition += 24; columnPosition = 30; if (linePosition >= 480) { pageCount += 1; page = pdfDoc.AddPage(); page.Orientation = PageOrientation.Landscape; linePosition = 60; gfx = XGraphics.FromPdfPage(page); tf = new XTextFormatter(gfx); // Logo gfx.DrawImage(image, 10, 10); gfx.DrawString("Outstanding Visit Report (Page " + pageCount.ToString() + ")", fontb, XBrushes.Black, new XRect(columnPosition, linePosition, page.Width.Point, 20), XStringFormats.TopLeft); linePosition += 24; /// rewrite column headers foreach (var header in headerArray) { cellCount += 1; var width = Convert.ToInt32(widthArray[cellCount - 1]); gfx.DrawString(header.ToString(), fontb, XBrushes.Black, new XRect(columnPosition, linePosition, width, 20), XStringFormats.TopLeft); columnPosition += width; } columnPosition = 30; linePosition += 24; cellCount = 0; } foreach (TableCell cell in row.Cells) { int[] ignore = { }; if (!ignore.Contains(cellCount)) { cellCount += 1; if (rowCount == 1) { widthArray.Add((int)cell.Width.Value * 5); headerArray.Add(cell.Text); gfx.DrawString(cell.Text, fontb, XBrushes.Black, new XRect(columnPosition, linePosition, cell.Width.Value * 5, 20), XStringFormats.TopLeft); columnPosition += (int)cell.Width.Value * 5; } else { var width = Convert.ToInt32(widthArray[cellCount - 1]); tf.DrawString(cell.Text, fontr, XBrushes.Black, new XRect(columnPosition, linePosition, width, 20), XStringFormats.TopLeft); columnPosition += width; } } } } pdfDoc.Save(destFile); Response.Clear(); Response.Buffer = true; Response.ContentEncoding = Encoding.UTF8; Response.ContentType = "application/pdf"; Response.AddHeader("content-disposition", String.Format("attachment;filename={0}", destName)); Response.Charset = ""; this.EnableViewState = false; Response.WriteFile(destFile); Response.End(); }
public override PdfDocument ToPdf() { var watch = new Stopwatch(); watch.Start(); //http://www.pdfsharp.net/wiki/Unicode-sample.ashx // Create new document var document = new PdfDocument(); var pdfString = "eXPRS Plan of Care - Services Delivered Report Form\n\n" + "Timesheet ID: " + Id + "\n" + "Status of Timesheet: " + Status + "\n" + "Customer Name: " + ClientName + "\n" + "Prime: " + ClientPrime + "\n" + "Provider Name: " + ProviderName + "\n" + "Provider Num: " + ProviderId + "\n" + "CM Organization: Multnomah Case Management\n" + "Form Type: " + FormType + "\n\n" + "Service Goal: " + ServiceGoal + "\n\n" + "Progress Notes: " + ProgressNotes + "\n\n" + "Submitted on: " + Submitted + "\n"; // Set font encoding to unicode var options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); var font = new XFont("Times New Roman", 12, XFontStyle.Regular, options); var page = document.AddPage(); var gfx = XGraphics.FromPdfPage(page); var tf = new XTextFormatter(gfx) { Alignment = XParagraphAlignment.Left }; tf.DrawString(pdfString, font, XBrushes.Black, new XRect(100, 100, page.Width - 200, 600), XStringFormats.TopLeft); // TABLE var doc = new Document(); var section = doc.AddSection(); var table = section.AddTable(); table.Style = "Table"; table.Borders.Width = 0.25; table.Borders.Left.Width = 0.5; table.Borders.Right.Width = 0.5; table.Rows.LeftIndent = 0; // Before you can add a row, you must define the columns var column = table.AddColumn("2.5cm"); column.Format.Alignment = ParagraphAlignment.Center; column = table.AddColumn("2.5cm"); column.Format.Alignment = ParagraphAlignment.Right; column = table.AddColumn("3cm"); column.Format.Alignment = ParagraphAlignment.Right; column = table.AddColumn("3.5cm"); column.Format.Alignment = ParagraphAlignment.Right; column = table.AddColumn("2cm"); column.Format.Alignment = ParagraphAlignment.Center; // Create the header of the table var row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Shading.Color = Colors.LightGreen; row.Cells[0].AddParagraph("Date"); row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].AddParagraph("Start/Time IN"); row.Cells[1].Format.Alignment = ParagraphAlignment.Left; row.Cells[2].AddParagraph("End/Time OUT"); row.Cells[2].Format.Alignment = ParagraphAlignment.Left; row.Cells[3].AddParagraph("Total hours for entry"); row.Cells[3].Format.Alignment = ParagraphAlignment.Left; row.Cells[4].AddParagraph("Group? (yes/no)"); row.Cells[4].Format.Alignment = ParagraphAlignment.Left; double totalHours = 0; foreach (var entry in TimeEntries) { row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Cells[0].AddParagraph(entry.Date.ToShortDateString()); row.Cells[0].Format.Alignment = ParagraphAlignment.Left; row.Cells[1].AddParagraph(entry.In.ToShortTimeString()); row.Cells[1].Format.Alignment = ParagraphAlignment.Left; row.Cells[2].AddParagraph(entry.Out.ToShortTimeString()); row.Cells[2].Format.Alignment = ParagraphAlignment.Left; totalHours += entry.Hours; row.Cells[3].AddParagraph(entry.Hours.ToString(CultureInfo.CurrentCulture)); row.Cells[3].Format.Alignment = ParagraphAlignment.Left; row.Cells[4].AddParagraph(entry.Group ? "Yes" : "No"); row.Cells[4].Format.Alignment = ParagraphAlignment.Left; } row = table.AddRow(); row.HeadingFormat = true; row.Format.Alignment = ParagraphAlignment.Center; row.Format.Font.Bold = true; row.Cells[0].AddParagraph("Total"); row.Cells[0].MergeRight = 2; row.Cells[0].Format.Alignment = ParagraphAlignment.Right; row.Cells[3].AddParagraph(totalHours + " Hours"); row.Cells[3].MergeRight = 1; row.Cells[3].Format.Alignment = ParagraphAlignment.Left; table.SetEdge(0, 0, 5, 1, Edge.Box, BorderStyle.Single, 0.75, Color.Empty); // Create a renderer and prepare (=layout) the document var docRenderer = new MigraDoc.Rendering.DocumentRenderer(doc); docRenderer.PrepareDocument(); // Render the paragraph. You can render tables or shapes the same way. docRenderer.RenderObject(gfx, XUnit.FromCentimeter(5), XUnit.FromCentimeter(13), "12cm", table); //END OF TABLE //This code section will add new pages with images. foreach (var uri in UriList) { using var wc = new WebClient(); using var objImage = XImage.FromStream(wc.OpenRead(uri)); //do stuff with the image var newPage = document.AddPage(); var gfx2 = XGraphics.FromPdfPage(newPage); gfx2.DrawImage(objImage, 0, 0, newPage.Width, newPage.Height); } watch.Stop(); Console.WriteLine("Time to Generate PDF: " + watch.Elapsed.Seconds + "." + watch.Elapsed.Milliseconds + " seconds"); return(document); }
public void GenerateChart() { try { Chart chart = new Chart(ChartType.Column2D); Series series = null; string dataFileName = GetDataFileName(); if (string.IsNullOrEmpty(dataFileName)) { this.Error = " Empty File Name "; return; } var daraSeries = GetRenderingData(dataFileName); if (daraSeries != null) { foreach (string key in daraSeries.Keys) { series = chart.SeriesCollection.AddSeries(); series.Name = key; series.Add(new double[] { Convert.ToDouble(daraSeries[key][Params.IndexOf(ParamName)]) }); } } // chart.XAxis.TickLabels.Format = "00"; chart.XAxis.MajorTickMark = TickMarkType.Outside; chart.XAxis.Title.Caption = Path.GetFileNameWithoutExtension(DataFileName); chart.YAxis.MajorTickMark = TickMarkType.Outside; chart.YAxis.HasMajorGridlines = true; chart.PlotArea.LineFormat.Color = XColors.DarkGray; chart.PlotArea.LineFormat.Width = 1; chart.PlotArea.LineFormat.Visible = true; chart.Legend.Docking = DockingType.Right; chart.DataLabel.Type = DataLabelType.Value; chart.DataLabel.Position = DataLabelPosition.OutsideEnd; string filename = System.IO.Path.Combine(SolutionFolder, @"Documents\", Guid.NewGuid().ToString().ToUpper() + ".pdf"); PdfDocument document = new PdfDocument(filename); chartFrame.Location = new XPoint(30, 30); chartFrame.Size = new XSize(500, 600); chartFrame.Add(chart); PdfPage page = document.AddPage(); page.Size = PageSize.Letter; XGraphics gfx = XGraphics.FromPdfPage(page); chartFrame.Draw(gfx); document.Close(); Process.Start(filename); } catch { this.Error = "Something went wrong when generating the PDF reports"; } }
static void Main() { // Create a new PDF document. var document = new PdfDocument(); // Create a font. var font = new XFont("Verdana", 14); // Create a page. var page = document.AddPage(); var gfx = XGraphics.FromPdfPage(page); // Create a PDF text annotation. var textAnnot = new PdfTextAnnotation(); textAnnot.Title = "This is the title"; textAnnot.Subject = "This is the subject"; textAnnot.Contents = "This is the contents of the annotation.\rThis is the 2nd line."; textAnnot.Icon = PdfTextAnnotationIcon.Note; gfx.DrawString("The first text annotation", font, XBrushes.Black, 30, 50, XStringFormats.Default); // Convert rectangle from world space to page space. This is necessary because the annotation is // placed relative to the bottom left corner of the page with units measured in point. var rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 60), new XSize(30, 30))); textAnnot.Rectangle = new PdfRectangle(rect); // Add the annotation to the page page.Annotations.Add(textAnnot); // Create another PDF text annotation which is open and transparent. textAnnot = new PdfTextAnnotation(); textAnnot.Title = "Annotation 2 (title)"; textAnnot.Subject = "Annotation 2 (subject)"; textAnnot.Contents = "This is the contents of the 2nd annotation."; textAnnot.Icon = PdfTextAnnotationIcon.Help; textAnnot.Color = XColors.LimeGreen; textAnnot.Opacity = 0.5; textAnnot.Open = true; gfx.DrawString("The second text annotation (opened)", font, XBrushes.Black, 30, 140, XStringFormats.Default); rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(30, 150), new XSize(30, 30))); textAnnot.Rectangle = new PdfRectangle(rect); // Add the 2nd annotation to the page. page.Annotations.Add(textAnnot); // Create a so-called rubber stamp annotation. I'm not sure if it is useful, but at least // it looks impressive... var rsAnnot = new PdfRubberStampAnnotation(); rsAnnot.Icon = PdfRubberStampAnnotationIcon.TopSecret; rsAnnot.Flags = PdfAnnotationFlags.ReadOnly; rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(100, 400), new XSize(350, 150))); rsAnnot.Rectangle = new PdfRectangle(rect); // Add the rubber stamp annotation to the page. page.Annotations.Add(rsAnnot); // PDF supports some more pretty types of annotations like PdfLineAnnotation, PdfSquareAnnotation, // PdfCircleAnnotation, PdfMarkupAnnotation (with the subtypes PdfHighlightAnnotation, PdfUnderlineAnnotation, // PdfStrikeOutAnnotation, and PdfSquigglyAnnotation), PdfSoundAnnotation, or PdfMovieAnnotation. // If you need one of them, feel encouraged to implement it. It is quite easy. rect = gfx.Transformer.WorldToDefaultPage(new XRect(new XPoint(100, 600), new XSize(350, 150))); var linkAnnotation = PdfLinkAnnotation.CreateWebLink(new PdfRectangle(rect), "http://www.pdfsharp.net"); page.Annotations.Add(linkAnnotation); // Save the document... const string filename = "Annotations_tempfile.pdf"; document.Save(filename); // ...and start a viewer. Process.Start(filename); }
public static void SaveTest() { XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always); initialize(); PdfPage page = _document.AddPage(); XGraphics X = XGraphics.FromPdfPage(page, XGraphicsPdfPageOptions.Prepend); page.Size = PageSize.A4; double width = page.Width; double height = page.Height; double top = _margins.Top; double bottom = _margins.Bottom; double left = _margins.Left; double right = _margins.Right * 2; double y = top; double x = left; XFont titleFont = new XFont("Calibri", 14F, XFontStyle.Bold, options); XFont fontW = new XFont("Calibri", 100F, XFontStyle.Regular, options); XFont fontQ = new XFont("Calibri", 12F, XFontStyle.Regular, options); XFont fontA = new XFont("Calibri", 11F, XFontStyle.Regular, options); var img = new Bitmap(1, 1); XGraphics E = XGraphics.FromGraphics(Graphics.FromImage(img), new XSize()); X.DrawStringML(_title, titleFont, XBrushes.Black, x, ref y, width - right); y += titleFont.GetHeight() + 20; X.DrawString("Date: " + _date, fontQ, Brushes.Black, width - right - 40, y); X.DrawString("First Name: ___________________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Last Name: ___________________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Class: ________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 5; X.DrawString("Points:________", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 35; X.DrawString("Choose the correct answer. There might be more than one correct answers.", fontQ, Brushes.Black, x, y); y += fontQ.GetHeight() + 20; for (int i = 0; i < _test.Count; i++) { string question = (i + 1) + ". " + _test[i].question; //Ipologismos gia allagi selidas double tempY = y; E.DrawStringML(question, fontQ, Brushes.Black, x, ref tempY, width - right); if (tempY > height - bottom) { watermarkprint(X, page, fontW); page = _document.AddPage(); page.Size = PageSize.A4; X = XGraphics.FromPdfPage(page); y = top; } //Prints Questions X.DrawStringML(question, fontQ, XBrushes.Black, x, ref y, width - right); for (int k = 0; k < _test[i].anwsers.Count; k++) { string answer = _test[i].anwsers[k].text; //ipologismos gia allagi selida tempY = y; E.DrawStringML(answer, fontQ, Brushes.Black, x, ref tempY, width - right); if (tempY > height - bottom) { watermarkprint(X, page, fontW); page = _document.AddPage(); page.Size = PageSize.A4; X = XGraphics.FromPdfPage(page); y = top; } y += 3; //Edw tipwnei apantisi X.DrawRectangle(new Pen(Color.Black), x + 15, y, 20, 20); if (_solved && _test[i].anwsers[k].correct) { var cube = new Bitmap(20, 20); Graphics C = Graphics.FromImage(cube); C.FillRectangle(Brushes.Black, 0, 0, 20, 20); X.DrawImage(cube, x + 15, y, 20, 20); } y += 12; X.DrawStringML(answer, fontA, Brushes.Black, x + 45, ref y, width - right); } y += 30; } watermarkprint(X, page, fontW); _document.Save(_savePath); Process.Start(_savePath); }
public List <int[, ]> MakePDF(List <int[, ]> cards, string _saveLoc) { string imgName = @"bingo1.png"; string imgSource = Path.Combine(Directory.GetCurrentDirectory(), "..\\..\\", @"Resources\", imgName); if (_outputDirectory != null) { imgSource = _outputDirectory; } string saveLoc = imgSource.Replace("png", "pdf"); PdfDocument doc = new PdfDocument(); saveLoc = _saveLoc + ".pdf"; XImage img = XImage.FromFile(imgSource); XFont numberFont = new XFont("Verdana", 125, XFontStyle.Italic); XFont plateNumFont = new XFont("Verdana", 30, XFontStyle.Regular); XImage pdfSize = XImage.FromFile(imgSource); #region PixelStuff int startPlateY = 834; int startX = 356; int jumpX = 222; int jumpY = 240; int jumpYPlate = 796; int plateNumX = 45; int plateNumY = 3300; #endregion for (int i = 0; i < cards.Count; i++) { if (cards[i][0, 0] != -1) { PdfPage page = new PdfPage(); //Template for page //XSize size = PageSizeConverter.ToSize(PdfSharp.PageSize.A4); page.Width = pdfSize.PixelWidth; page.Height = pdfSize.PixelHeight; page.TrimMargins.Top = 0; page.TrimMargins.Right = 0; page.TrimMargins.Bottom = 0; page.TrimMargins.Left = -30; doc.Pages.Add(page); XGraphics xgr = XGraphics.FromPdfPage(doc.Pages[doc.PageCount - 1]); xgr.DrawImage(img, 0, 0, page.Width, page.Height); int plateChooser = startPlateY; int rowChooser = plateChooser; int columnChooser = startX; for (int j = 0; j < 3; j++) //Pladenummer. Styrer y-akses startpunkt { rowChooser = plateChooser; for (int row = 0; row < 3; row++) //rækkenummer. Placerer y-akseværdi { for (int column = 0; column < 9; column++) { if (cards[i][column, row] != 0) { if (cards[i][column, row] < 10) { xgr.DrawString(" " + Convert.ToString(cards[i][column, row]), numberFont, XBrushes.Black, new XRect(columnChooser, rowChooser, 10, 0), XStringFormats.TopLeft); } else { xgr.DrawString(Convert.ToString(cards[i][column, row]), numberFont, XBrushes.Black, new XRect(columnChooser, rowChooser, 10, 0), XStringFormats.TopLeft); } } columnChooser += jumpX; //Hopper med en kolonne per iteration } columnChooser = startX; rowChooser += jumpY; //Hopper en række per iteration } plateChooser += jumpYPlate; // hopper en plade per iteration } xgr.DrawString("Pladenummer: " + Convert.ToString(i), plateNumFont, XBrushes.Black, new XRect(plateNumX, plateNumY, 10, 0), XStringFormats.TopLeft); } } doc.Save(saveLoc); doc.Close(); return(cards); }
//Exporting a list of images to a pdf document public static void ExportImageToPdf(List <Bitmap> ImageList, string path) { PdfDocument doc = new PdfDocument(); foreach (Bitmap image in ImageList) { //Initializing new pdf document and pages PdfPage oPage = new PdfPage(); //Adding the page to the document doc.Pages.Add(oPage); //Creating a graphics element form the pdf page XGraphics xgr = XGraphics.FromPdfPage(oPage); if (image.Width > image.Height) { image.RotateFlip(RotateFlipType.Rotate270FlipNone); } using (MemoryStream ms = new MemoryStream()) { image.Save(ms, System.Drawing.Imaging.ImageFormat.Jpeg); //Creating an XImage from the image XImage img = XImage.FromStream(ms); double ratioHeight = image.Height / oPage.Height; double ratioWidth = image.Width / oPage.Width; double newWidth = 0; double newHeight = 0; if (ratioHeight > 1 && ratioHeight > ratioWidth) { newWidth = image.Width / (image.Height / (oPage.Height - 40)); xgr.DrawImage(img, 0, 0, newWidth, oPage.Height - 40); } else if (ratioWidth > 1 && ratioWidth > ratioHeight) { newHeight = image.Height / (image.Width / (oPage.Width - 40)); xgr.DrawImage(img, 0, 0, oPage.Width - 40, newHeight); } else { xgr.DrawImage(img, 0, 0); } img = null; } xgr = null; } try { doc.Save(path); } catch { ((ShellViewModel)IoC.Get <IShell>()).ShowError("File in use."); } doc.Close(); }
public void SaveToPdf() { ResetPreviewControl(); using (var saveDialog = new SaveFileDialog { Filter = Resources.FileFilterPDF, FilterIndex = 0, FileName = PreselectedPdfFileName }) { if (saveDialog.ShowDialog() == DialogResult.OK) { PreselectedPdfFileName = string.Empty; var wasForPdf = ForPdf; Cursor = Cursors.WaitCursor; try { var document = new PdfDocument(); document.Info.Title = Controller.SourceImage.Description; document.Info.Author = SystemInformation.UserName; document.Info.Creator = AppInfo.AppDescription + " (" + AppInfo.AppVersion + ")"; document.Info.CreationDate = DateTime.Now; document.Info.ModificationDate = document.Info.CreationDate; document.Info.Subject = Resources.SaeFileDescription; var pageSettings = printDocument.DefaultPageSettings; var pageMargins = pageSettings.Margins; var pageWidth = new XUnit(pageSettings.PaperSize.Width * 72.0 / 100.0, XGraphicsUnit.Point); var pageHeight = new XUnit(pageSettings.PaperSize.Height * 72.0 / 100.0, XGraphicsUnit.Point); if (pageSettings.Landscape) { var x = pageWidth; pageWidth = pageHeight; pageHeight = x; } var pageSize = new Size((int)pageWidth.Point, (int)pageHeight.Point); var marginsRect = new Rectangle( pageMargins.Left * 72 / 100, pageMargins.Top * 72 / 100, pageSize.Width - (pageMargins.Left + pageMargins.Right) * 72 / 100, pageSize.Height - (pageMargins.Top + pageMargins.Bottom) * 72 / 100); ForPdf = true; UpdatePagePrintSize(Controller); using (var form = new Form { Text = Resources.PrintSavingToPdf, Size = new System.Drawing.Size(200, 130), TopMost = true, FormBorderStyle = FormBorderStyle.FixedDialog, ShowIcon = false, ControlBox = false }) { using (var painter = new PdfSharpPainter(IndexedImageExtensions.ToBitmap) { FontName = Controller.GridPainter.SymbolsFont.Name, FontFamily = FontHelper.GetFontFamily(Controller.GridPainter.SymbolsFont.Name) }) { var progressLabel = new Label { Location = new System.Drawing.Point(32, 24), AutoSize = true }; form.Controls.Add(progressLabel); form.Show(); for (int i = 0; i < Controller.PagesCount; i++) { progressLabel.Text = string.Format(Resources.PrintPageNo, i + 1, Controller.SourceImage.Description); form.Invalidate(); form.Update(); var page = document.AddPage(); page.Orientation = pageSettings.Landscape ? PageOrientation.Landscape : PageOrientation.Portrait; page.Width = pageWidth; page.Height = pageHeight; using (var pdfGraphics = XGraphics.FromPdfPage(page)) { painter.PdfGraphics = pdfGraphics; // Keep same painter for different pages to share fonts Controller.PaintPrintPageImage( painter, i, pageSize, marginsRect, AppInfo.AppDescription, Controller.SourceImage.Description ?? Resources.UnsavedImageDescription); } } } document.Save(saveDialog.FileName); } if (File.Exists(saveDialog.FileName)) { Process.Start(saveDialog.FileName); } Dispose(); } catch (IOException ex) { MessageBox.Show(Resources.ErrorSavePdf + Environment.NewLine + ex.Message); ForPdf = wasForPdf; UpdatePagePrintSize(Controller); Cursor = DefaultCursor; } } } }