Exemplo n.º 1
0
        public string CreatePDF()
        {
            // Create PDF Document with ItextSharp
            //string appRootDir = new DirectoryInfo(Environment.CurrentDirectory).FullName;
            //string path = appRootDir + "/PDFs/" + "OrdreMission.pdf";
            try
            {
                // Step 1: Creating System.IO.FileStream object
                using (FileStream fs = new FileStream("Borderau" + Departure.Id + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None))
                    // Step 2: Creating iTextSharp.text.Document object
                    using (Document doc = new Document())
                        // Step 3: Creating iTextSharp.text.pdf.PdfWriter object
                        // It helps to write the Document to the Specified FileStream
                        using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
                        {
                            // Step 4: Openning the Document
                            doc.Open();

                            // Step 5: Adding a paragraph
                            // NOTE: When we want to insert text, then we've to do it through creating paragraph
                            //doc.Add(new Paragraph("Hello World :"));

                            PdfFile file = new PdfFile();

                            PrintPage page = new PrintPage();

                            page.BRDHeader(file, doc, writer, Departure);

                            List <String> HeaderText = new List <string>();
                            HeaderText.Add("Designations");
                            HeaderText.Add("NBRE");
                            HeaderText.Add("Observations");

                            PdfPTable table = file.CreateHeaderTable(doc, HeaderText);
                            // Designations
                            PdfPCell DesignationsCell = new PdfPCell(new Phrase(Departure.Designation.French));
                            DesignationsCell.MinimumHeight = 50f;
                            table.AddCell(DesignationsCell);
                            //NBRE
                            PdfPCell NBRECell = new PdfPCell(new Phrase(Departure.NBRE.ToString()));
                            NBRECell.MinimumHeight = 32f;
                            table.AddCell(NBRECell);
                            //Observations
                            PdfPCell ObsCell = new PdfPCell(new Phrase(Departure.Observations + "\n\n\n\n\n" + "Le Directeur de l'Hopital" + "\n\n"));
                            ObsCell.MinimumHeight = 32f;
                            table.AddCell(ObsCell);


                            PdfContentByte cb = writer.DirectContent;
                            table.TotalWidth = 500f;//80
                            table.WriteSelectedRows(0, -1, 50, doc.PageSize.Width / 2 + 200, cb);

                            //page.BRDFooter(file, doc, writer);

                            // Step 6: Closing the Document
                            doc.Close();
                        }
            }
            // Catching iTextSharp.text.DocumentException if any
            catch (DocumentException de)
            {
                throw de;
            }
            // Catching System.IO.IOException if any
            catch (IOException ioe)
            {
                throw ioe;
            }

            return("Borderau" + Departure.Id + ".pdf");
        }
        public string CreatePDF()
        {
            // Create PDF Document with ItextSharp
            //string appRootDir = new DirectoryInfo(Environment.CurrentDirectory).FullName;
            //string path = appRootDir + "/PDFs/" + "OrdreMission.pdf";
            try
            {
                // Step 1: Creating System.IO.FileStream object
                using (FileStream fs = new FileStream("MaterialsList_" + Location.Name + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None))
                    // Step 2: Creating iTextSharp.text.Document object
                    using (Document doc = new Document())
                        // Step 3: Creating iTextSharp.text.pdf.PdfWriter object
                        // It helps to write the Document to the Specified FileStream
                        using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
                        {
                            // Step 4: Openning the Document
                            doc.Open();

                            // Step 5: Adding a paragraph
                            // NOTE: When we want to insert text, then we've to do it through creating paragraph
                            //doc.Add(new Paragraph("Hello World :"));

                            PdfFile file = new PdfFile();
                            // Document Header
                            file.CreateParagraph(doc, "Royaume du Maroc\nMinistère de la sante\nDélégation Tanger-assilah\nHôpital Mohammed VI", false, false, false);
                            file.AddImage(doc, 50f, 100f, 10f, doc.PageSize.Width / 2 - 15, doc.PageSize.Height / 2 + 320, Resources.MarocHeaderresx.Maroc, ImageFormat.Bmp);
                            file.AddImage(doc, 50f, 100f, 22f, doc.PageSize.Width - 36f - 72f, doc.PageSize.Height / 2 + 320, Resources.SanteHeader.Sante, ImageFormat.Bmp);
                            //

                            file.CreateText(doc, writer, "Inventaire de Materiels de Service : " + Location.Name.French, doc.PageSize.Width / 2 - 85, doc.PageSize.Height / 2 + 250, false, true);


                            List <String> HeaderText = new List <string>();
                            HeaderText.Add("Designation");
                            HeaderText.Add("N/INV");
                            HeaderText.Add("Dimension");
                            HeaderText.Add("Observation");
                            HeaderText.Add("NBRE");
                            PdfPTable table = file.CreateHeaderTable(doc, HeaderText);

                            // List<Material> MaterialsList = new  MaterialBLO(db).GetMaterialsBylocation(Location);

                            //foreach (var item in MaterialsList)
                            //{

                            //    // Designation
                            //    PdfPCell DesignationCell = new PdfPCell(new Phrase(item.Designation.French));
                            //    DesignationCell.MinimumHeight = 32f;
                            //    table.AddCell(DesignationCell);

                            //    // Inventory Number
                            //    PdfPCell InventoryNumberCell = new PdfPCell(new Phrase(item.InventoryNumber));
                            //    InventoryNumberCell.MinimumHeight = 32f;
                            //    table.AddCell(InventoryNumberCell);

                            //    // Dimension
                            //    PdfPCell DimensionCell = new PdfPCell(new Phrase(item.Dimension.ToString()));
                            //    DimensionCell.MinimumHeight = 32f;
                            //    table.AddCell(DimensionCell);

                            //    // Observation
                            //    PdfPCell ObservationCell = new PdfPCell(new Phrase(item.Observation.French));
                            //    ObservationCell.MinimumHeight = 32f;
                            //    table.AddCell(ObservationCell);

                            //    //NBRE
                            //    PdfPCell NBRECell = new PdfPCell(new Phrase(item.NBRE.ToString()));
                            //    NBRECell.MinimumHeight = 32f;
                            //    table.AddCell(NBRECell);
                            //}
                            //////////////////////////////////////////////////

                            foreach (var item in db.Materials)
                            {
                                List <MaterialInOut> MaterialInOutList = new MaterialInOutBLO(db).GetMIOByMaterial(item);
                                if (MaterialInOutList.Count > 0)
                                {
                                    MaterialInOut MIO = MaterialInOutList[0];
                                    if (MIO.Location.Id == Convert.ToInt32(Location.Id))
                                    {
                                        // Designation
                                        PdfPCell DesignationCell = new PdfPCell(new Phrase(MIO.Material.Designation.French));
                                        DesignationCell.MinimumHeight = 32f;
                                        table.AddCell(DesignationCell);

                                        // Inventory Number
                                        PdfPCell InventoryNumberCell = new PdfPCell(new Phrase(MIO.Material.InventoryNumber));
                                        InventoryNumberCell.MinimumHeight = 32f;
                                        table.AddCell(InventoryNumberCell);

                                        // Dimension
                                        PdfPCell DimensionCell = new PdfPCell(new Phrase(MIO.Material.Dimension.ToString()));
                                        DimensionCell.MinimumHeight = 32f;
                                        table.AddCell(DimensionCell);

                                        // Observation
                                        PdfPCell ObservationCell = new PdfPCell(new Phrase(MIO.Material.Observation.French));
                                        ObservationCell.MinimumHeight = 32f;
                                        table.AddCell(ObservationCell);

                                        //NBRE
                                        PdfPCell NBRECell = new PdfPCell(new Phrase(MIO.Material.NBRE.ToString()));
                                        NBRECell.MinimumHeight = 32f;
                                        table.AddCell(NBRECell);
                                    }
                                }
                            }

                            PdfContentByte cb = writer.DirectContent;
                            table.TotalWidth = 500f;
                            table.WriteSelectedRows(0, -1, 50, 665, cb);

                            // Step 6: Closing the Document
                            doc.Close();
                        }
            }
            // Catching iTextSharp.text.DocumentException if any
            catch (DocumentException de)
            {
                throw de;
            }
            // Catching System.IO.IOException if any
            catch (IOException ioe)
            {
                throw ioe;
            }

            return("MaterialsList_" + Location.Name + ".pdf");
        }
Exemplo n.º 3
0
        public string CreatePDF()
        {
            // Create PDF Document with ItextSharp
            //string appRootDir = new DirectoryInfo(Environment.CurrentDirectory).FullName;
            //string path = appRootDir + "/PDFs/" + "OrdreMission.pdf";
            try
            {
                // Step 1: Creating System.IO.FileStream object
                using (FileStream fs = new FileStream("MaterialsList_" + service.Name + ".pdf", FileMode.Create, FileAccess.Write, FileShare.None))
                    // Step 2: Creating iTextSharp.text.Document object
                    using (Document doc = new Document())
                        // Step 3: Creating iTextSharp.text.pdf.PdfWriter object
                        // It helps to write the Document to the Specified FileStream
                        using (PdfWriter writer = PdfWriter.GetInstance(doc, fs))
                        {
                            // Step 4: Openning the Document
                            doc.Open();

                            // Step 5: Adding a paragraph
                            // NOTE: When we want to insert text, then we've to do it through creating paragraph
                            //doc.Add(new Paragraph("Hello World :"));

                            PdfFile file = new PdfFile();
                            // Document Header

                            PrintPage page = new PrintPage();
                            page.CreateHeader(file, doc, writer, service);
                            //
                            List <String> HeaderText = new List <string>();
                            HeaderText.Add("Designation");
                            HeaderText.Add("N/INV");
                            HeaderText.Add("Dimension");
                            HeaderText.Add("Observation");
                            HeaderText.Add("NBRE");
                            PdfPTable table = file.CreateHeaderTable(doc, HeaderText);


                            ///////////////////////////////////////////////

                            foreach (var item in db.Materials)
                            {
                                List <MaterialInOut> InOutMaterial = new MaterialInOutBLO(db).GetMIOByMaterial(item);
                                if (InOutMaterial.Count > 0)
                                {
                                    MaterialInOut MIO = InOutMaterial[0];
                                    if (MIO.Service.Id == Convert.ToInt32(service.Id))
                                    {
                                        // Designation
                                        PdfPCell DesignationCell = new PdfPCell(new Phrase(MIO.Material.Designation.French));
                                        DesignationCell.MinimumHeight = 32f;
                                        table.AddCell(DesignationCell);

                                        // Inventory Number
                                        PdfPCell InventoryNumberCell = new PdfPCell(new Phrase(MIO.Material.InventoryNumber));
                                        InventoryNumberCell.MinimumHeight = 32f;
                                        table.AddCell(InventoryNumberCell);

                                        // Dimension
                                        PdfPCell DimensionCell = new PdfPCell(new Phrase(MIO.Material.ToString()));
                                        DimensionCell.MinimumHeight = 32f;
                                        table.AddCell(DimensionCell);

                                        // Observation
                                        PdfPCell ObservationCell = new PdfPCell(new Phrase(MIO.Material.Observation.French));
                                        ObservationCell.MinimumHeight = 32f;
                                        table.AddCell(ObservationCell);

                                        //NBRE
                                        PdfPCell NBRECell = new PdfPCell(new Phrase(MIO.Material.ToString()));
                                        NBRECell.MinimumHeight = 32f;
                                        table.AddCell(NBRECell);
                                    }
                                }
                            }



                            PdfContentByte cb = writer.DirectContent;
                            table.TotalWidth = 500f;
                            table.WriteSelectedRows(0, -1, 50, 665, cb);

                            //
                            page.CreateFooter(file, doc, writer);
                            // Step 6: Closing the Document
                            doc.Close();
                        }
            }
            // Catching iTextSharp.text.DocumentException if any
            catch (DocumentException de)
            {
                throw de;
            }
            // Catching System.IO.IOException if any
            catch (IOException ioe)
            {
                throw ioe;
            }

            return("MaterialsList_" + service.Name + ".pdf");
        }