/// <summary>Calculates the common rectangle which includes all the input rectangles.</summary> /// <param name="rectangles">list of input rectangles.</param> /// <returns>common rectangle.</returns> public static iText.Kernel.Geom.Rectangle GetCommonRectangle(params iText.Kernel.Geom.Rectangle[] rectangles ) { float ury = -float.MaxValue; float llx = float.MaxValue; float lly = float.MaxValue; float urx = -float.MaxValue; foreach (iText.Kernel.Geom.Rectangle rectangle in rectangles) { if (rectangle == null) { continue; } iText.Kernel.Geom.Rectangle rec = rectangle.Clone(); if (rec.GetY() < lly) { lly = rec.GetY(); } if (rec.GetX() < llx) { llx = rec.GetX(); } if (rec.GetY() + rec.GetHeight() > ury) { ury = rec.GetY() + rec.GetHeight(); } if (rec.GetX() + rec.GetWidth() > urx) { urx = rec.GetX() + rec.GetWidth(); } } return(new iText.Kernel.Geom.Rectangle(llx, lly, urx - llx, ury - lly)); }
/// <summary>Check if this rectangle and the passed rectangle overlap</summary> /// <param name="rect">a rectangle which is to be checked if it overlaps the passed rectangle</param> /// <param name="epsilon"> /// if greater than zero, then this is the maximum distance that one rectangle can go to another, but /// they will not overlap, if less than zero, then this is the minimum required distance between the /// rectangles so that they do not overlap /// </param> /// <returns>true if there is overlap of some kind</returns> public virtual bool Overlaps(iText.Kernel.Geom.Rectangle rect, float epsilon) { // Two rectangles do not overlap if any of the following holds // The first rectangle lies to the left of the second rectangle or touches very slightly if ((this.GetX() + this.GetWidth()) < (rect.GetX() + epsilon)) { return(false); } // The first rectangle lies to the right of the second rectangle or touches very slightly if ((this.GetX() + epsilon) > (rect.GetX() + rect.GetWidth())) { return(false); } // The first rectangle lies to the bottom of the second rectangle or touches very slightly if ((this.GetY() + this.GetHeight()) < (rect.GetY() + epsilon)) { return(false); } // The first rectangle lies to the top of the second rectangle or touches very slightly if ((this.GetY() + epsilon) > (rect.GetY() + rect.GetHeight())) { return(false); } return(true); }
/// <summary> /// Gets the rectangle as it looks on the rotated page /// and returns the rectangle in coordinates relevant to the true page origin. /// </summary> /// <remarks> /// Gets the rectangle as it looks on the rotated page /// and returns the rectangle in coordinates relevant to the true page origin. /// This rectangle can be used to add annotations, fields, and other objects /// to the rotated page. /// </remarks> /// <param name="rect">the rectangle as it looks on the rotated page.</param> /// <param name="page">the page on which one want to process the rectangle.</param> /// <returns>the newly created rectangle with translated coordinates.</returns> public static iText.Kernel.Geom.Rectangle GetRectangleOnRotatedPage(iText.Kernel.Geom.Rectangle rect, PdfPage page) { iText.Kernel.Geom.Rectangle resultRect = rect; int rotation = page.GetRotation(); if (0 != rotation) { iText.Kernel.Geom.Rectangle pageSize = page.GetPageSize(); switch ((rotation / 90) % 4) { case 1: { // 90 degrees resultRect = new iText.Kernel.Geom.Rectangle(pageSize.GetWidth() - resultRect.GetTop(), resultRect.GetLeft (), resultRect.GetHeight(), resultRect.GetWidth()); break; } case 2: { // 180 degrees resultRect = new iText.Kernel.Geom.Rectangle(pageSize.GetWidth() - resultRect.GetRight(), pageSize.GetHeight () - resultRect.GetTop(), resultRect.GetWidth(), resultRect.GetHeight()); break; } case 3: { // 270 degrees resultRect = new iText.Kernel.Geom.Rectangle(resultRect.GetLeft(), pageSize.GetHeight() - resultRect.GetRight (), resultRect.GetHeight(), resultRect.GetWidth()); break; } case 4: default: { // 0 degrees break; } } } return(resultRect); }
/// <summary>Check if this rectangle and the passed rectangle overlap</summary> /// <param name="rect"/> /// <returns>true if there is overlap of some kind</returns> public virtual bool Overlaps(iText.Kernel.Geom.Rectangle rect) { // Two rectangles do not overlap if any of the following holds // 1. the lower left corner of the second rectangle is to the right of the upper-right corner of the first. return(!(this.GetX() + this.GetWidth() < rect.GetX() || // 2. the lower left corner of the second rectangle is above the upper right corner of the first. this.GetY() + this.GetHeight() < rect.GetY() || // 3. the upper right corner of the second rectangle is to the left of the lower-left corner of the first. this.GetX() > rect.GetX() + rect.GetWidth() || // 4. the upper right corner of the second rectangle is below the lower left corner of the first. this.GetY() > rect.GetY() + rect.GetHeight())); }
public void Draw(PdfCanvas canvas, iText.Kernel.Geom.Rectangle drawArea) { float coordY = drawArea.GetY() + lineWidth / 2 + offset; canvas .SaveState() .SetStrokeColor(color) .SetLineWidth(lineWidth) .MoveTo(drawArea.GetX(), coordY) .LineTo(drawArea.GetX() + drawArea.GetWidth(), coordY) .Stroke() .RestoreState(); }
/// <summary>Check if this rectangle contains the passed rectangle.</summary> /// <remarks> /// Check if this rectangle contains the passed rectangle. /// A rectangle will envelop itself, meaning that for any rectangle /// <paramref name="rect"/> /// the expression /// <c>rect.contains(rect)</c> /// always returns true. /// </remarks> /// <param name="rect">a rectangle which is to be checked if it is fully contained inside this rectangle.</param> /// <returns>true if this rectangle contains the passed rectangle, false otherwise.</returns> public virtual bool Contains(iText.Kernel.Geom.Rectangle rect) { float llx = this.GetX(); float lly = this.GetY(); float urx = llx + this.GetWidth(); float ury = lly + this.GetHeight(); float rllx = rect.GetX(); float rlly = rect.GetY(); float rurx = rllx + rect.GetWidth(); float rury = rlly + rect.GetHeight(); return(llx - EPS <= rllx && lly - EPS <= rlly && rurx <= urx + EPS && rury <= ury + EPS); }
override public void Draw(DrawContext drawContext) { base.Draw(drawContext); iText.Kernel.Geom.Rectangle cuadro = GetOccupiedAreaBBox(); cuadro.MoveUp(margenExterior).MoveRight(margenExterior); cuadro.SetHeight(cuadro.GetHeight() - (margenExterior * 2)); cuadro.SetWidth(cuadro.GetWidth() - (margenExterior * 2)); PdfTextFormField field = PdfFormField.CreateText(drawContext.GetDocument(), cuadro, fieldName, valor); field.SetJustification(justificacion); field.SetVisibility(PdfFormField.VISIBLE); field.SetFontSize(fontSize); PdfAcroForm form = PdfAcroForm.GetAcroForm(drawContext.GetDocument(), true); form.AddField(field); }
private Rectangle GetUpperOrLowerAnnotationRect(Rectangle buttonRect, PdfFont font, IAnnotation annotation, Pdf.IWord target, bool upper = true) { var contentBounds = GetContentBounds(annotation.Content, target.Parent.Width / 2, font); var targetWidthHalf = buttonRect.GetWidth() / 2; var helpWidthHalf = contentBounds.width / 2; var annotHeight = contentBounds.height + 6; float annotY; if (upper) { annotY = buttonRect.GetY() + buttonRect.GetHeight() + 5; } else { annotY = buttonRect.GetY() - annotHeight - 10; } var helpRect = new Rectangle(buttonRect.GetX() + targetWidthHalf - helpWidthHalf - 5, annotY, contentBounds.width + 10, annotHeight); return(helpRect); }
public static void RotarPDF(string ficheroDestino, string ficheroOrigen, int angulo) { PdfDocument pdfDoc = new PdfDocument(new PdfReader(ficheroOrigen), new PdfWriter(ficheroDestino)); int margin = 72; for (int i = 1; i <= pdfDoc.GetNumberOfPages(); i++) { PdfPage page = pdfDoc.GetPage(i); // change page size iText.Kernel.Geom.Rectangle mediaBox = page.GetMediaBox(); iText.Kernel.Geom.Rectangle newMediaBox = new iText.Kernel.Geom.Rectangle((int)mediaBox.GetLeft() - margin, (int)mediaBox.GetBottom() - margin, (int)mediaBox.GetWidth() + margin * 2, (int)mediaBox.GetHeight() + margin * 2); page.SetMediaBox(newMediaBox); // add border PdfCanvas over = new PdfCanvas(page); over.Rectangle(mediaBox.GetLeft(), mediaBox.GetBottom(), mediaBox.GetWidth(), mediaBox.GetHeight()); over.Stroke(); // change rotation of the even pages page.SetRotation(angulo); } pdfDoc.Close(); }
public void HandleEvent(Event @event) { PdfDocumentEvent docEvent = (PdfDocumentEvent)@event; PdfPage page = docEvent.GetPage(); int pageNumber = docEvent.GetDocument().GetNumberOfPages(); var bgColor = ((SolidColorBrush)Pages[pageNumber - 1].Canvas.Background).Color; var pageColor = new iText.Kernel.Colors.DeviceRgb( Convert.ToInt32(bgColor.R), Convert.ToInt32(bgColor.G), Convert.ToInt32(bgColor.B) ); PdfCanvas canvas = new PdfCanvas(page); iText.Kernel.Geom.Rectangle rect = page.GetPageSize(); canvas.SaveState() .SetFillColor(pageColor) .Rectangle(rect.GetLeft(), rect.GetBottom(), rect.GetWidth(), rect.GetHeight()) .FillStroke() .RestoreState(); }
public string AddPageNumber(string nomeFileIn, string nomeFileOut, ref Esito esito) { string ret = nomeFileOut; try { FileInfo file = new FileInfo(nomeFileOut); //file.Directory.Create(); PdfDocument pdfDoc = new PdfDocument(new PdfReader(nomeFileIn), new PdfWriter(nomeFileOut)); Document doc = new Document(pdfDoc); iText.Kernel.Geom.Rectangle pageSize = pdfDoc.GetPage(1).GetPageSize(); int n = pdfDoc.GetNumberOfPages(); for (int i = 1; i <= n; i++) { //doc.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), // 520, 815, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); doc.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); } doc.Close(); ret = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + Path.GetFileName(nomeFileOut); } catch (Exception ex) { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "AddPageNumber: " + nomeFileIn + "," + nomeFileOut + Environment.NewLine + ex.Message; BasePage b = new BasePage(); b.ShowError(esito.Descrizione); return(ret); } return(ret); }
public Esito popolaPannelloGiornata() { Esito esito = new Esito(); try { // LEGGO I PARAMETRI DI VS Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA"); string pIvaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE"); string denominazioneVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO"); string toponimoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO"); string indirizzoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO"); string civicoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP"); string capVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA"); string cittaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA"); string provinciaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL"); string emailVs = cfAppo.valore; // GESTIONE NOMI FILE PDF string nomeFile = "RiepilogoGiornata.pdf"; string pathGiornata = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile; string mapPathGiornata = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile; iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png")); iText.IO.Image.ImageData imageDNV = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/DNV_2008_ITA2.jpg")); PdfWriter wr = new PdfWriter(mapPathGiornata); PdfDocument doc = new PdfDocument(wr); doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate()); //Document document = new Document(doc); Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4.Rotate(), false); // IMPOSTO LA DATA DI OGGI SE PRIMA ELABORAZIONE if (string.IsNullOrEmpty(tbDataElaborazione.Text.Trim())) { tbDataElaborazione.Text = DateTime.Today.ToShortDateString(); } document.SetMargins(90, 35, 50, 35); Paragraph pSpazio = new Paragraph(""); document.Add(pSpazio); // COLORE BLU VIDEOSYSTEM iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243); DateTime dataTmp = Convert.ToDateTime(tbDataElaborazione.Text.Trim()); string sDataTmp = dataTmp.ToString("yyyy-MM-dd") + "T00:00:00.000"; string queryRicerca = "select dal.descrizione as qualifica,ac.cognome as cognome_operatore, ac.nome as nome_operatore, da.codice_lavoro,produzione,lavorazione " + //", da.durata_lavorazione as Durata , ca.nome,ts.nome,tt.nome " + //", ac.cognome as cognome_operatore,ac.nome as nome_operatore, dal.descrizioneLunga " + "from[dbo].[tab_dati_agenda] da " + "left join tipo_colonne_agenda ca " + "on da.id_colonne_agenda = ca.id " + "left join tipo_stato ts " + "on da.id_stato = ts.id " + "left join tipo_tipologie tt " + "on da.id_tipologia = tt.id " + "left join dati_lavorazione dl " + "on dl.idDatiAgenda = da.id " + "left join dati_articoli_lavorazione dal " + "on dl.id = dal.idDatiLavorazione " + "left join anag_collaboratori ac " + "on dal.idCollaboratori = ac.id " + "where ac.cognome is not null and dal.descrizione<> 'Diaria' " + "and data_inizio_lavorazione <= '@dataElaborazione' and data_fine_lavorazione >= '@dataElaborazione' " + //"order by codice_lavoro, dal.descrizione, ac.cognome, ac.nome"; "group by dal.descrizione ,ac.cognome, ac.nome, da.codice_lavoro,produzione,lavorazione " + //"order by qualifica,ac.cognome, ac.nome, codice_lavoro"; "order by codice_lavoro,qualifica,ac.cognome, ac.nome"; queryRicerca = queryRicerca.Replace("@dataElaborazione", sDataTmp); esito = new Esito(); DataTable dtProtocolli = Base_DAL.GetDatiBySql(queryRicerca, ref esito); if (dtProtocolli != null && dtProtocolli.Rows != null && dtProtocolli.Rows.Count > 0) { // INTESTAZIONE GRIGLIA iText.Layout.Element.Table table = new iText.Layout.Element.Table(3).UseAllAvailableWidth(); //Paragraph intestazione = new Paragraph("Codice Lavoro").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); //table.AddHeaderCell(intestazione); //intestazione = new Paragraph("Produzione").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); //table.AddHeaderCell(intestazione); //intestazione = new Paragraph("Lavorazione").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); //table.AddHeaderCell(intestazione); Paragraph intestazione = new Paragraph("Qualifica").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Cognome").SetFontSize(10).SetBold().SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Nome").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); string codice_lavoro = ""; foreach (DataRow riga in dtProtocolli.Rows) { string qualifica = ""; string cognome = ""; string nome = ""; string produzione = ""; string lavorazione = ""; //Cell cellaQualifica = new Cell(); //if (!riga["qualifica"].ToString().ToUpper().Equals(qualifica.ToUpper())) //{ // Paragraph pQualifica = new Paragraph(riga["qualifica"].ToString()).SetFontSize(8).SetBold(); // cellaQualifica.Add(pQualifica); // qualifica = riga["qualifica"].ToString(); //} //else //{ // Paragraph pQualifica = new Paragraph("").SetFontSize(8).SetBold(); // cellaQualifica.Add(pQualifica); //} //table.AddCell(cellaQualifica); Cell cellaLavorazione = new Cell(1, 3); if (!riga["codice_lavoro"].ToString().ToUpper().Equals(codice_lavoro.ToUpper())) { if (riga["produzione"] != null) { produzione = riga["produzione"].ToString(); } if (riga["lavorazione"] != null) { lavorazione = riga["lavorazione"].ToString(); } Paragraph pCodiceLavoro = new Paragraph(riga["codice_lavoro"].ToString() + " - Produzione: " + produzione + " - Lavorazione: " + lavorazione).SetFontSize(10).SetBold(); cellaLavorazione.Add(pCodiceLavoro).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); codice_lavoro = riga["codice_lavoro"].ToString(); table.AddCell(cellaLavorazione); } //else //{ // Paragraph pCodiceLavoro = new Paragraph("").SetFontSize(8).SetBold(); // cellaLavorazione.Add(pCodiceLavoro); //} //table.AddCell(cellaLavorazione); if (riga["qualifica"] != null) { qualifica = riga["qualifica"].ToString(); } if (riga["cognome_operatore"] != null) { cognome = riga["cognome_operatore"].ToString(); } if (riga["nome_operatore"] != null) { nome = riga["nome_operatore"].ToString(); } //table.AddCell(produzione).SetFontSize(8); //table.AddCell(lavorazione).SetFontSize(8); Cell cellaQualifica = new Cell(); Paragraph pQualifica = new Paragraph(qualifica).SetFontSize(9).SetBold(); cellaQualifica.Add(pQualifica).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); table.AddCell(cellaQualifica); table.AddCell(cognome).SetFontSize(9); table.AddCell(nome).SetFontSize(9); } document.Add(table); } int n = doc.GetNumberOfPages(); iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize(); // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA for (int i = 1; i <= n; i++) { // AGGIUNGO LOGO iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(60, 60).SetFixedPosition(i, 20, pageSize.GetHeight() - 80); document.Add(image); // AGGIUNGO LOGO DNV iText.Layout.Element.Image logoDnv = new iText.Layout.Element.Image(imageDNV).ScaleAbsolute(40, 40).SetFixedPosition(i, 780, 8); document.Add(logoDnv); //AGGIUNGO NUM.PAGINA document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); // AGGIUNGO TITOLO document.ShowTextAligned(new Paragraph("OPERATORI IMPEGNATI PER IL " + tbDataElaborazione.Text.Trim()).SetFontSize(11), 400, pageSize.GetHeight() - 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); //AGGIUNGO FOOTER document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER), pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); if (i == n) { // ULTIMA PAGINA } } document.Close(); wr.Close(); if (File.Exists(mapPathGiornata)) { framePdfGiornata.Attributes.Remove("src"); framePdfGiornata.Attributes.Add("src", pathGiornata.Replace("~", "")); DivFramePdfGiornata.Visible = true; framePdfGiornata.Visible = true; ScriptManager.RegisterStartupScript(Page, typeof(Page), "aggiornaFrame", script: "javascript: document.getElementById('" + framePdfGiornata.ClientID + "').contentDocument.location.reload(true);", addScriptTags: true); btnStampaGiornata.Attributes.Add("onclick", "window.open('" + pathGiornata.Replace("~", "") + "');"); //} } else { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "Il File " + pathGiornata.Replace("~", "") + " non è stato creato correttamente!"; } } catch (Exception ex) { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "popolaPannelloGiornata() " + ex.Message + Environment.NewLine + ex.StackTrace; } return(esito); }
/// <summary> /// Creates the copy of given /// <see cref="Rectangle"/> /// </summary> /// <param name="rect"> /// the copied /// <see cref="Rectangle"/> /// </param> public Rectangle(iText.Kernel.Geom.Rectangle rect) : this(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight()) { }
/// <summary>Check if this rectangle and the passed rectangle overlap</summary> /// <param name="rect"/> /// <returns>true if there is overlap of some kind</returns> public virtual bool Overlaps(iText.Kernel.Geom.Rectangle rect) { // Two rectangles do not overlap if any of the following holds return(!(this.GetX() + this.GetWidth() < rect.GetX() || this.GetY() + this.GetHeight() < rect.GetY() || this .GetX() > rect.GetX() + rect.GetWidth() || this.GetY() > rect.GetY() + rect.GetHeight())); }
//private void Helper_GeneralSummary(GridViewRow row) //{ // row.BackColor = Color.Gray; // row.Cells[0].HorizontalAlign = HorizontalAlign.Right; // row.Cells[0].Text = "<b>Totale</b>"; // row.Cells[1].Text = "<b>" + row.Cells[1].Text + "</b>"; // row.Cells[2].Text = "<b>" + row.Cells[2].Text + "</b>"; // row.Cells[3].Text = "<b>" + row.Cells[3].Text + "</b>"; // row.Cells[4].Text = "<b>" + row.Cells[4].Text + "</b>"; // row.Cells[5].Text = "<b>" + row.Cells[5].Text + "</b>"; // //row.Cells[6].Text = "<b>" + row.Cells[6].Text + "</b>"; //} protected void btnStampa_Click(object sender, EventArgs e) { try { Esito esito = new Esito(); DateTime dataInizio = DateTime.Parse(txt_DataInizio.Text); DateTime dataFine = DateTime.Parse(txt_DataFine.Text); string nominativo = txt_Nominativo.Text; string lavorazione = txt_Lavorazione.Text; string produzione = txt_Produzione.Text; bool soloFornitori = chk_Fornitore.Checked; List <DatiReport> listaDatiReport = Report_BLL.Instance.GetListaDatiReportCollaboratoriFornitori(dataInizio, dataFine, nominativo, lavorazione, produzione, soloFornitori, ref esito); Report_BLL.Instance.EliminaCollaboratoriImportoZero(ref listaDatiReport); if (esito.Codice == 0 && listaDatiReport != null && listaDatiReport.Count > 0) { // LEGGO I PARAMETRI DI VS Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA"); string pIvaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE"); string denominazioneVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO"); string toponimoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO"); string indirizzoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO"); string civicoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP"); string capVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA"); string cittaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA"); string provinciaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL"); string emailVs = cfAppo.valore; // export SU PDF string nomeFile = "Report_Collaboratori.pdf"; string pathReport = ConfigurationManager.AppSettings["PATH_DOCUMENTI_REPORT"] + nomeFile; string mapPathReport = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_REPORT"]) + nomeFile; //string prefissoUrl = Request.Url.Scheme + "://" + Request.Url.Authority; iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png")); PdfWriter wr = new PdfWriter(mapPathReport); PdfDocument doc = new PdfDocument(wr); doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate()); //doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4); Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4.Rotate(), false); document.SetMargins(50, 30, 50, 30); //iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(0, 225, 0); // COLORE BLU VIDEOSYSTEM iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243); //CICLO LISTA DATI REPORT int totCollaboratoriUtilizzati = 0; foreach (DatiReport collaboratore in listaDatiReport) { totCollaboratoriUtilizzati++; // AGGIUNGO TABLE PER LAYOUT INTESTAZIONE iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(new float[] { 1, 9 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER); iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(100, 70).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); Cell cellaImmagine = new Cell().SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.MIDDLE).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); cellaImmagine.Add(image); tbIntestazione.AddCell(cellaImmagine); iText.Layout.Element.Table tbIntestazioneDx = new iText.Layout.Element.Table(new float[] { 4, 6 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER); Paragraph pTitolo = new Paragraph("Nome").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); Paragraph pValore = new Paragraph(collaboratore.NomeCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Qualifica").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pValore = new Paragraph(collaboratore.QualificaCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Indirizzo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pValore = new Paragraph(collaboratore.IndirizzoCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Città").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pValore = new Paragraph(collaboratore.CittaCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Telefono").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pValore = new Paragraph(collaboratore.TelefonoCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Cod.Fiscale/P.Iva").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pValore = new Paragraph(collaboratore.CodFiscaleCollaboratore).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); // AGGIUNGO INTESTAZIONE COLLABORATORE tbIntestazione.AddCell(tbIntestazioneDx).SetBorder(iText.Layout.Borders.Border.NO_BORDER); document.Add(tbIntestazione); Paragraph pSpazio = new Paragraph(" "); document.Add(pSpazio); Paragraph pLuogoData = new Paragraph(cittaVs + ", " + DateTime.Today.ToLongDateString()); document.Add(pLuogoData); document.Add(pSpazio); // CREAZIONE GRIGLIA iText.Layout.Element.Table tbGrigla = new iText.Layout.Element.Table(new float[] { 67, 138, 120, 100, 100, 55, 50, 50, 50, 50 }).SetWidth(780).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetFixedLayout(); Paragraph pGriglia; Cell cellaGriglia; // INTESTAZIONE GRIGLIA pGriglia = new Paragraph("Data").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Lavorazione").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Produzione").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Cliente").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Descrizione").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Assunz.").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Mista").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Rimb. KM").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Rit. Acconto").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Fattura").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); //pGriglia = new Paragraph("Diaria").SetFontSize(10); //cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); //cellaGriglia.Add(pGriglia); //tbGrigla.AddHeaderCell(cellaGriglia); // TOTALI PARZIALI decimal fattura = 0; decimal ritenutaAcconto = 0; decimal assunzione = 0; decimal mista = 0; decimal rimborsoKm = 0; //int diaria = 0; foreach (DatiFiscaliLavorazione datiFiscali in collaboratore.ListaDatiFiscali) { pGriglia = new Paragraph(datiFiscali.DataLavorazione.ToShortDateString()).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(datiFiscali.Lavorazione).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(datiFiscali.Produzione).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(datiFiscali.Cliente).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(datiFiscali.Descrizione).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); assunzione += datiFiscali.Assunzione; pGriglia = new Paragraph(datiFiscali.Assunzione.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); mista += datiFiscali.Mista; pGriglia = new Paragraph(datiFiscali.Mista.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); rimborsoKm += datiFiscali.RimborsoKm; pGriglia = new Paragraph(datiFiscali.RimborsoKm.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); ritenutaAcconto += datiFiscali.RitenutaAcconto; pGriglia = new Paragraph(datiFiscali.RitenutaAcconto.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); fattura += datiFiscali.Fattura; pGriglia = new Paragraph(datiFiscali.Fattura.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); //diaria += datiFiscali.Diaria; //pGriglia = new Paragraph(datiFiscali.Diaria.ToString("###")).SetFontSize(9); //cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); //cellaGriglia.Add(pGriglia); //tbGrigla.AddCell(cellaGriglia); } pGriglia = new Paragraph("TOTALI").SetFontSize(9); cellaGriglia = new Cell(1, 5).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(assunzione.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(mista.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(rimborsoKm.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(ritenutaAcconto.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(fattura.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); //pGriglia = new Paragraph(diaria.ToString("##0")).SetFontSize(9); //cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); //cellaGriglia.Add(pGriglia); //tbGrigla.AddCell(cellaGriglia); // AGGIUNGO TABELLA document.Add(tbGrigla); if (totCollaboratoriUtilizzati < listaDatiReport.Count) { // AGGIUNGO SALTO PAGINA document.Add(new AreaBreak()); } } int n = doc.GetNumberOfPages(); iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize(); // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA for (int i = 1; i <= n; i++) { //AGGIUNGO NUM.PAGINA document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); //AGGIUNGO FOOTER document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER), pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); } // CHIUDO IL PDF document.Flush(); document.Close(); wr.Close(); btnRicerca_Click(null, null); // CREO STRINGA PER IL JAVASCRIPT DI VISUALIZZAZIONE if (System.IO.File.Exists(mapPathReport)) { Page page = HttpContext.Current.Handler as Page; ScriptManager.RegisterStartupScript(page, page.GetType(), "apriPdf", script: "window.open('" + pathReport.Replace("~", "") + "')", addScriptTags: true); } else { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "Il File " + pathReport.Replace("~", "") + " non è stato creato correttamente!"; BasePage p = new BasePage(); p.ShowError(esito.Descrizione); } } } catch (Exception ex) { BasePage p = new BasePage(); p.ShowError(ex.Message + " " + ex.StackTrace); } }
public Esito popolaPannelloFattura(DatiAgenda eventoSelezionato) { Esito esito = new Esito(); try { if (eventoSelezionato != null && eventoSelezionato.LavorazioneCorrente != null) { // LEGGO I PARAMETRI DI VS Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA"); string pIvaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE"); string denominazioneVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO"); string toponimoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO"); string indirizzoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO"); string civicoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP"); string capVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA"); string cittaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA"); string provinciaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL"); string emailVs = cfAppo.valore; //List<DatiArticoliLavorazione> listaArticoliLavorazione = eventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.Where(x => x.Stampa).OrderBy(x => x.Fattura).ToList<DatiArticoliLavorazione>(); List <DatiArticoliLavorazione> listaArticoliLavorazione = eventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.Where(x => x.Stampa).ToList <DatiArticoliLavorazione>(); if (listaArticoliLavorazione != null) { Protocolli protocolloFattura = new Protocolli(); int idTipoProtocollo = UtilityTipologiche.getElementByNome(UtilityTipologiche.caricaTipologica(EnumTipologiche.TIPO_PROTOCOLLO), "Fattura", ref esito).id; List <Protocolli> listaProtocolli = Protocolli_BLL.Instance.getProtocolliByCodLavIdTipoProtocollo(eventoSelezionato.codice_lavoro, idTipoProtocollo, ref esito, true); string numeroProtocollo = ""; string numeroFattura = ""; if (listaProtocolli.Count == 0) { numeroProtocollo = Protocolli_BLL.Instance.getNumeroProtocollo(); // ESTRAPOLO IL NUMERO FATTURA DALLA TABELLA TAB_NUMERO_FATTURA numeroFattura = Protocolli_BLL.Instance.getNumeroFattura(); } else { bool trovato = false; foreach (Protocolli protocollo in listaProtocolli) { if (protocollo.Destinatario == "Cliente") { //protocolloFattura = listaProtocolli.First(); numeroProtocollo = protocollo.Numero_protocollo; numeroFattura = protocollo.Protocollo_riferimento; protocolloFattura = protocollo; trovato = true; break; } } if (!trovato) { numeroProtocollo = Protocolli_BLL.Instance.getNumeroProtocollo(); // ESTRAPOLO IL NUMERO FATTURA DALLA TABELLA TAB_NUMERO_FATTURA numeroFattura = Protocolli_BLL.Instance.getNumeroFattura(); listaProtocolli.Clear(); } } // GESTIONE NOMI FILE PDF //string nomeFile = "Fattura_" + eventoSelezionato.codice_lavoro + ".pdf"; string nomeFile = "Fattura_" + numeroFattura + ".pdf"; string pathFattura = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile; string mapPathFattura = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile; //string prefissoUrl = Request.Url.Scheme + "://" + Request.Url.Authority; iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png")); iText.IO.Image.ImageData imageDNV = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/DNV_2008_ITA2.jpg")); PdfWriter wr = new PdfWriter(mapPathFattura); PdfDocument doc = new PdfDocument(wr); doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4); //Document document = new Document(doc); Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4, false); document.SetMargins(245, 30, 110, 30); // ESTRAPOLO IL CLIENTE Anag_Clienti_Fornitori cliente = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(eventoSelezionato.id_cliente, ref esito); Paragraph pSpazio = new Paragraph(" "); document.Add(pSpazio); // CREAZIONE GRIGLIA iText.Layout.Element.Table tbGrigla = new iText.Layout.Element.Table(new float[] { 80, 70, 180, 70, 30, 30, 70 }).SetWidth(530).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetFixedLayout(); Paragraph pGriglia; Cell cellaGriglia; // COLORE BLU VIDEOSYSTEM iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243); // INTESTAZIONE FATTURA pGriglia = new Paragraph("Fattura").SetFontSize(10).SetBold(); cellaGriglia = new Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph(numeroFattura + " Rif.Lav. " + eventoSelezionato.codice_lavoro).SetFontSize(10).SetBold(); cellaGriglia = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); //pGriglia = new Paragraph("").SetFontSize(10); //cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); //cellaGriglia.Add(pGriglia); //tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Rif.Prot. " + numeroProtocollo).SetFontSize(10).SetBold(); cellaGriglia = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); // INTESTAZIONE GRIGLIA pGriglia = new Paragraph("Codice").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Descrizione Offerta").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Prezzo").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Qta").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Iva").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); pGriglia = new Paragraph("Totale").SetFontSize(10); cellaGriglia = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 1, 100)).SetPadding(5).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddHeaderCell(cellaGriglia); decimal totPrezzo = 0; decimal totIVA = 0; // CICLO GLI ARTICOLI //foreach (DatiArticoli da in listaDatiArticoli) foreach (DatiArticoliLavorazione da in listaArticoliLavorazione) { // CALCOLO I TOTALI //totPrezzo += da.Prezzo * da.Quantita; totPrezzo += da.Prezzo * 1; //totIVA += (da.Prezzo * da.Iva / 100) * da.Quantita; totIVA += (da.Prezzo * da.Iva / 100) * 1; string descrizione = da.Descrizione; string descrizioneLunga = da.DescrizioneLunga; pGriglia = new Paragraph(descrizione).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); if (da.Consuntivo == true) { //descrizione = "(c)" + descrizione; //descrizioneLunga = "(Consuntivo)" + Environment.NewLine + descrizioneLunga; Text firstDesc = new Text("(Consuntivo)" + Environment.NewLine).SetFontSize(9).SetBold(); Text secondDesc = new Text(descrizioneLunga).SetFontSize(9); pGriglia = new Paragraph().Add(firstDesc).Add(secondDesc); } else { pGriglia = new Paragraph(descrizioneLunga).SetFontSize(9); } cellaGriglia = new Cell(1, 2).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(da.Prezzo.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); //pGriglia = new Paragraph(da.Quantita.ToString("##0")).SetFontSize(9); pGriglia = new Paragraph(1.ToString("##0")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(da.Iva.ToString("##")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); //decimal totale = da.Prezzo * da.Quantita; decimal totale = da.Prezzo * 1; pGriglia = new Paragraph(totale.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); } // AGGIUNGO UNO SPAZIO pGriglia = new Paragraph(" ").SetFontSize(9); cellaGriglia = new Cell(1, 7).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); // ESTRAPOLO NOTEOFFERTA NoteOfferta noteOfferta = Offerta_BLL.Instance.getNoteOffertaByIdDatiAgenda(eventoSelezionato.id, ref esito); // NOTE Text first = new Text("Note:").SetFontSize(9).SetBold(); //Text second = new Text(Environment.NewLine + "Gli articoli con la dicitura 'Cons' sono da ritenersi a CONSUNTIVO" + Environment.NewLine + noteOfferta.Note.Trim()).SetFontSize(9); Text second = new Text(Environment.NewLine + noteOfferta.Note.Trim()).SetFontSize(9); Paragraph paragraphNote = new Paragraph().Add(first).Add(second); cellaGriglia = new iText.Layout.Element.Cell(3, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10); cellaGriglia.Add(paragraphNote); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph("Imponibile").SetFontSize(9); cellaGriglia = new iText.Layout.Element.Cell(1, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(totPrezzo.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); // TOTALE IVA pGriglia = new Paragraph("i.v.a.").SetFontSize(9); cellaGriglia = new iText.Layout.Element.Cell(1, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph(totIVA.ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); // TOTALE EURO pGriglia = new Paragraph("Totale Euro").SetFontSize(9); cellaGriglia = new iText.Layout.Element.Cell(1, 3).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); pGriglia = new Paragraph((totPrezzo + totIVA).ToString("###,##0.00")).SetFontSize(9); cellaGriglia = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT).SetBold(); cellaGriglia.Add(pGriglia); tbGrigla.AddCell(cellaGriglia); document.Add(tbGrigla); //iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(1).GetPageSize(); int n = doc.GetNumberOfPages(); iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize(); // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA for (int i = 1; i <= n; i++) { // AGGIUNGO LOGO iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(90, 80).SetFixedPosition(i, 30, 740); document.Add(image); // CREAZIONE GRIGLIA INFORMAZIONI iText.Layout.Element.Table tbGriglaInfo = new iText.Layout.Element.Table(new float[] { 70, 230 }).SetWidth(300).SetFixedPosition(i, 30, 640, 300); Paragraph pGrigliaInfo = new Paragraph(cittaVs).SetFontSize(9).SetBold(); iText.Layout.Element.Cell cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); //pGrigliaInfo = new Paragraph(DateTime.Today.ToLongDateString()).SetFontSize(9); if (string.IsNullOrEmpty(tbDataProtocollo.Text)) { tbDataProtocollo.Text = eventoSelezionato.data_inizio_lavorazione.ToShortDateString(); } pGrigliaInfo = new Paragraph(Convert.ToDateTime(tbDataProtocollo.Text).ToLongDateString()).SetFontSize(9); cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); pGrigliaInfo = new Paragraph("Produzione:").SetFontSize(9).SetBold(); cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); pGrigliaInfo = new Paragraph(eventoSelezionato.produzione).SetFontSize(9); cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); pGrigliaInfo = new Paragraph("Lavorazione:").SetFontSize(9).SetBold(); cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); pGrigliaInfo = new Paragraph(eventoSelezionato.lavorazione).SetFontSize(9); cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); pGrigliaInfo = new Paragraph("Data Lav.ne:").SetFontSize(9).SetBold(); cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); pGrigliaInfo = new Paragraph(eventoSelezionato.data_inizio_lavorazione.ToString("dd/MM/yyyy")).SetFontSize(9); cellaGrigliaInfo = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaInfo.Add(pGrigliaInfo); tbGriglaInfo.AddCell(cellaGrigliaInfo); document.Add(tbGriglaInfo); // CREAZIONE GRIGLIA DESTINATARIO iText.Layout.Element.Table tbGriglaDest = new iText.Layout.Element.Table(new float[] { 70, 230 }).SetWidth(300).SetFixedPosition(i, 350, 650, 300); Paragraph pGrigliaDest = new Paragraph("Spettabile").SetFontSize(9).SetBold(); iText.Layout.Element.Cell cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaDest.Add(pGrigliaDest); tbGriglaDest.AddCell(cellaGrigliaDest); pGrigliaDest = new Paragraph(cliente.RagioneSociale).SetFontSize(9); cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaDest.Add(pGrigliaDest); tbGriglaDest.AddCell(cellaGrigliaDest); // INDIRIZZO DESTINATARIO pGrigliaDest = new Paragraph("Indirizzo").SetFontSize(9).SetBold(); cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaDest.Add(pGrigliaDest); tbGriglaDest.AddCell(cellaGrigliaDest); //pGrigliaDest = new Paragraph(cliente.TipoIndirizzoOperativo + " " + cliente.IndirizzoOperativo + " " + cliente.NumeroCivicoOperativo + Environment.NewLine + cliente.CapOperativo + " " + cliente.ComuneOperativo + " " + cliente.ProvinciaOperativo).SetFontSize(9); //cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); //cellaGrigliaDest.Add(pGrigliaDest); //tbGriglaDest.AddCell(cellaGrigliaDest); pGrigliaDest = new Paragraph(cliente.TipoIndirizzoLegale + " " + cliente.IndirizzoLegale + " " + cliente.NumeroCivicoLegale + Environment.NewLine + cliente.CapLegale + " " + cliente.ComuneLegale + " " + cliente.ProvinciaLegale).SetFontSize(9); cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaDest.Add(pGrigliaDest); tbGriglaDest.AddCell(cellaGrigliaDest); // PARTITA IVA DESTINATARIO pGrigliaDest = new Paragraph("P.Iva/C.F.").SetFontSize(9).SetBold(); cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaDest.Add(pGrigliaDest); tbGriglaDest.AddCell(cellaGrigliaDest); string pIvaCF = cliente.PartitaIva; if (string.IsNullOrEmpty(pIvaCF)) { pIvaCF = cliente.CodiceFiscale; } pGrigliaDest = new Paragraph(pIvaCF).SetFontSize(9); cellaGrigliaDest = new iText.Layout.Element.Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaDest.Add(pGrigliaDest); tbGriglaDest.AddCell(cellaGrigliaDest); document.Add(tbGriglaDest); //document.Add(pSpazio); //document.Add(pSpazio); // CREAZIONE INTESTAZIONE GRIGLIA //iText.Layout.Element.Table tbGriglaInt = new iText.Layout.Element.Table(new float[] { 80, 50, 200, 80, 20, 20, 80 }).SetWidth(530).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE, 10).SetFixedPosition(i, 30, 595, 530); ; //document.Add(tbGriglaInt); // AGGIUNGO LOGO DNV iText.Layout.Element.Image logoDnv = new iText.Layout.Element.Image(imageDNV).ScaleAbsolute(40, 40).SetFixedPosition(i, 518, 8); document.Add(logoDnv); //AGGIUNGO NUM.PAGINA document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); //AGGIUNGO FOOTER document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER), pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); if (i == n) { // NELL'ULTIMA PAGINA AGGIUNGO LA GRIGLIA CON LE NOTE E IL TIMBRO // CREAZIONE GRIGLIA iText.Layout.Element.Table tbGriglaNoteFooter = new iText.Layout.Element.Table(new float[] { 80, 70, 180, 70, 30, 30, 70 }).SetWidth(530).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.LIGHT_GRAY, 10).SetFixedPosition(30, 50, 530).SetFixedLayout(); // PRIMA RIGA GRIGLIA NOTE FOOTER Paragraph pGrigliaNoteFooter = new Paragraph("Banca").SetFontSize(9); iText.Layout.Element.Cell cellaGrigliaNoteFooter = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); pGrigliaNoteFooter = new Paragraph(noteOfferta.Banca).SetFontSize(9); //cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1,2).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.LIGHT_GRAY, 10).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(2); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 2, 50)).SetBorderTop(iText.Layout.Borders.Border.NO_BORDER).SetBorderLeft(iText.Layout.Borders.Border.NO_BORDER).SetBorderBottom(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); pGrigliaNoteFooter = new Paragraph("Timbro e firma per accettazione").SetFontSize(9); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); // SECONDA RIGA GRIGLIA NOTE FOOTER pGrigliaNoteFooter = new Paragraph("Pagamento").SetFontSize(9); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); pGrigliaNoteFooter = new Paragraph(noteOfferta.NotaPagamento).SetFontSize(9); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 2, 50)).SetBorderTop(iText.Layout.Borders.Border.NO_BORDER).SetBorderLeft(iText.Layout.Borders.Border.NO_BORDER).SetBorderBottom(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); pGrigliaNoteFooter = new Paragraph(" ").SetFontSize(9); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); // TERZA RIGA GRIGLIA NOTE FOOTER pGrigliaNoteFooter = new Paragraph("Consegna").SetFontSize(9); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell().SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); pGrigliaNoteFooter = new Paragraph(noteOfferta.Consegna.Replace("\r\n", " ")).SetFontSize(9); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 2).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.WHITE, 2, 50)).SetBorderTop(iText.Layout.Borders.Border.NO_BORDER).SetBorderLeft(iText.Layout.Borders.Border.NO_BORDER).SetBorderBottom(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); pGrigliaNoteFooter = new Paragraph(" ").SetFontSize(9); cellaGrigliaNoteFooter = new iText.Layout.Element.Cell(1, 4).SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER).SetPadding(5); cellaGrigliaNoteFooter.Add(pGrigliaNoteFooter); tbGriglaNoteFooter.AddCell(cellaGrigliaNoteFooter); document.Add(tbGriglaNoteFooter); } } document.Close(); wr.Close(); if (File.Exists(mapPathFattura)) { // SE FILE OK INSERISCO O AGGIORNO PROTOCOLLO DI FATTURA if (listaProtocolli.Count == 0) { //INSERISCO protocolloFattura.Attivo = true; protocolloFattura.Cliente = cliente.RagioneSociale.Trim(); protocolloFattura.Codice_lavoro = eventoSelezionato.codice_lavoro; protocolloFattura.Data_inizio_lavorazione = eventoSelezionato.data_inizio_impegno; //protocolloFattura.Data_protocollo = DateTime.Today; protocolloFattura.Data_protocollo = Convert.ToDateTime(tbDataProtocollo.Text); protocolloFattura.Descrizione = "Fattura"; protocolloFattura.Id_cliente = eventoSelezionato.id_cliente; protocolloFattura.Id_tipo_protocollo = idTipoProtocollo; protocolloFattura.Lavorazione = eventoSelezionato.lavorazione; protocolloFattura.PathDocumento = Path.GetFileName(mapPathFattura); protocolloFattura.Produzione = eventoSelezionato.produzione; protocolloFattura.Protocollo_riferimento = numeroFattura; protocolloFattura.Numero_protocollo = numeroProtocollo; protocolloFattura.Pregresso = false; protocolloFattura.Destinatario = "Cliente"; int idProtPianoEsterno = Protocolli_BLL.Instance.CreaProtocollo(protocolloFattura, ref esito); ViewState["idProtocollo"] = idProtPianoEsterno; } else { // AGGIORNO protocolloFattura.PathDocumento = Path.GetFileName(mapPathFattura); protocolloFattura.Data_protocollo = Convert.ToDateTime(tbDataProtocollo.Text); esito = Protocolli_BLL.Instance.AggiornaProtocollo(protocolloFattura); ViewState["idProtocollo"] = protocolloFattura.Id; } ViewState["importo"] = totPrezzo; ViewState["iva"] = listaArticoliLavorazione[0].Iva;// totIVA; ViewState["importoIva"] = totPrezzo + totIVA; ViewState["banca"] = noteOfferta.Banca; ViewState["numeroDocumento"] = eventoSelezionato.codice_lavoro; framePdfFattura.Attributes.Remove("src"); framePdfFattura.Attributes.Add("src", pathFattura.Replace("~", "")); DivFramePdfFattura.Visible = true; framePdfFattura.Visible = true; ScriptManager.RegisterStartupScript(Page, typeof(Page), "aggiornaFrame", script: "javascript: document.getElementById('" + framePdfFattura.ClientID + "').contentDocument.location.reload(true);", addScriptTags: true); btnStampaFattura.Attributes.Add("onclick", "window.open('" + pathFattura.Replace("~", "") + "');"); //} } else { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "Il File " + pathFattura.Replace("~", "") + " non è stato creato correttamente!"; } } } } catch (Exception ex) { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "popolaPannelloFattura(DatiAgenda eventoSelezionato) " + ex.Message + Environment.NewLine + ex.StackTrace; } return(esito); }
public Task WriteAnnotatedPdfAsync(string pdfDocumentPath, IEnumerable <IAnnotation> annotations, string filePath) { using (var reader = new PdfReader(pdfDocumentPath)) using (var outFile = File.Open(filePath, FileMode.Create)) using (var writer = new PdfWriter(outFile)) using (var doc = new PdfDocument(reader, writer)) { var acroForm = PdfAcroForm.GetAcroForm(doc, true); foreach (var ann in annotations) { var targets = ann.SelectedTargets; if (targets == null || targets.Count < 1) { targets = ann.Subject.Appearances ?? throw new ArgumentException($"The subject word {ann.Subject.Text} for a given annotation has no appearances."); } foreach (var trg in targets) { var page = doc.GetPage(trg.Parent.Index + 1); var font = PdfFontFactory.CreateRegisteredFont(iText.IO.Font.Constants.StandardFonts.HELVETICA); var coord = trg.GetPdfCoords(); var buttonRect = new Rectangle(coord.Llx, coord.Lly, coord.width, coord.height); var txRect = GetAnnotationRect(buttonRect, font, ann, trg); var textFieldName = Guid.NewGuid().ToString("n"); var textField = PdfFormField.CreateText(doc, txRect, textFieldName); textField.SetValue(ann.Content, font, FontSize); textField.SetColor(ColorConstants.DARK_GRAY); textField.SetBackgroundColor(ColorConstants.LIGHT_GRAY); textField.SetReadOnly(true); textField.SetMultiline(true); textField.SetVisibility(PdfFormField.HIDDEN); textField.SetBorderColor(ColorConstants.LIGHT_GRAY); textField.SetFieldFlags(4097); acroForm.AddField(textField, page); var enter = PdfAction.CreateHide(textFieldName, false); var exit = PdfAction.CreateHide(textFieldName, true); var btn = PdfFormField.CreatePushButton(doc, buttonRect, Guid.NewGuid().ToString("n"), string.Empty); btn.SetBackgroundColor(null); btn.SetBorderWidth(0); btn.SetAdditionalAction(PdfName.E, enter); btn.SetAdditionalAction(PdfName.X, exit); acroForm.AddField(btn, page); var underline = PdfTextMarkupAnnotation.CreateUnderline(new Rectangle(buttonRect.GetX(), buttonRect.GetY() - 2, buttonRect.GetWidth(), 3), new float[] { buttonRect.GetX() + buttonRect.GetWidth(), buttonRect.GetY() + buttonRect.GetHeight(), buttonRect.GetX(), buttonRect.GetY() + buttonRect.GetHeight(), buttonRect.GetX() + buttonRect.GetWidth(), buttonRect.GetY() - 2, buttonRect.GetX(), buttonRect.GetY() - 2, }); underline.SetColor(ColorConstants.YELLOW); page.AddAnnotation(underline); } } } return(Task.CompletedTask); }
public static bool Export() { Pages[] pages = Annotator.pages.ToArray(); pdfDoc = new PdfDocument(new PdfReader(Data.sourcePDFpath), new PdfWriter(Data.savePDFpath)); Document document = new Document(pdfDoc); // Load image from disk string imgC = "Stamps\\correct.png"; string imgW = "Stamps\\wrong.png"; ImageData correctSign = ImageDataFactory.Create(imgC); ImageData wrongSign = ImageDataFactory.Create(imgW); //Create layout image object and provide parameters. Page number = 1 for (int i = 1; i <= Data.pageCount; i++) { iText.Kernel.Geom.Rectangle mediabox = pdfDoc.GetPage(i).GetPageSize(); int actualWidth = (int)mediabox.GetWidth(); int actualHeight = (int)mediabox.GetHeight(); int img_w; int img_h; int px, py; if (pages[i - 1].tick != null) { img_w = (iWidth * actualWidth) / Data.OriginalImages[i - 1].Width; img_h = (iHeight * actualHeight) / Data.OriginalImages[i - 1].Height; foreach (var item in pages[i - 1].tick) { px = Convert.ToInt32(item.x * actualWidth); py = actualHeight - Convert.ToInt32(item.y * actualHeight) - img_h / 2; iText.Layout.Element.Image image; int numLines = item.text.Split('\n').Length * 14; Text scoreText = new Text($"({item.text})").SetFontColor(ColorConstants.RED).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA)).SetFontSize(fontSize); Text commentText = new Text($"{item.text}").SetFontColor(ColorConstants.RED).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA)).SetFontSize(fontSize); if (item.type == 'C') { image = new iText.Layout.Element.Image(correctSign).ScaleAbsolute(img_w, img_h).SetFixedPosition(i, px, py); } else if (item.type == 'I') { image = new iText.Layout.Element.Image(wrongSign).ScaleAbsolute(img_w, img_h).SetFixedPosition(i, px, py); } else { image = null; } // This adds the image to the page if (image != null) { document.Add(image); if (item.text != "") { Paragraph p1 = new Paragraph(scoreText).SetFixedPosition(i, px + img_w, py, 50).SetFontSize(fontSize); document.Add(p1); } } else { Paragraph p1 = new Paragraph(commentText).SetFixedPosition(i, px, py - numLines, 200).SetFontSize(fontSize); p1.SetFixedLeading(Convert.ToInt32(fontSize * 1.2)); document.Add(p1); } } } if (i == 1) { px = Convert.ToInt32(fScoreOrigin_x * actualWidth) + 10; py = actualHeight - Convert.ToInt32((fScoreOrigin_y * actualHeight) + (fontSize * 2.5)); Text finalText = new Text($"{Data.finalScore}\n-----\n{Data.maxScore}").SetFontColor(ColorConstants.RED).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA)); Paragraph p2 = new Paragraph(finalText).SetFixedPosition(1, px, py, 50).SetFontSize(fontSize); p2.SetFixedLeading(Convert.ToInt32((fontSize * 10) / 12)); document.Add(p2); } } document.Close(); MessageBox.Show("File saved successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); return(true); }
public static void Export(string file, Pages[] pages) { pdfDoc = new PdfDocument(new PdfReader(DATA.sourcePDFpath), new PdfWriter(file)); // Document to add layout elements: paragraphs, images etc Document document = new Document(pdfDoc); // Load image from disk string imgC = "Stamps\\correct.png"; string imgW = "Stamps\\wrong.png"; //var image = Properties.Resources.right; ImageData correctSign = ImageDataFactory.Create(imgC); ImageData wrongSign = ImageDataFactory.Create(imgW); //Create layout image object and provide parameters. Page number = 1 for (int i = 1; i <= DATA.pageCount; i++) { iText.Kernel.Geom.Rectangle mediabox = pdfDoc.GetPage(i).GetPageSize(); int actualWidth = (int)mediabox.GetWidth(); int actualHeight = (int)mediabox.GetHeight(); int img_w; int img_h; int px, py; if (pages[i - 1].tick != null) { img_w = (iWidth * actualWidth) / DATA.OriginalImages[i - 1].Width; img_h = (iHeight * actualHeight) / DATA.OriginalImages[i - 1].Height; foreach (var item in pages[i - 1].tick) { px = Convert.ToInt32((item.x * actualWidth) / 1000); py = actualHeight - Convert.ToInt32((item.y * actualHeight) / 1000) - img_h / 2; iText.Layout.Element.Image image; int numLines = item.text.Split('\n').Length * 14; Text scoreText = new Text($"({item.text})").SetFontColor(ColorConstants.RED).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA)).SetFontSize(fontSize); Text commentText = new Text($"{item.text}").SetFontColor(ColorConstants.RED).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA)).SetFontSize(fontSize); if (item.Type == 'C') { image = new iText.Layout.Element.Image(correctSign).ScaleAbsolute(img_w, img_h).SetFixedPosition(i, px, py); } else if (item.Type == 'I') { image = new iText.Layout.Element.Image(wrongSign).ScaleAbsolute(img_w, img_h).SetFixedPosition(i, px, py); } else { image = null; } // This adds the image to the page if (image != null) { document.Add(image); if (item.text != "") { Paragraph p1 = new Paragraph(scoreText).SetFixedPosition(i, px + img_w, py, 50).SetFontSize(fontSize); document.Add(p1); } } else { //px = Convert.ToInt32((item.x * actualWidth) / 1000) + 10; //py = actualHeight - Convert.ToInt32(((item.y * actualHeight) / 1000) + (fontSize * item.cmtLines)); Paragraph p1 = new Paragraph(commentText).SetFixedPosition(i, px, py - numLines, 200).SetFontSize(fontSize); p1.SetFixedLeading(Convert.ToInt32(fontSize * 1.2)); document.Add(p1); } } } if (i == 1) { px = Convert.ToInt32((fScoreOrigin.X * actualWidth) / 1000) + 10; py = actualHeight - Convert.ToInt32(((fScoreOrigin.Y * actualHeight) / 1000) + (fontSize * 2.5)); Text finalText = new Text($"{DATA.finalScore}\n-----\n{DATA.outOf}").SetFontColor(ColorConstants.RED).SetFont(PdfFontFactory.CreateFont(StandardFonts.HELVETICA)); Paragraph p2 = new Paragraph(finalText).SetFixedPosition(1, px, py, 50).SetFontSize(fontSize); p2.SetFixedLeading(Convert.ToInt32((fontSize * 10) / 12)); document.Add(p2); } } // Don't forget to close the document. // When you use Document, you should close it rather than PdfDocument instance document.Close(); MessageBox.Show("File saved successfully.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information); FrmMain.isSaved = true; //pdfViewer.src = target; //pdfDocument.Load(target); }
/// <summary>Appends a rectangle to the current path as a complete subpath.</summary> public virtual void Rectangle(iText.Kernel.Geom.Rectangle rect) { Rectangle(rect.GetX(), rect.GetY(), rect.GetWidth(), rect.GetHeight()); }
private void AddPageWithRotationAndScaling(PdfCanvas pdfCanvas, Rectangle documentPageSize, PdfXObject watermarkXObject, Rectangle watermarkPageSize, int rotation, bool fitToPage) { float scaleWidth; float scaleHeight; float scale; float backgroundHeight; float backgroundWidth; switch (rotation) { case 90: scaleWidth = documentPageSize.GetWidth() / watermarkPageSize.GetHeight(); scaleHeight = documentPageSize.GetHeight() / watermarkPageSize.GetWidth(); scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight; scale = fitToPage ? scale : 1; backgroundHeight = scale * watermarkPageSize.GetHeight(); backgroundWidth = scale * watermarkPageSize.GetWidth(); pdfCanvas.AddXObject(watermarkXObject, 0, -scale, scale, 0, (documentPageSize.GetWidth() - backgroundHeight) / 2, backgroundWidth + (documentPageSize.GetHeight() - backgroundWidth) / 2); break; case 180: scaleWidth = documentPageSize.GetWidth() / watermarkPageSize.GetWidth(); scaleHeight = documentPageSize.GetHeight() / watermarkPageSize.GetHeight(); scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight; scale = fitToPage ? scale : 1; backgroundHeight = scale * watermarkPageSize.GetHeight(); backgroundWidth = scale * watermarkPageSize.GetWidth(); pdfCanvas.AddXObject(watermarkXObject, -scale, 0, 0, -scale, backgroundWidth + (documentPageSize.GetWidth() - backgroundWidth) / 2, backgroundHeight + (documentPageSize.GetHeight() - backgroundHeight) / 2); break; case 270: scaleWidth = documentPageSize.GetWidth() / watermarkPageSize.GetHeight(); scaleHeight = documentPageSize.GetHeight() / watermarkPageSize.GetWidth(); scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight; scale = fitToPage ? scale : 1; backgroundHeight = scale * watermarkPageSize.GetHeight(); backgroundWidth = scale * watermarkPageSize.GetWidth(); pdfCanvas.AddXObject(watermarkXObject, 0, scale, -scale, 0, backgroundHeight + (documentPageSize.GetWidth() - backgroundHeight) / 2, (documentPageSize.GetHeight() - backgroundWidth) / 2); break; case 0: default: scaleWidth = documentPageSize.GetWidth() / watermarkPageSize.GetWidth(); scaleHeight = documentPageSize.GetHeight() / watermarkPageSize.GetHeight(); scale = scaleWidth < scaleHeight ? scaleWidth : scaleHeight; scale = fitToPage ? scale : 1; backgroundHeight = scale * watermarkPageSize.GetHeight(); backgroundWidth = scale * watermarkPageSize.GetWidth(); pdfCanvas.AddXObject(watermarkXObject, scale, 0, 0, scale, (documentPageSize.GetWidth() - backgroundWidth) / 2, (documentPageSize.GetHeight() - backgroundHeight) / 2); break; } }
public Esito popolaPannelloPianoEsterno(DatiAgenda eventoSelezionato) { Esito esito = new Esito(); try { if (eventoSelezionato != null && eventoSelezionato.LavorazioneCorrente != null) { // LEGGO I PARAMETRI DI VS Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA"); string pIvaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE"); string denominazioneVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO"); string toponimoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO"); string indirizzoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO"); string civicoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP"); string capVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA"); string cittaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA"); string provinciaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL"); string emailVs = cfAppo.valore; List <DatiPianoEsternoLavorazione> listaDatiPianoEsternoLavorazione = eventoSelezionato.LavorazioneCorrente.ListaDatiPianoEsternoLavorazione; if (listaDatiPianoEsternoLavorazione != null) { Protocolli protocolloPianoEsterno = new Protocolli(); int idTipoProtocollo = UtilityTipologiche.getElementByNome(UtilityTipologiche.caricaTipologica(EnumTipologiche.TIPO_PROTOCOLLO), "Piano Esterno", ref esito).id; List <Protocolli> listaProtocolli = Protocolli_BLL.Instance.getProtocolliByCodLavIdTipoProtocollo(eventoSelezionato.codice_lavoro, idTipoProtocollo, ref esito, true); string numeroProtocollo = ""; if (listaProtocolli.Count == 0) { numeroProtocollo = Protocolli_BLL.Instance.getNumeroProtocollo(); } else { protocolloPianoEsterno = listaProtocolli.First(); numeroProtocollo = protocolloPianoEsterno.Numero_protocollo; } // GESTIONE NOMI FILE PDF //string nomeFile = "PianoEsterno_" + eventoSelezionato.LavorazioneCorrente.Id.ToString() + ".pdf"; //string nomeFile = "PianoEsterno_" + numeroProtocollo + ".pdf"; string nomeFile = "PianoEsterno_" + eventoSelezionato.codice_lavoro + ".pdf"; string pathPianoEsterno = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile; string mapPathPianoEsterno = MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile; //string prefissoUrl = Request.Url.Scheme + "://" + Request.Url.Authority; iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(MapPath("~/Images/logoVSP_trim.png")); PdfWriter wr = new PdfWriter(mapPathPianoEsterno); PdfDocument doc = new PdfDocument(wr); doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate()); //doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4); //Document document = new Document(doc); Document document = new Document(doc, iText.Kernel.Geom.PageSize.A4.Rotate(), false); //document.SetMargins(90, 30, 50, 30); document.SetMargins(50, 30, 50, 30); //iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(0, 225, 0); // COLORE BLU VIDEOSYSTEM iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243); // AGGIUNGO TABLE PER LAYOUT INTESTAZIONE iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(new float[] { 1, 9 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER); //iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(3).UseAllAvailableWidth(); iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(90, 80).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); Cell cellaImmagine = new Cell().SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.MIDDLE).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); cellaImmagine.Add(image); tbIntestazione.AddCell(cellaImmagine); iText.Layout.Element.Table tbIntestazioneDx = new iText.Layout.Element.Table(new float[] { 2, 3, 2, 3 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER); Anag_Clienti_Fornitori cliente = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(eventoSelezionato.id_cliente, ref esito); Paragraph pTitolo = new Paragraph("Cliente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); Paragraph pValore = new Paragraph(cliente.RagioneSociale.Trim()).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Referente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); string nomeReferente = ""; if (eventoSelezionato.LavorazioneCorrente.IdReferente != null) { Anag_Referente_Clienti_Fornitori referente = Anag_Referente_Clienti_Fornitori_BLL.Instance.getReferenteById(ref esito, Convert.ToInt32(eventoSelezionato.LavorazioneCorrente.IdReferente.Value)); nomeReferente = referente.Nome + " " + referente.Cognome; } pValore = new Paragraph(nomeReferente).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Produzione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pValore = new Paragraph(eventoSelezionato.produzione).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Capotecnico").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); string nomeCapotecnico = ""; if (eventoSelezionato.LavorazioneCorrente.IdCapoTecnico != null) { Anag_Collaboratori coll = Anag_Collaboratori_BLL.Instance.getCollaboratoreById(eventoSelezionato.LavorazioneCorrente.IdCapoTecnico.Value, ref esito); nomeCapotecnico = coll.Nome + " " + coll.Cognome; } pValore = new Paragraph(nomeCapotecnico).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Lavorazione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.lavorazione).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Data Inizio").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_impegno.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Luogo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.luogo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Data Lavoraz.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_lavorazione.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Indirizzo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.indirizzo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Cod.Lavor.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.codice_lavoro).SetBorder(iText.Layout.Borders.Border.NO_BORDER); iText.Layout.Element.Cell cellaNote = new iText.Layout.Element.Cell(2, 4).SetBorder(iText.Layout.Borders.Border.NO_BORDER); string notePianoEsterno = ""; if (eventoSelezionato.LavorazioneCorrente.NotePianoEsterno != null) { notePianoEsterno = eventoSelezionato.LavorazioneCorrente.NotePianoEsterno; } Paragraph pNotePiano = new Paragraph(notePianoEsterno.Trim()).SetFontSize(10).SetBorder(iText.Layout.Borders.Border.NO_BORDER); cellaNote.Add(pNotePiano).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(cellaNote).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazione.AddCell(tbIntestazioneDx).SetBorder(iText.Layout.Borders.Border.NO_BORDER); document.Add(tbIntestazione); Paragraph pSpazio = new Paragraph(" "); document.Add(pSpazio); Paragraph pLuogoData = new Paragraph(cittaVs + ", " + DateTime.Today.ToLongDateString()); document.Add(pLuogoData); document.Add(pSpazio); // INTESTAZIONE GRIGLIA iText.Layout.Element.Table table = new iText.Layout.Element.Table(10).UseAllAvailableWidth(); //.SetBorderTop(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.ORANGE, 5)).SetBorderBottom(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.YELLOW, 5)).SetBorderLeft(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.GREEN, 5)).SetBorderRight(new iText.Layout.Borders.SolidBorder(iText.Kernel.Colors.ColorConstants.RED, 5)); Paragraph intestazione = new Paragraph("Data").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Personale").SetFontSize(10).SetBold().SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Qualifica").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Intervento").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Telefono").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Città").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Albergo").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Diaria").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Orario").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); intestazione = new Paragraph("Note").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione); string dataConfronto = ""; foreach (DatiPianoEsternoLavorazione dpe in listaDatiPianoEsternoLavorazione) { string collaboratoreFornitore = ""; string telefono = ""; string qualifica = ""; string citta = ""; string descrizioneArticoloAssociato = ""; if (dpe.IdCollaboratori != null) { Anag_Collaboratori coll = Anag_Collaboratori_BLL.Instance.getCollaboratoreById(dpe.IdCollaboratori.Value, ref esito); collaboratoreFornitore = coll.Cognome.Trim() + " " + coll.Nome.Trim(); // prendo descrizione da datiArticoliLavorazione filtrando per data, idCollaboratore e idLavorazione DatiArticoliLavorazione articoloAssociato = SessionManager.EventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.FirstOrDefault(x => x.IdCollaboratori == coll.Id && x.Data == dpe.Data); if (articoloAssociato != null) { descrizioneArticoloAssociato = articoloAssociato.Descrizione; } FiguraProfessionale fp = coll.CreaFiguraProfessionale(descrizioneArticoloAssociato); //if (fp!=null && !string.IsNullOrEmpty(fp.ElencoQualifiche)) qualifica = fp.ElencoQualifiche; if (fp != null && !string.IsNullOrEmpty(fp.DescrizioneArticoloAssociato)) { qualifica = fp.DescrizioneArticoloAssociato; } if (fp != null && !string.IsNullOrEmpty(fp.Telefono)) { telefono = fp.Telefono; } if (telefono.StartsWith("0039")) { telefono = telefono.Substring(4); } if (telefono.StartsWith("+39")) { telefono = telefono.Substring(3); } if (fp != null && !string.IsNullOrEmpty(fp.Citta)) { citta = fp.Citta; } } else if (dpe.IdFornitori != null) { Anag_Clienti_Fornitori clienteFornitore = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(dpe.IdFornitori.Value, ref esito); collaboratoreFornitore = clienteFornitore.RagioneSociale.Trim(); // prendo descrizione da datiArticoliLavorazione filtrando per data, idFornitore e idLavorazione DatiArticoliLavorazione articoloAssociato = SessionManager.EventoSelezionato.LavorazioneCorrente.ListaArticoliLavorazione.FirstOrDefault(x => x.IdFornitori == clienteFornitore.Id && x.Data == dpe.Data); if (articoloAssociato != null) { descrizioneArticoloAssociato = articoloAssociato.Descrizione; } FiguraProfessionale fp = clienteFornitore.CreaFiguraProfessionale(descrizioneArticoloAssociato); //if (fp != null && !string.IsNullOrEmpty(fp.ElencoQualifiche)) qualifica = fp.ElencoQualifiche; if (fp != null && !string.IsNullOrEmpty(fp.DescrizioneArticoloAssociato)) { qualifica = fp.DescrizioneArticoloAssociato; } if (fp != null && !string.IsNullOrEmpty(fp.Telefono)) { telefono = fp.Telefono; } if (fp != null && !string.IsNullOrEmpty(fp.Citta)) { citta = fp.Citta; } } string importoDiaria = "0,00"; if (dpe.ImportoDiaria != null) { importoDiaria = dpe.ImportoDiaria.Value.ToString("###,###.00"); } string nota = ""; if (!string.IsNullOrEmpty(dpe.Nota)) { nota = dpe.Nota; } string dataPiano = ""; if (dpe.Data != null) { dataPiano = dpe.Data.Value.ToShortDateString(); } // METTO SEPARATORE QUANDO CAMBIA DATA if (string.IsNullOrEmpty(dataConfronto)) { dataConfronto = dataPiano; } if (!string.IsNullOrEmpty(dataConfronto) && !dataConfronto.Equals(dataPiano)) { dataConfronto = dataPiano; Cell cellavuota = new Cell(2, 10).SetHeight(10f); table.AddCell(cellavuota); } string orario = ""; if (dpe.Orario != null) { orario = dpe.Orario.Value.ToShortTimeString(); } string intervento = ""; if (dpe.IdIntervento != null) { intervento = SessionManager.ListaTipiIntervento.FirstOrDefault(x => x.id == dpe.IdIntervento).nome; } string albergo = "no"; if (dpe.Albergo != null && dpe.Albergo == true) { albergo = "si"; } //Paragraph p = new Paragraph(dpe.Data.Value.ToLongDateString() + " " + orario + " " + collaboratoreFornitore + " " + nota).SetFontSize(8); //document.Add(p); table.AddCell(dataPiano).SetFontSize(8).SetFontSize(10); table.AddCell(collaboratoreFornitore); table.AddCell(qualifica).SetFontSize(8); table.AddCell(intervento).SetFontSize(8); table.AddCell(telefono).SetFontSize(8); table.AddCell(citta).SetFontSize(8); table.AddCell(albergo).SetFontSize(8); Paragraph pImportoDiaria = new Paragraph(importoDiaria).SetFontSize(8).SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); table.AddCell(pImportoDiaria); table.AddCell(orario).SetFontSize(8); table.AddCell(nota).SetFontSize(8); } document.Add(table); //iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(1).GetPageSize(); int n = doc.GetNumberOfPages(); iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(n).GetPageSize(); // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA for (int i = 1; i <= n; i++) { // AGGIUNGO LOGO //iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(60, 60).SetFixedPosition(i, 20, pageSize.GetHeight() - 80); //document.Add(image); //AGGIUNGO NUM.PAGINA document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); //AGGIUNGO FOOTER document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER), pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); } document.Close(); wr.Close(); if (File.Exists(mapPathPianoEsterno)) { // SE FILE OK INSERISCO O AGGIORNO PROTOCOLLO DI TIPO PIANO ESTERNO if (listaProtocolli.Count == 0) { //INSERISCO protocolloPianoEsterno.Attivo = true; protocolloPianoEsterno.Cliente = cliente.RagioneSociale.Trim(); protocolloPianoEsterno.Codice_lavoro = eventoSelezionato.codice_lavoro; protocolloPianoEsterno.Data_inizio_lavorazione = eventoSelezionato.data_inizio_impegno; protocolloPianoEsterno.Data_protocollo = DateTime.Today; protocolloPianoEsterno.Descrizione = "Piano Esterno"; protocolloPianoEsterno.Id_cliente = eventoSelezionato.id_cliente; protocolloPianoEsterno.Id_tipo_protocollo = idTipoProtocollo; protocolloPianoEsterno.Lavorazione = eventoSelezionato.lavorazione; protocolloPianoEsterno.PathDocumento = Path.GetFileName(mapPathPianoEsterno); protocolloPianoEsterno.Produzione = eventoSelezionato.produzione; protocolloPianoEsterno.Protocollo_riferimento = ""; protocolloPianoEsterno.Numero_protocollo = numeroProtocollo; protocolloPianoEsterno.Pregresso = false; protocolloPianoEsterno.Destinatario = "Cliente"; int idProtPianoEsterno = Protocolli_BLL.Instance.CreaProtocollo(protocolloPianoEsterno, ref esito); } else { // AGGIORNO protocolloPianoEsterno.PathDocumento = Path.GetFileName(mapPathPianoEsterno); esito = Protocolli_BLL.Instance.AggiornaProtocollo(protocolloPianoEsterno); } //string nomeFileToDisplay = BaseStampa.Instance.AddPageNumber(mapPathPdfSenzaNumeroPagina, mapPianoEsterno, ref esito); //if (File.Exists(mapPathPdfSenzaNumeroPagina)) File.Delete(mapPathPdfSenzaNumeroPagina); //if (esito.codice == Esito.ESITO_OK) { framePdfPianoEsterno.Attributes.Remove("src"); framePdfPianoEsterno.Attributes.Add("src", pathPianoEsterno.Replace("~", "")); DivFramePdfPianoEsterno.Visible = true; framePdfPianoEsterno.Visible = true; ScriptManager.RegisterStartupScript(Page, typeof(Page), "aggiornaFrame", script: "javascript: document.getElementById('" + framePdfPianoEsterno.ClientID + "').contentDocument.location.reload(true);", addScriptTags: true); btnStampaPianoEsterno.Attributes.Add("onclick", "window.open('" + pathPianoEsterno.Replace("~", "") + "');"); //} } else { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "Il File " + pathPianoEsterno.Replace("~", "") + " non è stato creato correttamente!"; } } } } catch (Exception ex) { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "popolaPannelloPianoEsterno(DatiAgenda eventoSelezionato) " + ex.Message + Environment.NewLine + ex.StackTrace; } return(esito); }
public Esito PopolaPannelloNotaSpese(DatiAgenda eventoSelezionato, FiguraProfessionale figuraProfessionaleSelezionata) { Esito esito = new Esito(); try { if (eventoSelezionato != null && eventoSelezionato.LavorazioneCorrente != null) { #region LEGGO I PARAMETRI DI VS Config cfAppo = Config_BLL.Instance.getConfig(ref esito, "PARTITA_IVA"); string pIvaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "DENOMINAZIONE"); string denominazioneVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "TOPONIMO"); string toponimoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "INDIRIZZO"); string indirizzoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CIVICO"); string civicoVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CAP"); string capVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "CITTA"); string cittaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "PROVINCIA"); string provinciaVs = cfAppo.valore; cfAppo = Config_BLL.Instance.getConfig(ref esito, "EMAIL"); string emailVs = cfAppo.valore; #endregion List <DatiPianoEsternoLavorazione> listaDatiPianoEsternoLavorazione = eventoSelezionato.LavorazioneCorrente.ListaDatiPianoEsternoLavorazione; if (listaDatiPianoEsternoLavorazione != null) { string nomeFile = "NotaSpese.pdf"; string pathNotaSpese = ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"] + nomeFile; string mapPathNotaSpese = HttpContext.Current.Server.MapPath(ConfigurationManager.AppSettings["PATH_DOCUMENTI_PROTOCOLLO"]) + nomeFile; //string prefissoUrl = HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority; iText.IO.Image.ImageData imageData = iText.IO.Image.ImageDataFactory.Create(HttpContext.Current.Request.MapPath("~/Images/logoVSP_trim.png")); PdfWriter wr = new PdfWriter(mapPathNotaSpese); PdfDocument doc = new PdfDocument(wr); doc.SetDefaultPageSize(iText.Kernel.Geom.PageSize.A4.Rotate()); Document document = new Document(doc); document.SetMargins(50, 30, 50, 30); // COLORE BLU VIDEOSYSTEM iText.Kernel.Colors.Color coloreIntestazioni = new iText.Kernel.Colors.DeviceRgb(33, 150, 243); Paragraph pIntestazioneNotaSpese = new Paragraph("Nota Spese di: " + figuraProfessionaleSelezionata.Nome + " " + figuraProfessionaleSelezionata.Cognome); pIntestazioneNotaSpese.SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); pIntestazioneNotaSpese.SetFontSize(20); pIntestazioneNotaSpese.SetBold(); document.Add(pIntestazioneNotaSpese); // AGGIUNGO TABLE PER LAYOUT INTESTAZIONE iText.Layout.Element.Table tbIntestazione = new iText.Layout.Element.Table(new float[] { 1, 9 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER); iText.Layout.Element.Image image = new iText.Layout.Element.Image(imageData).ScaleAbsolute(90, 80).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); Cell cellaImmagine = new Cell().SetVerticalAlignment(iText.Layout.Properties.VerticalAlignment.MIDDLE).SetHorizontalAlignment(iText.Layout.Properties.HorizontalAlignment.CENTER); cellaImmagine.Add(image); tbIntestazione.AddCell(cellaImmagine); iText.Layout.Element.Table tbIntestazioneDx = new iText.Layout.Element.Table(new float[] { 2, 3, 2, 3 }).UseAllAvailableWidth().SetBorder(iText.Layout.Borders.Border.NO_BORDER); Anag_Clienti_Fornitori cliente = Anag_Clienti_Fornitori_BLL.Instance.getAziendaById(eventoSelezionato.id_cliente, ref esito); Paragraph pTitolo = new Paragraph("Cliente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); Paragraph pValore = new Paragraph(cliente.RagioneSociale.Trim()).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Referente").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); string nomeReferente = ""; if (eventoSelezionato.LavorazioneCorrente.IdReferente != null) { Anag_Referente_Clienti_Fornitori referente = Anag_Referente_Clienti_Fornitori_BLL.Instance.getReferenteById(ref esito, Convert.ToInt32(eventoSelezionato.LavorazioneCorrente.IdReferente.Value)); nomeReferente = referente.Nome + " " + referente.Cognome; } pValore = new Paragraph(nomeReferente).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Produzione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pValore = new Paragraph(eventoSelezionato.produzione).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Capotecnico").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); string nomeCapotecnico = ""; if (eventoSelezionato.LavorazioneCorrente.IdCapoTecnico != null) { Anag_Collaboratori coll = Anag_Collaboratori_BLL.Instance.getCollaboratoreById(eventoSelezionato.LavorazioneCorrente.IdCapoTecnico.Value, ref esito); nomeCapotecnico = coll.Nome + " " + coll.Cognome; } pValore = new Paragraph(nomeCapotecnico).SetBackgroundColor(iText.Kernel.Colors.ColorConstants.WHITE).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pValore).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Lavorazione").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.lavorazione).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Data Inizio").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_impegno.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Luogo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.luogo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Data Lavoraz.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.data_inizio_lavorazione.ToShortDateString()).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Indirizzo").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.indirizzo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); pTitolo = new Paragraph("Cod.Lavor.").SetBackgroundColor(coloreIntestazioni, 0.7f).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(pTitolo).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazioneDx.AddCell(eventoSelezionato.codice_lavoro).SetBorder(iText.Layout.Borders.Border.NO_BORDER); tbIntestazione.AddCell(tbIntestazioneDx).SetBorder(iText.Layout.Borders.Border.NO_BORDER); document.Add(tbIntestazione); Paragraph pSpazio = new Paragraph(" "); document.Add(pSpazio); Paragraph pLuogoData = new Paragraph(cittaVs + ", " + DateTime.Today.ToLongDateString()); pLuogoData.SetFontSize(8); document.Add(pLuogoData); document.Add(pSpazio); // INTESTAZIONE GRIGLIA iText.Layout.Element.Table table = new iText.Layout.Element.Table(new float[] { 90, 70, 70, 70, 70, 70, 70, 70, 200 }).SetWidth(780); Border bordoDoppio = new DoubleBorder(1); Cell cella = new Cell().SetBorder(iText.Layout.Borders.Border.NO_BORDER); table.AddHeaderCell(cella); Paragraph intestazioneMain = new Paragraph("Tipologia di pagamento").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); cella = new Cell(1, 3).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); cella.SetBorderLeft(bordoDoppio); cella.Add(intestazioneMain); table.AddHeaderCell(cella); intestazioneMain = new Paragraph("Costi in Euro").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); cella = new Cell(1, 5).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); cella.SetBorderLeft(bordoDoppio); cella.Add(intestazioneMain); table.AddHeaderCell(cella); Paragraph intestazione = new Paragraph("Data").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Sofid").SetFontSize(10).SetBold().SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); cella = new Cell().SetBorderLeft(bordoDoppio); cella.Add(intestazione); table.AddHeaderCell(cella).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Carta").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Contanti").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Carburante").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); cella = new Cell().SetBorderLeft(bordoDoppio); cella.Add(intestazione); table.AddHeaderCell(cella).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Albergo").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Trasporti").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Pasti").SetFontSize(10).SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); intestazione = new Paragraph("Varie").SetFontSize(10).SetBold().SetBackgroundColor(coloreIntestazioni, 0.7f); table.AddHeaderCell(intestazione).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER); // CELLE VUOTE for (int i = 0; i < 12; i++) { table.AddCell(new Cell().SetHeight(15)); cella = new Cell().SetBorderLeft(bordoDoppio); table.AddCell(cella); table.AddCell(" "); table.AddCell(" "); cella = new Cell().SetBorderLeft(bordoDoppio); table.AddCell(cella); table.AddCell(" "); table.AddCell(" "); table.AddCell(" "); table.AddCell(" "); } document.Add(table); Paragraph pFirma = new Paragraph("in fede"); pFirma.SetFontSize(9); pFirma.SetTextAlignment(iText.Layout.Properties.TextAlignment.RIGHT); pFirma.SetMarginRight(90); pFirma.SetMarginTop(13); document.Add(pFirma); iText.Kernel.Geom.Rectangle pageSize = doc.GetPage(1).GetPageSize(); int n = doc.GetNumberOfPages(); // AGGIUNGO CONTEGGIO PAGINE E FOOTER PER OGNI PAGINA for (int i = 1; i <= n; i++) { //AGGIUNGO NUM.PAGINA document.ShowTextAligned(new Paragraph("pagina " + i.ToString() + " di " + n.ToString()).SetFontSize(7), pageSize.GetWidth() - 60, pageSize.GetHeight() - 20, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); //AGGIUNGO FOOTER document.ShowTextAligned(new Paragraph(denominazioneVs + " P.IVA " + pIvaVs + Environment.NewLine + "Sede legale: " + toponimoVs + " " + indirizzoVs + " " + civicoVs + " - " + capVs + " " + cittaVs + " " + provinciaVs + " e-mail: " + emailVs).SetFontSize(7).SetTextAlignment(iText.Layout.Properties.TextAlignment.CENTER), pageSize.GetWidth() / 2, 30, i, iText.Layout.Properties.TextAlignment.CENTER, iText.Layout.Properties.VerticalAlignment.TOP, 0); } //document.Flush(); document.Close(); wr.Close(); } } } catch (Exception ex) { esito.Codice = Esito.ESITO_KO_ERRORE_GENERICO; esito.Descrizione = "PopolaPannelloNotaSpese(DatiAgenda eventoSelezionato, FiguraProfessionale figuraProfessionaleSelezionata) " + ex.Message + Environment.NewLine + ex.StackTrace; } return(esito); }