Пример #1
0
        private static void addCell(PdfPTable table, string text, string type = "TD", int rowspan = 0, int Colsapn = 0)
        {
            BaseFont bfTimes  = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
            BaseFont bfTimes1 = BaseFont.CreateFont(BaseFont.TIMES_BOLD, BaseFont.CP1252, false);

            iTextSharp.text.Font times;
            if (type == "TH")
            {
                times = new iTextSharp.text.Font(bfTimes1, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
            }
            else
            {
                times = new iTextSharp.text.Font(bfTimes, 10, iTextSharp.text.Font.NORMAL, iTextSharp.text.BaseColor.BLACK);
            }
            PdfPCell cell = new PdfPCell(new Phrase(text, times));

            if (rowspan != 0)
            {
                cell.Rowspan = rowspan;
            }
            if (Colsapn != 0)
            {
                cell.Colspan = Colsapn;
            }
            cell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;
            cell.VerticalAlignment   = PdfPCell.ALIGN_MIDDLE;
            cell.MinimumHeight       = 20f;
            BaseColor color = WebColors.GetRGBColor("#008CF9");

            cell.BorderColor = color;
            table.AddCell(cell);
        }
Пример #2
0
// ---------------------------------------------------------------------------
        public byte[] FillTemplate(byte[] pdf, Movie movie)
        {
            using (MemoryStream ms = new MemoryStream()) {
                PdfReader reader = new PdfReader(pdf);
                using (PdfStamper stamper = new PdfStamper(reader, ms)) {
                    AcroFields form  = stamper.AcroFields;
                    BaseColor  color = WebColors.GetRGBColor(
                        "#" + movie.entry.category.color
                        );
                    PushbuttonField bt = form.GetNewPushbuttonFromField(POSTER);
                    bt.Layout           = PushbuttonField.LAYOUT_ICON_ONLY;
                    bt.ProportionalIcon = true;
                    bt.Image            = Image.GetInstance(Path.Combine(IMAGE, movie.Imdb + ".jpg"));
                    bt.BackgroundColor  = color;
                    form.ReplacePushbuttonField(POSTER, bt.Field);

                    PdfContentByte           canvas = stamper.GetOverContent(1);
                    float                    size   = 12;
                    AcroFields.FieldPosition f      = form.GetFieldPositions(TEXT)[0];
                    while (AddParagraph(CreateMovieParagraph(movie, size),
                                        canvas, f, true) && size > 6)
                    {
                        size -= 0.2f;
                    }
                    AddParagraph(CreateMovieParagraph(movie, size), canvas, f, false);

                    form.SetField(YEAR, movie.Year.ToString());
                    form.SetFieldProperty(YEAR, "bgcolor", color, null);
                    form.SetField(YEAR, movie.Year.ToString());
                    stamper.FormFlattening = true;
                }
                return(ms.ToArray());
            }
        }
Пример #3
0
        public virtual void MoreColorTest()
        {
            String colorStr     = "#888";
            String colorStrLong = "#888888";

            Assert.AreEqual(WebColors.GetRGBColor(colorStr), WebColors.GetRGBColor(colorStrLong), "Oh Nooo colors are different");
        }
Пример #4
0
 public PdfDocument(object model)
 {
     _model                = model;
     _titleFont            = new Font(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.CACHED), 16);
     _itemFont             = new Font(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.CACHED), 12);
     _boldFont             = new Font(BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1250, BaseFont.CACHED), 12, Font.BOLD);
     _tableHeaderGrayColor = WebColors.GetRGBColor("#999999");
 }
        //add table cell
        private void addTableCell(PdfPTable table, String text, Font font, int collapse, int allignement, String color)
        {
            PdfPCell  cell          = new PdfPCell(new Phrase(text, font));
            BaseColor cellBackColor = WebColors.GetRGBColor(color);

            cell.BackgroundColor     = cellBackColor;
            cell.Colspan             = collapse;
            cell.Padding             = 4;
            cell.HorizontalAlignment = allignement;
            table.AddCell(cell);
        }
 /// <summary>Operations to perform before drawing an element.</summary>
 /// <remarks>
 /// Operations to perform before drawing an element.
 /// This includes setting stroke color and width, fill color.
 /// </remarks>
 /// <param name="context">the svg draw context</param>
 internal virtual void PreDraw(SvgDrawContext context)
 {
     if (this.attributesAndStyles != null)
     {
         PdfCanvas currentCanvas = context.GetCurrentCanvas();
         if (!partOfClipPath)
         {
             {
                 // fill
                 String fillRawValue = GetAttribute(SvgConstants.Attributes.FILL);
                 this.doFill = !SvgConstants.Values.NONE.EqualsIgnoreCase(fillRawValue);
                 if (doFill && CanElementFill())
                 {
                     Color color = ColorConstants.BLACK;
                     if (fillRawValue != null)
                     {
                         color = WebColors.GetRGBColor(fillRawValue);
                     }
                     currentCanvas.SetFillColor(color);
                 }
             }
             {
                 // stroke
                 String strokeRawValue = GetAttribute(SvgConstants.Attributes.STROKE);
                 if (!SvgConstants.Values.NONE.EqualsIgnoreCase(strokeRawValue))
                 {
                     DeviceRgb rgbColor = WebColors.GetRGBColor(strokeRawValue);
                     if (strokeRawValue != null && rgbColor != null)
                     {
                         currentCanvas.SetStrokeColor(rgbColor);
                         String strokeWidthRawValue = GetAttribute(SvgConstants.Attributes.STROKE_WIDTH);
                         float  strokeWidth         = 1f;
                         if (strokeWidthRawValue != null)
                         {
                             strokeWidth = CssUtils.ParseAbsoluteLength(strokeWidthRawValue);
                         }
                         currentCanvas.SetLineWidth(strokeWidth);
                         doStroke = true;
                     }
                 }
             }
             {
                 // opacity
                 String opacityValue = GetAttribute(SvgConstants.Attributes.FILL_OPACITY);
                 if (opacityValue != null && !SvgConstants.Values.NONE.EqualsIgnoreCase(opacityValue))
                 {
                     PdfExtGState gs1 = new PdfExtGState();
                     gs1.SetFillOpacity(float.Parse(opacityValue, System.Globalization.CultureInfo.InvariantCulture));
                     currentCanvas.SetExtGState(gs1);
                 }
             }
         }
     }
 }
Пример #7
0
        /// <summary>
        /// Process table row for PDF export
        /// </summary>
        /// <param name="table"></param>
        /// <param name="line"></param>
        /// <param name="font"></param>
        /// <param name="isHeader"></param>
        private static void process(Table table, String line, PdfFont font, Boolean isHeader)
        {
            StringTokenizer tokenizer = new StringTokenizer(line, ",");

            while (tokenizer.HasMoreTokens())
            {
                if (isHeader)
                {
                    table.AddHeaderCell(new Cell().SetBackgroundColor(WebColors.GetRGBColor("A6B8AE")).Add(new Paragraph(tokenizer.NextToken()).SetFont(font)));
                }
                else
                {
                    table.AddCell(new Cell().Add(new iText.Layout.Element.Paragraph(tokenizer.NextToken()).SetFont(font)));
                }
            }
        }
Пример #8
0
// ---------------------------------------------------------------------------

        /**
         * Create a table with information about a movie.
         * @param screening a Screening
         * @return a table
         */
        private PdfPTable GetTable(Screening screening)
        {
            // Create a table with 4 columns
            PdfPTable table = new PdfPTable(4);

            table.SetWidths(new int[] { 1, 5, 10, 10 });
            // Get the movie
            Movie movie = screening.movie;
            // A cell with the title as a nested table spanning the complete row
            PdfPCell cell = new PdfPCell();

            // nesting is done with addElement() in this example
            cell.AddElement(FullTitle(screening));
            cell.Colspan = 4;
            cell.Border  = PdfPCell.NO_BORDER;
            BaseColor color = WebColors.GetRGBColor(
                "#" + movie.entry.category.color
                );

            cell.BackgroundColor = color;
            table.AddCell(cell);
            // empty cell
            cell              = new PdfPCell();
            cell.Border       = PdfPCell.NO_BORDER;
            cell.UseAscender  = true;
            cell.UseDescender = true;
            table.AddCell(cell);
            // cell with the movie poster
            cell        = new PdfPCell(GetImage(movie.Imdb));
            cell.Border = PdfPCell.NO_BORDER;
            table.AddCell(cell);
            // cell with the list of directors
            cell = new PdfPCell();
            cell.AddElement(PojoToElementFactory.GetDirectorList(movie));
            cell.Border       = PdfPCell.NO_BORDER;
            cell.UseAscender  = true;
            cell.UseDescender = true;
            table.AddCell(cell);
            // cell with the list of countries
            cell = new PdfPCell();
            cell.AddElement(PojoToElementFactory.GetCountryList(movie));
            cell.Border       = PdfPCell.NO_BORDER;
            cell.UseAscender  = true;
            cell.UseDescender = true;
            table.AddCell(cell);
            return(table);
        }
Пример #9
0
        public virtual void GoodColorTests()
        {
            String[] colors =
            {
                "#00FF00", "00FF00", "#0F0", "0F0", "LIme",
                "rgb(0,255,0 )"
            };
            // TODO webColor creates colors with a zero alpha channel (save
            // "transparent"), BaseColor's 3-param constructor creates them with a
            // 0xFF alpha channel. Which is right?!
            BaseColor testCol = new BaseColor(0, 255, 0);

            foreach (String colStr in colors)
            {
                BaseColor curCol = WebColors.GetRGBColor(colStr);
                Assert.IsTrue(testCol.Equals(curCol), DumpColor(testCol) + "!=" + DumpColor(curCol));
            }
        }
        private TransparentColor GetColorFromAttributeValue(SvgDrawContext context, String rawColorValue, float objectBoundingBoxMargin
                                                            , float parentOpacity)
        {
            if (rawColorValue == null)
            {
                return(null);
            }
            CssDeclarationValueTokenizer tokenizer = new CssDeclarationValueTokenizer(rawColorValue);

            CssDeclarationValueTokenizer.Token token = tokenizer.GetNextValidToken();
            if (token == null)
            {
                return(null);
            }
            String tokenValue = token.GetValue();

            if (tokenValue.StartsWith("url(#") && tokenValue.EndsWith(")"))
            {
                Color            resolvedColor   = null;
                float            resolvedOpacity = 1;
                String           normalizedName  = tokenValue.JSubstring(5, tokenValue.Length - 1).Trim();
                ISvgNodeRenderer colorRenderer   = context.GetNamedObject(normalizedName);
                if (colorRenderer is AbstractGradientSvgNodeRenderer)
                {
                    resolvedColor = ((AbstractGradientSvgNodeRenderer)colorRenderer).CreateColor(context, GetObjectBoundingBox
                                                                                                     (context), objectBoundingBoxMargin, parentOpacity);
                }
                if (resolvedColor != null)
                {
                    return(new TransparentColor(resolvedColor, resolvedOpacity));
                }
                token = tokenizer.GetNextValidToken();
            }
            // may become null after function parsing and reading the 2nd token
            if (token != null)
            {
                String value = token.GetValue();
                if (!SvgConstants.Values.NONE.EqualsIgnoreCase(value))
                {
                    return(new TransparentColor(WebColors.GetRGBColor(value), parentOpacity * GetAlphaFromRGBA(value)));
                }
            }
            return(null);
        }
Пример #11
0
        public void BadColorTests()
        {
            String[] badColors = { "", null, "#xyz", "#12345", "notAColor" };

            foreach (String curStr in badColors)
            {
                try {
                    // we can ignore the return value that'll never happen here
                    WebColors.GetRGBColor(curStr);

                    Assert.IsTrue(false, "getRGBColor should have thrown for: " + curStr);
                } catch (FormatException e) {
                    // Non-null bad colors will throw an illArgEx
                    Assert.IsTrue(curStr != null);
                    // good, it was supposed to throw
                } catch (NullReferenceException e) {
                    // the null color will NPE
                    Assert.IsTrue(curStr == null);
                }
            }
        }
Пример #12
0
// ---------------------------------------------------------------------------

        /**
         * Draws a colored block on the time table, corresponding with
         * the screening of a specific movie.
         * @param    screening    a screening POJO, contains a movie and a category
         * @param    under    the canvas to which the block is drawn
         */
        protected void DrawBlock(
            Screening screening, PdfContentByte under, PdfContentByte over
            )
        {
            under.SaveState();
            BaseColor color = WebColors.GetRGBColor(
                "#" + screening.movie.entry.category.color
                );

            under.SetColorFill(color);
            Rectangle rect = GetPosition(screening);

            under.Rectangle(
                rect.Left, rect.Bottom, rect.Width, rect.Height
                );
            under.Fill();
            over.Rectangle(
                rect.Left, rect.Bottom, rect.Width, rect.Height
                );
            over.Stroke();
            under.RestoreState();
        }
Пример #13
0
// ---------------------------------------------------------------------------

        /**
         * Manipulates a PDF file src with the file dest as result
         * @param src the original PDF
         */
        public virtual byte[] ManipulatePdf(byte[] src)
        {
            locations = PojoFactory.GetLocations();
            // Create a reader
            PdfReader reader = new PdfReader(src);

            using (MemoryStream ms = new MemoryStream()) {
                // Create a stamper
                using (PdfStamper stamper = new PdfStamper(reader, ms)) {
                    // Add the annotations
                    int           page = 1;
                    Rectangle     rect;
                    PdfAnnotation annotation;
                    Movie         movie;
                    foreach (string day in PojoFactory.GetDays())
                    {
                        foreach (Screening screening in PojoFactory.GetScreenings(day))
                        {
                            movie      = screening.movie;
                            rect       = GetPosition(screening);
                            annotation = PdfAnnotation.CreateText(
                                stamper.Writer, rect, movie.MovieTitle,
                                string.Format(INFO, movie.Year, movie.Duration),
                                false, "Help"
                                );
                            annotation.Color = WebColors.GetRGBColor(
                                "#" + movie.entry.category.color
                                );
                            stamper.AddAnnotation(annotation, page);
                        }
                        page++;
                    }
                }
                return(ms.ToArray());
            }
        }
Пример #14
0
 public virtual void TestGetRGBColorChannelsMissingBlue()
 {
     Assert.AreEqual(0, WebColors.GetRGBColor(RGB_MISSING_COLOR_VALUES).B);
 }
Пример #15
0
 public virtual void TestGetRGBColorChannelsMissingGreen()
 {
     Assert.AreEqual(63, WebColors.GetRGBColor(RGB_MISSING_COLOR_VALUES).G);
 }
Пример #16
0
 public virtual void TestGetRGBColorChannelsMissingRed()
 {
     Assert.AreEqual(127, WebColors.GetRGBColor(RGB_MISSING_COLOR_VALUES).R);
 }
Пример #17
0
 public virtual void TestGetRGBColorValueOutOfRange()
 {
     Assert.AreEqual(255, WebColors.GetRGBColor(RGB_OUT_OF_RANGE).B);
 }
Пример #18
0
 public virtual void TestGetRGBColorNegativeValue()
 {
     Assert.AreEqual(0, WebColors.GetRGBColor(RGB_OUT_OF_RANGE).R);
 }
    public Boolean PDFUpload(Int64 PurchaseOrderId)
    {
        string finalResult = string.Empty;
        bool   flag        = true;

        Int64 inid = 0;

        try
        {
            //string query = "Select POH.*,CONVERT(nvarchar, POH.OrderDate,103) + ' '+REPLACE(REPLACE(CONVERT(varchar(15), CAST(POH.OrderDate AS TIME), 100), 'P', ' P'), 'A', ' A') as OrderDate1, POD.*, PM.ProdName as ProdName , VM.*, BM.BrandName as Brand, SM.Size as Size from [DoctorDiagnosisNew].[PurchaseOrderHeader] POH ,[DoctorDiagnosisNew].[PurchaseOrderDetails] POD ,[dbo].[VendorMaster] VM ,[dbo].[BrandMaster] BM ,[dbo].[SizeMaster] SM ,[dbo].[ProductMaster] PM where POH.isdeleted=0 AND POH.[PurchaseOrderId] = " + CategoryId + " AND POH.[VendorId] = VM.[VendorId] AND POH.[PurchaseOrderId] = POD.[PurchaseOrderId] AND POD.[BrandId] = BM.[BrandId] AND POD.[SizeId] = SM.[SizeId] AND POD.[ProdId] = PM.[ProdId] ORDER BY ProdName DESC";
            DataSet ds = new DataSet();

            SqlCommand cmd = new SqlCommand();

            cmd.CommandText = "PurchaseOrderHeader_SelectById";
            cmd.Parameters.AddWithValue("@id", PurchaseOrderId);
            //cmd.Parameters.AddWithValue("@password", password);
            cmd.CommandType = CommandType.StoredProcedure;
            SqlDataAdapter sda = new SqlDataAdapter();
            cmd.Connection    = con;
            sda.SelectCommand = cmd;



            //SqlDataAdapter da = new SqlDataAdapter(query, con);
            sda.Fill(ds);
            String       po      = ds.Tables[0].Rows[0]["PONo"].ToString();
            Document     pdfDoc  = new Document(PageSize.A4, 10, 10, 10, 10);
            MemoryStream PDFData = new MemoryStream();
            //PdfWriter pw = PdfWriter.GetInstance(
            //PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(Context.Server.MapPath("~/uploads/PurchaseOrders/") + po + ".pdf", FileMode.Create));
            PdfWriter writer = PdfWriter.GetInstance(pdfDoc, PDFData);

            var titleFont      = FontFactory.GetFont("Arial", 6, Font.NORMAL);
            var titleFontBlue  = FontFactory.GetFont("Arial", 14, Font.NORMAL, Color.BLUE);
            var boldTableFont  = FontFactory.GetFont("Arial", 8, Font.BOLD);              //8
            var boldTableFont1 = FontFactory.GetFont("Arial", 8, Font.BOLD);              //8
            var bodyFont       = FontFactory.GetFont("Arial", 7, Font.NORMAL);            //8
            var EmailFont      = FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK); //8
            var HeaderFont     = FontFactory.GetFont("Arial", 10, Font.BOLD, Color.BLACK);

            var   footerfont = FontFactory.GetFont("Arial", 6, Font.NORMAL, Color.BLACK);//8
            Color TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE");

            Rectangle pageSize = writer.PageSize;
            // Open the Document for writing
            pdfDoc.Open();
            //Add elements to the document here

            #region Top table
            // Create the header table
            PdfPTable headertable = new PdfPTable(3);
            headertable.HorizontalAlignment = 0;
            headertable.WidthPercentage     = 100;
            headertable.SetWidths(new float[] { 100f, 320f, 220f }); // then set the column's __relative__ widths
            headertable.DefaultCell.Border = Rectangle.NO_BORDER;
            headertable.DefaultCell.Border = Rectangle.BOX;          //for testing



            // invoice rperte

            PdfPTable Invoicetable2 = new PdfPTable(1);
            Invoicetable2.HorizontalAlignment = 0;
            Invoicetable2.WidthPercentage     = 100;
            Invoicetable2.SetWidths(new float[] { 500f });  // then set the column's __relative__ widths
            Invoicetable2.DefaultCell.Border = Rectangle.NO_BORDER;

            {
                PdfPTable mainN = new PdfPTable(1);
                // tablenew.HorizontalAlignment = 1;
                //PdfPCell cellnew = new PdfPCell(new Phrase("PURCHASE ORDER"),EmailFont);
                PdfPCell cellN = new PdfPCell(new Phrase("Morya Tools \n\n 22, Pradhan Park, M.G Road, Nashik, Maharashtra, India 422001 "
                                                         + "\n\nPhone: (0253) 3014578 Email: [email protected]", HeaderFont));
                cellN.PaddingTop        = 15f;
                cellN.PaddingBottom     = 15f;
                cellN.VerticalAlignment = 1;
                //cellnew.Colspan = 2;
                cellN.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
                mainN.AddCell(cellN);
                PdfPCell nesthousingnn = new PdfPCell(mainN);

                PdfPTable tablenew = new PdfPTable(1);
                // tablenew.HorizontalAlignment = 1;
                //PdfPCell cellnew = new PdfPCell(new Phrase("PURCHASE ORDER"),EmailFont);
                PdfPCell cellnew = new PdfPCell(new Phrase("PURCHASE ORDER", EmailFont));
                cellnew.PaddingTop        = 15f;
                cellnew.PaddingBottom     = 15f;
                cellnew.VerticalAlignment = 1;
                //cellnew.Colspan = 2;
                cellnew.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
                tablenew.AddCell(cellnew);
                PdfPCell nesthousingn = new PdfPCell(tablenew);



                PdfPTable tablenew1 = new PdfPTable(2);

                // tablenew1.DefaultCell.FixedHeight = 100f;
                PdfPCell cellnew4 = new PdfPCell(new Phrase("PO No :    " + ds.Tables[0].Rows[0]["PONo"].ToString(), EmailFont));
                cellnew4.FixedHeight         = 30f;
                cellnew4.HorizontalAlignment = 1;
                cellnew4.PaddingTop          = 15f;
                cellnew4.PaddingBottom       = 15f;
                PdfPCell cellnew5 = new PdfPCell(new Phrase("PO Date :  " + ds.Tables[0].Rows[0]["OrderDate1"].ToString(), EmailFont));
                cellnew5.HorizontalAlignment = 1;
                cellnew5.PaddingTop          = 15f;
                cellnew5.PaddingBottom       = 15f;

                tablenew1.AddCell(cellnew4);

                tablenew1.AddCell(cellnew5);



                PdfPTable tablevendor = new PdfPTable(2);

                PdfPCell suppliername = new PdfPCell(new Phrase("VENDOR NAME :    " + ds.Tables[0].Rows[0]["vendorName"].ToString(), EmailFont));
                suppliername.MinimumHeight = 80f;
                suppliername.PaddingTop    = 10f;
                PdfPCell supplierdetails = new PdfPCell(new Phrase("VENDOR DETAILS:  \n\n\t Contact Person : " + ds.Tables[0].Rows[0]["vendorName"].ToString() + "\n\n\t Mobile No : " + ds.Tables[0].Rows[0]["MobileNo1"].ToString() + "\n\n\t Email : " + ds.Tables[0].Rows[0]["email"].ToString(), EmailFont));
                supplierdetails.PaddingTop = 10f;
                // PdfPCell termsnconditions = new PdfPCell(new Phrase("Terms & Conditions:    ", EmailFont));

                tablevendor.AddCell(suppliername);
                tablevendor.AddCell(supplierdetails);
                //tablevendor.AddCell(termsnconditions);



                PdfPCell nesthousingn1 = new PdfPCell(tablenew1);
                PdfPCell nesthousingn2 = new PdfPCell(tablevendor);
                // nesthousingn2.Height = 10f;
                //PdfPCell nesthousingn3 = new PdfPCell(tablenew3);


                nesthousingn.Border = Rectangle.NO_BORDER;

                //nesthousingn.PaddingBottom = 10f;
                Invoicetable2.AddCell(nesthousingnn);
                Invoicetable2.AddCell(nesthousingn);
                Invoicetable2.AddCell(nesthousingn1);
                Invoicetable2.AddCell(nesthousingn2);
                //Invoicetable2.AddCell(nesthousingn3);
            }
            //invoice repeat

            // Invoicetable2.AddCell(headertable);
            Invoicetable2.SpacingBefore = 3f;
            //  Invoicetable. = 10f;

            // pdfDoc.Add(Invoicetable);



            #endregion

            #region Items Table
            //Create body table
            PdfPTable itemTable = new PdfPTable(2);

            itemTable.HorizontalAlignment = 0;
            itemTable.WidthPercentage     = 100;
            // itemTable.SetWidths(new float[] { });  // then set the column's __relative__ widths
            //itemTable.SetWidths(new float[] { 4, 30, 6, 6, 6 });
            itemTable.SpacingAfter = 10;

            //itemTable.DefaultCell.Border = Rectangle.BOX;



            PdfPCell cell1 = new PdfPCell(new Phrase("PRODUCT", boldTableFont));
            //cell1.BackgroundColor = TabelHeaderBackGroundColor;
            cell1.HorizontalAlignment = Element.ALIGN_CENTER;
            itemTable.AddCell(cell1);

            /*
             * PdfPCell cell2 = new PdfPCell(new Phrase("BRAND", boldTableFont));
             * //cell2.BackgroundColor = TabelHeaderBackGroundColor;
             * cell2.HorizontalAlignment = 1;
             * itemTable.AddCell(cell2);
             *
             *
             *
             * PdfPCell cell3 = new PdfPCell(new Phrase("SIZE", boldTableFont));
             * //cell4.BackgroundColor = TabelHeaderBackGroundColor;
             * cell3.HorizontalAlignment = 1;
             * itemTable.AddCell(cell3);
             */

            PdfPCell cell4 = new PdfPCell(new Phrase("QUANTITY", boldTableFont));
            //cell5.BackgroundColor = TabelHeaderBackGroundColor;
            cell4.HorizontalAlignment = 1;
            itemTable.AddCell(cell4);


            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                PdfPCell cell1i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["ProdName"].ToString(), bodyFont));
                //cell1.BackgroundColor = TabelHeaderBackGroundColor;
                cell1i.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell1i);

                /*
                 * PdfPCell cell2i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["Brand"].ToString(), bodyFont));
                 * //cell2.BackgroundColor = TabelHeaderBackGroundColor;
                 * cell2i.HorizontalAlignment = 1;
                 * itemTable.AddCell(cell2i);
                 *
                 *
                 *
                 * PdfPCell cell4i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["Size"].ToString(), bodyFont));
                 * //cell4.BackgroundColor = TabelHeaderBackGroundColor;
                 * cell4i.HorizontalAlignment = 1;
                 * itemTable.AddCell(cell4i);
                 */

                PdfPCell cell5i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["Quantity1"].ToString(), bodyFont));
                //cell5.BackgroundColor = TabelHeaderBackGroundColor;
                cell5i.HorizontalAlignment = 1;
                itemTable.AddCell(cell5i);

                //    PdfPCell cell3i = new PdfPCell(new Phrase("" + dtOrderProducts.Rows[i]["Amount"], bodyFont));
                //    //cell3.BackgroundColor = TabelHeaderBackGroundColor;
                //    cell3i.HorizontalAlignment = 1;
                //    itemTable.AddCell(cell3i);
            }



            PdfPCell nesthousingn3 = new PdfPCell(itemTable);
            //  PdfPCell nesthousingn4 = new PdfPCell(totalTable);


            //nesthousingn.Border = Rectangle.NO_BORDER;

            //nesthousingn.PaddingBottom = 10f;
            Invoicetable2.AddCell(nesthousingn3);
            // Invoicetable2.AddCell(nesthousingn4);
            // pdfDoc.Add(Invoicetable2);
            #endregion



            PdfPTable noTable1 = new PdfPTable(2);

            noTable1.HorizontalAlignment = 0;
            noTable1.WidthPercentage     = 100;
            // itemTable.SetWidths(new float[] {2,30,6,6,6,6,6,6,6,6,6,4,4,7 });  // then set the column's __relative__ widths
            //amtTable.SetWidths(new float[] { 4, 30});
            // amtTable.SpacingAfter = 10;

            noTable1.DefaultCell.Border = 0;


            PdfPCell cellnote1 = new PdfPCell(new Phrase("PREPARED BY\nNAME : " + "\nSIGNATURE : " + "\nDATE & TIME : ", EmailFont));
            cellnote1.Border = 0;
            cellnote1.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right


            noTable1.AddCell(cellnote1);



            PdfPCell cellnote3 = new PdfPCell(new Phrase("FOR MORYA TOOLS\n\n\n\nAUTHORIZED SIGNATORY", EmailFont));
            cellnote3.Border = 0;
            cellnote3.HorizontalAlignment = 2;//0=Left, 1=Centre, 2=Right


            noTable1.AddCell(cellnote3);



            PdfPCell nesthousingn5 = new PdfPCell(noTable1);
            Invoicetable2.AddCell(nesthousingn5);



            pdfDoc.Add(Invoicetable2);
            pdfDoc.Close();



            DownloadPDF(PDFData, po);



            Context.Response.Clear();
            Context.Response.ContentType = "application/json";
            Context.Response.Flush();
            Context.Response.Write(finalResult);
            Context.Response.End();



            //}
        }
        catch { }
        finally { con.Close(); }

        return(flag);
    }
Пример #20
0
 public virtual void TestGetRGBColorInPercentGreen()
 {
     Assert.AreEqual(84, WebColors.GetRGBColor(RGB_PERCENT).G);
 }
Пример #21
0
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="System.Exception"/>
        private void ElementOpacityTest(String elem)
        {
            String      outFileName     = destinationFolder + elem + "ElementOpacity01.pdf";
            String      cmpFileName     = sourceFolder + "cmp_" + elem + "ElementOpacity01.pdf";
            PdfDocument pdfDocument     = new PdfDocument(new PdfWriter(outFileName));
            Document    document        = new Document(pdfDocument);
            DeviceRgb   divBackground   = WebColors.GetRGBColor("#82abd6");
            DeviceRgb   paraBackground  = WebColors.GetRGBColor("#994ec7");
            DeviceRgb   textBackground  = WebColors.GetRGBColor("#009688");
            DeviceRgb   tableBackground = WebColors.GetRGBColor("#ffc107");

            document.SetFontColor(ColorConstants.WHITE);
            Div div = new Div().SetBackgroundColor(divBackground);

            if ("div".Equals(elem))
            {
                div.SetOpacity(0.3f);
            }
            div.Add(new Paragraph("direct div content"));
            Paragraph p = new Paragraph("direct paragraph content").SetBackgroundColor(paraBackground);

            if ("para".Equals(elem))
            {
                p.SetOpacity(0.3f);
            }
            Text text = new Text("text content").SetBackgroundColor(textBackground);

            p.Add(text);
            if ("text".Equals(elem))
            {
                text.SetOpacity(0.3f);
            }
            div.Add(p);
            iText.Layout.Element.Image image = new Image(ImageDataFactory.Create(sourceFolder + "itis.jpg"));
            div.Add(image);
            if ("image".Equals(elem))
            {
                image.SetOpacity(0.3f);
            }
            Table table = new Table(UnitValue.CreatePercentArray(2)).UseAllAvailableWidth().SetBackgroundColor(tableBackground
                                                                                                               );

            table.AddCell("Cell00");
            table.AddCell("Cell01");
            Cell cell10 = new Cell().Add(new Paragraph("Cell10"));

            if ("cell".Equals(elem))
            {
                cell10.SetOpacity(0.3f);
            }
            table.AddCell(cell10);
            table.AddCell(new Cell().Add(new Paragraph("Cell11")));
            if ("table".Equals(elem))
            {
                table.SetOpacity(0.3f);
            }
            div.Add(table);
            List list = new List();

            if ("list".Equals(elem))
            {
                list.SetOpacity(0.3f);
            }
            ListItem listItem = new ListItem("item 0");

            list.Add(listItem);
            if ("listItem".Equals(elem))
            {
                listItem.SetOpacity(0.3f);
            }
            list.Add("item 1");
            div.Add(list);
            document.Add(div);
            document.Close();
            NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder
                                                                             , "diff"));
        }
Пример #22
0
        public void ExportDatatablePdf(DataTable dtblTable, String strPdfPath, string strHeader)
        {
            System.IO.FileStream fs       = new FileStream(strPdfPath, FileMode.Create, FileAccess.Write, FileShare.None);
            Document             document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.A4);
            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            document.Open();

            //Report Header
            BaseFont  bfntHead   = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font      fntHead    = new Font(bfntHead, 16, 1, Color.BLACK);
            Paragraph prgHeading = new Paragraph();

            prgHeading.Alignment = Element.ALIGN_CENTER;
            prgHeading.Add(new Chunk(strHeader.ToUpper(), fntHead));
            document.Add(prgHeading);



            //Add a line seperation
            Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, Color.BLACK, Element.ALIGN_LEFT, 1)));

            document.Add(p);

            //Add line break
            document.Add(new Chunk("\n", fntHead));

            //Write the table
            PdfPTable table = new PdfPTable(dtblTable.Columns.Count);
            //Table header

            BaseFont btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntColumnHeader = new Font(btnColumnHeader, 9, 1, Color.BLACK);

            for (int i = 0; i < dtblTable.Columns.Count; i++)
            {
                PdfPCell cell = new PdfPCell();
                cell.BorderColor     = WebColors.GetRGBColor("#c4e4ff");
                cell.BackgroundColor = WebColors.GetRGBColor("#c5d9ea");
                cell.AddElement(new Chunk(dtblTable.Columns[i].ColumnName.ToUpper(), fntColumnHeader));
                table.AddCell(cell);
            }
            //table Data

            BaseFont btnColumnData = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font     fntColumnData = new Font(btnColumnData, 9, 2, Color.BLACK);

            for (int i = 0; i < dtblTable.Rows.Count; i++)
            {
                for (int j = 0; j < dtblTable.Columns.Count; j++)
                {
                    PdfPCell cell = new PdfPCell();
                    cell.BorderColor     = WebColors.GetRGBColor("#c4e4ff");
                    cell.BackgroundColor = Color.WHITE;
                    cell.AddElement(new Chunk(dtblTable.Rows[i][j].ToString(), fntColumnData));
                    table.AddCell(cell);
                    //  table.AddCell(dtblTable.Rows[i][j].ToString());
                }
            }

            document.Add(table);
            document.Close();
            writer.Close();
            fs.Close();
        }
Пример #23
0
        public MemoryStream GetPDF(Response <QuotationDto> response, string fullNameUser)
        {
            MemoryStream memoryStream = new MemoryStream();
            Generator    generator    = new Generator();
            TextUtils    textUtils    = new TextUtils();

            using (Document document = new Document(PageSize.A4, 40, 40, 140, 40))
            {
                try
                {
                    PdfWriter pdfWriter = PdfWriter.GetInstance(document, memoryStream);
                    pdfWriter.CloseStream = false;
                    pdfWriter.PageEvent   = new ITextEvents();

                    document.Open();

                    for (int i = 1; i <= 29; i++)
                    {
                        if (i == 1)
                        {
                            var pdfPTable = generator.GetPageOne(response);
                            document.Add(pdfPTable);
                            document.NewPage();
                        }

                        if (i == 2)
                        {
                            var elements = generator.GetPageTwo(response);
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 3)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 4)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 5)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 6)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 7)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);

                            document.SetPageSize(PageSize.A4.Rotate());
                            document.NewPage();
                        }

                        if (i == 8)
                        {
                            var elements = generator.GetPageEight(response, fullNameUser);
                            document.Add(elements);

                            document.SetPageSize(PageSize.A4);
                            document.NewPage();
                        }

                        if (i == 9)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 10)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 11)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 12)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 13)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 14)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 15)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 16)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 17)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 18)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 19)
                        {
                            //document.SetPageSize(iTextSharp.text.PageSize.A4.Rotate());
                            //document.SetPageSize(PageSize.A4.Rotate());

                            var       titleFont     = FontFactory.GetFont("Arial", 12, Font.BOLD);
                            var       titleFontBlue = FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLUE);
                            var       boldTableFont = FontFactory.GetFont("Arial", 8, Font.BOLD);
                            var       bodyFont      = FontFactory.GetFont("Arial", 8, Font.NORMAL);
                            var       EmailFont     = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLUE);
                            BaseColor TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE");


                            int countProfile = response.Data.QuotationProfile.Count;
                            int totalColumns = countProfile + 2;

                            //Create body table
                            PdfPTable itemTable = new PdfPTable(totalColumns);

                            itemTable.HorizontalAlignment = 0;
                            itemTable.WidthPercentage     = 100;
                            //itemTable.SetWidths(new float[] { 5, 40, 10, 20, 25 });  // then set the column's __relative__ widths
                            itemTable.SpacingAfter       = 40;
                            itemTable.DefaultCell.Border = Rectangle.BOX;
                            PdfPCell cell1 = new PdfPCell(new Phrase("", boldTableFont));
                            cell1.BackgroundColor     = TabelHeaderBackGroundColor;
                            cell1.HorizontalAlignment = Element.ALIGN_CENTER;
                            itemTable.AddCell(cell1);
                            PdfPCell cell2 = new PdfPCell(new Phrase("", boldTableFont));
                            cell2.BackgroundColor     = TabelHeaderBackGroundColor;
                            cell2.HorizontalAlignment = 1;
                            itemTable.AddCell(cell2);


                            foreach (var item in response.Data.QuotationProfile)
                            {
                                itemTable.AddCell(new PdfPCell(new Phrase(item.ProfileName, boldTableFont))).HorizontalAlignment = Element.ALIGN_CENTER;
                            }

                            PdfPCell cell2A = new PdfPCell(new Phrase("", boldTableFont));
                            cell2A.BackgroundColor     = TabelHeaderBackGroundColor;
                            cell2A.HorizontalAlignment = Element.ALIGN_CENTER;
                            itemTable.AddCell(cell2A);

                            PdfPCell cell2B = new PdfPCell(new Phrase("", boldTableFont));
                            cell2B.BackgroundColor     = TabelHeaderBackGroundColor;
                            cell2B.HorizontalAlignment = 1;
                            itemTable.AddCell(cell2B);

                            foreach (var item in response.Data.QuotationProfile)
                            {
                                itemTable.AddCell(new PdfPCell(new Phrase(item.ServiceTypeName, boldTableFont))).HorizontalAlignment = Element.ALIGN_CENTER;
                            }

                            //foreach (DataRow row in dt.Rows)
                            //{
                            //    PdfPCell numberCell = new PdfPCell(new Phrase("1", bodyFont));
                            //    numberCell.HorizontalAlignment = 1;
                            //    numberCell.PaddingLeft = 10f;
                            //    numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                            //    itemTable.AddCell(numberCell);

                            //    var _phrase = new Phrase();
                            //    _phrase.Add(new Chunk("New Signup Subscription Plan\n", EmailFont));
                            //    _phrase.Add(new Chunk("Subscription Plan description will add here.", bodyFont));
                            //    PdfPCell descCell = new PdfPCell(_phrase);
                            //    descCell.HorizontalAlignment = 0;
                            //    descCell.PaddingLeft = 10f;
                            //    descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                            //    itemTable.AddCell(descCell);

                            //    PdfPCell qtyCell = new PdfPCell(new Phrase("1", bodyFont));
                            //    qtyCell.HorizontalAlignment = 1;
                            //    qtyCell.PaddingLeft = 10f;
                            //    qtyCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                            //    itemTable.AddCell(qtyCell);

                            //    //PdfPCell amountCell = new PdfPCell(new Phrase("$100", bodyFont));
                            //    //amountCell.HorizontalAlignment = 1;
                            //    //amountCell.PaddingLeft = 10f;
                            //    //amountCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                            //    //itemTable.AddCell(amountCell);

                            //    //PdfPCell totalamtCell = new PdfPCell(new Phrase("$100", bodyFont));
                            //    //totalamtCell.HorizontalAlignment = 1;
                            //    //totalamtCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                            //    //itemTable.AddCell(totalamtCell);

                            //}
                            //// Table footer
                            //PdfPCell totalAmtCell1 = new PdfPCell(new Phrase(""));
                            //totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER;
                            //itemTable.AddCell(totalAmtCell1);
                            //PdfPCell totalAmtCell2 = new PdfPCell(new Phrase(""));
                            //totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                            //itemTable.AddCell(totalAmtCell2);
                            //PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(""));
                            //totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                            //itemTable.AddCell(totalAmtCell3);
                            //PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Total Amount", boldTableFont));
                            //totalAmtStrCell.Border = Rectangle.TOP_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                            //totalAmtStrCell.HorizontalAlignment = 1;
                            //itemTable.AddCell(totalAmtStrCell);
                            //PdfPCell totalAmtCell = new PdfPCell(new Phrase("$100", boldTableFont));
                            //totalAmtCell.HorizontalAlignment = 1;
                            //itemTable.AddCell(totalAmtCell);

                            //PdfPCell cell = new PdfPCell(new Phrase("***NOTICE: A finance charge of 1.5% will be made on unpaid balances after 30 days. ***", bodyFont));
                            //cell.Colspan = 5;
                            //cell.HorizontalAlignment = 1;
                            //itemTable.AddCell(cell);

                            document.Add(itemTable);
                            document.NewPage();
                        }

                        if (i == 20)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 21)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 22)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 23)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 24)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 25)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 26)
                        {
                            Paragraph elements = new Paragraph("Anexo 4. Registro como proveedor de Antamina", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;

                            Image image = Image.GetInstance(HttpContext.Current.Server.MapPath("~/images/certificado_registro.png"));
                            image.ScaleToFit(450f, 550f);
                            image.Alignment  = Image.ALIGN_CENTER;
                            image.PaddingTop = 20f;

                            document.Add(elements);
                            document.Add(image);

                            document.NewPage();
                        }

                        if (i == 27)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 28)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }

                        if (i == 29)
                        {
                            Paragraph elements = new Paragraph("SIN DATA", textUtils.fontBold12Black);
                            elements.Alignment = Element.ALIGN_JUSTIFIED;
                            document.Add(elements);
                            document.NewPage();
                        }
                    }

                    document.Close();

                    byte[] byteInfo = memoryStream.ToArray();
                    memoryStream.Write(byteInfo, 0, byteInfo.Length);
                    memoryStream.Position = 0;
                }
                catch (Exception ex)
                {
                    ErrorUtilities.AddLog(ex);
                }
            }

            return(memoryStream);
        }
Пример #24
0
        private void button1_Click(object sender, EventArgs e)
        {
            System.IO.FileStream fs       = new FileStream("Test.pdf", FileMode.Create, FileAccess.Write, FileShare.None);
            Document             document = new Document();

            document.SetPageSize(iTextSharp.text.PageSize.LETTER);
            PdfWriter writer = PdfWriter.GetInstance(document, fs);

            document.Open();

            //Report Header
            BaseFont  bfntHead   = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font      fntHead    = new Font(bfntHead, 16, 1, iTextSharp.text.BaseColor.BLACK);
            Paragraph prgHeading = new Paragraph();

            prgHeading.Alignment = Element.ALIGN_CENTER;
            prgHeading.Add(new Chunk("Reporte diario".ToUpper(), fntHead));
            document.Add(prgHeading);
            Paragraph p = new Paragraph(new Chunk(new iTextSharp.text.pdf.draw.LineSeparator(0.0F, 100.0F, iTextSharp.text.BaseColor.BLACK, Element.ALIGN_LEFT, 1)));

            document.Add(p);
            document.Add(new Chunk("\n", fntHead));


            string [] arreglo = { "Fecha", "Folio", "Cliente", "ESTS.", "Cond. Pago", "Total" };


            //Write the table
            PdfPTable table           = new PdfPTable(new float[] { 2, 2, 4, 2, 2, 2 });
            BaseFont  btnColumnHeader = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);
            Font      fntColumnHeader = new Font(btnColumnHeader, 9, 1, iTextSharp.text.BaseColor.BLACK);

            for (int i = 0; i < arreglo.Count(); i++)
            {
                PdfPCell cell = new PdfPCell();

                cell.HorizontalAlignment = Element.ALIGN_CENTER;
                cell.BorderColor         = WebColors.GetRGBColor("#c4e4ff");
                cell.BackgroundColor     = WebColors.GetRGBColor("#c5d9ea");
                cell.AddElement(new Chunk(arreglo[i], fntColumnHeader));
                table.AddCell(cell);
            }


            //table Data

            BaseFont btnColumnData = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, BaseFont.NOT_EMBEDDED);

            Font fntColumnData = new Font(btnColumnData, 9, 2, iTextSharp.text.BaseColor.BLACK);


            Models.Reports.Tickets diario = new Models.Reports.Tickets();
            using (diario)
            {
                List <Models.Reports.Tickets> dia = diario.get_tickets(dtFecha.Text, dtFecha.Text);
                if (dia.Count > 0)
                {
                    foreach (Models.Reports.Tickets item in dia)
                    {
                        table.AddCell(new PdfPCell(new Phrase(dtFecha.Text, fntColumnData)));
                        table.AddCell(new PdfPCell(new Phrase(item.Folio.ToString(), fntColumnData))
                        {
                            HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT
                        });
                        table.AddCell(new PdfPCell(new Phrase(item.Cliente.ToString(), fntColumnData)));
                        table.AddCell(new PdfPCell(new Phrase(item.Status.ToString(), fntColumnData))
                        {
                            HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT
                        });
                        table.AddCell("");
                        table.AddCell(new PdfPCell(new Phrase(item.Total.ToString(), fntColumnData))
                        {
                            HorizontalAlignment = iTextSharp.text.Element.ALIGN_RIGHT
                        });
                    }
                }
            }
            document.Add(table);
            document.Close();
            writer.Close();
            fs.Close();
        }
        public void GenerarPDF(DataTable dt, string fecha, string hora, string total, string proveedor)
        {
            try
            {
                //instanciamos el documento
                Document     pdfDoc  = new Document(PageSize.A4, 10, 10, 10, 10);
                MemoryStream PDFData = new MemoryStream();
                PdfWriter    writer  = PdfWriter.GetInstance(pdfDoc, PDFData);
                //tipos de fuentes que vamos a utilizar
                var       titleFont     = FontFactory.GetFont("Arial", 12, Font.BOLD);
                var       titleFontBlue = FontFactory.GetFont("Arial", 14, Font.NORMAL, BaseColor.BLUE);
                var       boldTableFont = FontFactory.GetFont("Arial", 8, Font.BOLD);
                var       bodyFont      = FontFactory.GetFont("Arial", 8, Font.NORMAL);
                var       EmailFont     = FontFactory.GetFont("Arial", 8, Font.NORMAL, BaseColor.BLUE);
                BaseColor TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE");

                Rectangle pageSize = writer.PageSize;
                // abrimos el documento para escribir
                pdfDoc.Open();
                //Agregamos los elementos para el documento

                #region Top table
                // creamos la tabla del encabezado
                PdfPTable headertable = new PdfPTable(3);
                headertable.HorizontalAlignment = 0;
                headertable.WidthPercentage     = 100;
                headertable.SetWidths(new float[] { 100f, 320f, 100f });  // Establecemos las dimensiones de las columnas
                headertable.DefaultCell.Border = Rectangle.NO_BORDER;
                //headertable.DefaultCell.Border = Rectangle.BOX; //para probar el codigo

                //colocamos el logo
                iTextSharp.text.Image logo = iTextSharp.text.Image.GetInstance(HttpContext.Current.Server.MapPath("~/ImagenesSistema/logoGym.JPG"));
                logo.ScaleToFit(100, 15);

                {
                    PdfPCell pdfCelllogo = new PdfPCell(logo);
                    pdfCelllogo.Border            = Rectangle.NO_BORDER;
                    pdfCelllogo.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    pdfCelllogo.BorderWidthBottom = 1f;
                    headertable.AddCell(pdfCelllogo);
                }

                {
                    PdfPCell middlecell = new PdfPCell();
                    middlecell.Border            = Rectangle.NO_BORDER;
                    middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    middlecell.BorderWidthBottom = 1f;
                    headertable.AddCell(middlecell);
                }

                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("THE GYM", titleFont));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Salta, Argentina", bodyFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase("Av. Entre Rios 865", bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);
                    PdfPCell nextPostCell4 = new PdfPCell(new Phrase("*****@*****.**", EmailFont));
                    nextPostCell4.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell4);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border            = Rectangle.NO_BORDER;
                    nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan           = 5;
                    nesthousing.PaddingBottom     = 10f;
                    headertable.AddCell(nesthousing);
                }


                PdfPTable Invoicetable = new PdfPTable(3);
                Invoicetable.HorizontalAlignment = 0;
                Invoicetable.WidthPercentage     = 100;
                Invoicetable.SetWidths(new float[] { 100f, 320f, 100f });  // establecemos el ancho de las columnas
                Invoicetable.DefaultCell.Border = Rectangle.NO_BORDER;

                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("PARA:", bodyFont));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase(proveedor, titleFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase("", bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);
                    PdfPCell nextPostCell4 = new PdfPCell(new Phrase("", EmailFont));
                    nextPostCell4.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell4);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border = Rectangle.NO_BORDER;
                    //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan       = 5;
                    nesthousing.PaddingBottom = 10f;
                    Invoicetable.AddCell(nesthousing);
                }

                {
                    PdfPCell middlecell = new PdfPCell();
                    middlecell.Border = Rectangle.NO_BORDER;
                    //middlecell.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //middlecell.BorderWidthBottom = 1f;
                    Invoicetable.AddCell(middlecell);
                }


                {
                    PdfPTable nested = new PdfPTable(1);
                    nested.DefaultCell.Border = Rectangle.NO_BORDER;
                    PdfPCell nextPostCell1 = new PdfPCell(new Phrase("ORDEN DE COMPRA", titleFontBlue));
                    nextPostCell1.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell1);
                    PdfPCell nextPostCell2 = new PdfPCell(new Phrase("Fecha: " + DateTime.Now.ToShortDateString(), bodyFont));
                    nextPostCell2.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell2);
                    PdfPCell nextPostCell3 = new PdfPCell(new Phrase(" " + fecha, bodyFont));
                    nextPostCell3.Border = Rectangle.NO_BORDER;
                    nested.AddCell(nextPostCell3);
                    nested.AddCell("");
                    PdfPCell nesthousing = new PdfPCell(nested);
                    nesthousing.Border = Rectangle.NO_BORDER;
                    //nesthousing.BorderColorBottom = new BaseColor(System.Drawing.Color.Black);
                    //nesthousing.BorderWidthBottom = 1f;
                    nesthousing.Rowspan       = 5;
                    nesthousing.PaddingBottom = 10f;
                    Invoicetable.AddCell(nesthousing);
                }


                pdfDoc.Add(headertable);
                Invoicetable.PaddingTop = 10f;

                pdfDoc.Add(Invoicetable);
                #endregion

                #region Items Table
                //Create body table
                PdfPTable itemTable = new PdfPTable(2);

                itemTable.HorizontalAlignment = 0;
                itemTable.WidthPercentage     = 100;
                itemTable.SetWidths(new float[] { 40, 10 });  // then set the column's __relative__ widths
                itemTable.SpacingAfter       = 40;
                itemTable.DefaultCell.Border = Rectangle.BOX;
                PdfPCell cell1 = new PdfPCell(new Phrase("Producto", boldTableFont));
                cell1.BackgroundColor     = TabelHeaderBackGroundColor;
                cell1.HorizontalAlignment = Element.ALIGN_CENTER;
                itemTable.AddCell(cell1);
                PdfPCell cell2 = new PdfPCell(new Phrase("Cantidad", boldTableFont));
                cell2.BackgroundColor     = TabelHeaderBackGroundColor;
                cell2.HorizontalAlignment = 1;
                itemTable.AddCell(cell2);
                foreach (DataRow row in dt.Rows)
                {
                    //instanciamos variables para los elementos del datatable
                    string productonombre   = row[1].ToString();
                    string cantidadproducto = row[0].ToString();
                    //insertamos en la tabla el nombre
                    PdfPCell numberCell = new PdfPCell(new Phrase(productonombre, bodyFont));
                    numberCell.HorizontalAlignment = 1;
                    numberCell.PaddingLeft         = 10f;
                    numberCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(numberCell);
                    //insertamos en la tabla la cantidad
                    var _phrase = new Phrase();
                    _phrase.Add(new Chunk(cantidadproducto, EmailFont));
                    PdfPCell descCell = new PdfPCell(_phrase);
                    descCell.HorizontalAlignment = 0;
                    descCell.PaddingLeft         = 10f;
                    descCell.Border = Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER;
                    itemTable.AddCell(descCell);
                }
                //pie de tabla
                PdfPCell totalAmtCell1 = new PdfPCell(new Phrase(""));
                totalAmtCell1.Border = Rectangle.LEFT_BORDER | Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell1);
                PdfPCell totalAmtCell2 = new PdfPCell(new Phrase(""));
                totalAmtCell2.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                itemTable.AddCell(totalAmtCell2);
                //PdfPCell totalAmtCell3 = new PdfPCell(new Phrase(""));
                //totalAmtCell3.Border = Rectangle.TOP_BORDER; //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                //itemTable.AddCell(totalAmtCell3);
                //PdfPCell totalAmtStrCell = new PdfPCell(new Phrase("Total", boldTableFont));
                //totalAmtStrCell.Border = Rectangle.TOP_BORDER;   //Rectangle.NO_BORDER; //Rectangle.TOP_BORDER;
                //totalAmtStrCell.HorizontalAlignment = 1;
                //itemTable.AddCell(totalAmtStrCell);
                //PdfPCell totalAmtCell = new PdfPCell(new Phrase("TOTAL", boldTableFont));
                //totalAmtCell.HorizontalAlignment = 1;
                //itemTable.AddCell(totalAmtCell);

                PdfPCell cell = new PdfPCell(new Phrase("***NOTA: Se acepta hasta un cargo del 0.5% en el periodo de 30 days. ***", bodyFont));
                cell.Colspan             = 5;
                cell.HorizontalAlignment = 1;
                itemTable.AddCell(cell);
                pdfDoc.Add(itemTable);
                #endregion

                PdfContentByte cb = new PdfContentByte(writer);


                BaseFont bf = BaseFont.CreateFont(BaseFont.HELVETICA, BaseFont.CP1250, true);
                cb = new PdfContentByte(writer);
                cb = writer.DirectContent;
                cb.BeginText();
                cb.SetFontAndSize(bf, 8);
                cb.SetTextMatrix(pageSize.GetLeft(120), 20);
                cb.ShowText("Esta factura es válida como comprobante de solicitud de reposición");
                cb.EndText();

                //Movemos el puntero y dibujamos una linea para separa el resto del documento del footer
                cb.MoveTo(40, pdfDoc.PageSize.GetBottom(50));
                cb.LineTo(pdfDoc.PageSize.Width - 40, pdfDoc.PageSize.GetBottom(50));
                cb.Stroke();

                //cerramos el PDF
                pdfDoc.Close();
                DownloadPDF(PDFData);
            }
            catch (Exception ex)
            {
                lblerrorPDF.Text = ex.Message.ToString();
            }
        }
Пример #26
0
        private string CrearReporte(DataTable Data, string GuiaEmpresarial, int cantidadLineamientos, string anexo)
        {
            string rutaDescarga  = WebConfigurationManager.AppSettings["RutaDescargaArchivos"].ToString();
            string ImagenReporte = WebConfigurationManager.AppSettings["ImagenReporte"].ToString();

            string rutaCompleta = rutaDescarga + GuiaEmpresarial.Replace(" ", "_") + "_" + DateTime.Now.ToString("yyyyMMdd-HHmmssfff") + ".pdf";

            int cantidadColumnas = Data.Columns.Count;
            List <SelectListItem> cabeceraReporte = cabecera(Data);

            Document doc = new Document(PageSize.A4.Rotate());

            PdfWriter writer = PdfWriter.GetInstance(doc, new FileStream(rutaCompleta, FileMode.Create));

            doc.AddTitle(GuiaEmpresarial);
            doc.AddCreator("GMD");
            doc.Open();
            writer.PageEvent = new PDFFooter();

            iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(ImagenReporte);
            jpg.ScaleToFit(110f, 140f);
            //jpg.SetAbsolutePosition(55f, 800f);

            doc.Add(jpg);

            //Definimos Colores
            BaseColor _BackgroundCabecera       = WebColors.GetRGBColor("#fafad2");
            BaseColor _BorderColor              = WebColors.GetRGBColor("#C0C0C0");
            Font      _FontColorCabecera        = new iTextSharp.text.Font(iTextSharp.text.Font.FontFamily.HELVETICA, 5.5f, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            Font      _FontColorTituloPrincipal = FontFactory.GetFont("HELVETICA", 9.3f, iTextSharp.text.Font.BOLD, BaseColor.BLACK);
            Font      _FontColorDetalle         = new Font(iTextSharp.text.Font.FontFamily.HELVETICA, 4.3f, iTextSharp.text.Font.NORMAL, BaseColor.BLACK);

            // Titulo del documento
            Paragraph titulo = new Paragraph();

            titulo.Add(new Phrase(anexo, _FontColorTituloPrincipal));
            titulo.Add(new Phrase("\n" + GuiaEmpresarial.Replace("_", " ") + "\n", _FontColorTituloPrincipal));
            //PdfPCell col_2 = new PdfPCell(titulo);
            //Paragraph titulo = new Paragraph(0, GuiaEmpresarial.Replace("_", " ") + "\n\n", _FontColorTituloPrincipal);

            titulo.Alignment        = Element.ALIGN_CENTER;
            titulo.SpacingBefore    = 16f;
            titulo.SpacingAfter     = 4f;
            titulo.IndentationRight = 14f;
            doc.Add(titulo);

            PdfPTable tblPrincipal = new PdfPTable(1);

            tblPrincipal.WidthPercentage     = 100f;
            tblPrincipal.HorizontalAlignment = Element.ALIGN_CENTER;
            tblPrincipal.SplitLate           = false;

            PdfPCell tblCabecera = new PdfPCell();

            tblCabecera.BorderWidth               = 0f;
            tblCabecera.PaddingTop                = 0f;
            tblCabecera.Table                     = new PdfPTable(cantidadColumnas);
            tblCabecera.Table.WidthPercentage     = 100;
            tblCabecera.Table.HorizontalAlignment = Element.ALIGN_LEFT;

            PdfPCell tblDetalle = new PdfPCell();

            tblDetalle.BorderWidth               = 0f;
            tblDetalle.PaddingTop                = 0f;
            tblDetalle.Table                     = new PdfPTable(cantidadColumnas);
            tblDetalle.Table.WidthPercentage     = 100;
            tblDetalle.Table.HorizontalAlignment = Element.ALIGN_CENTER;

            int cont = 0;

            foreach (SelectListItem item in cabeceraReporte)
            {
                Paragraph TituloCabecera = new Paragraph();
                TituloCabecera.Add(new Phrase(item.Text, _FontColorCabecera));
                PdfPCell cabecera = new PdfPCell(TituloCabecera);
                cabecera.BorderWidth         = 0.5f;
                cabecera.BackgroundColor     = _BackgroundCabecera;
                cabecera.HorizontalAlignment = Element.ALIGN_CENTER;
                cabecera.VerticalAlignment   = Element.ALIGN_MIDDLE;
                cabecera.BorderColor         = BaseColor.BLACK;
                cabecera.PaddingBottom       = 4;
                cabecera.Rowspan             = item.Value.ToString() == "" ? 2 : 1;
                cabecera.Colspan             = item.Value.ToString() != "" ? (item.Text == "Metas" ? 5 : 2) : 1;

                string valorAnterior = cont > 0 ? cabeceraReporte[cont - 1].Text : "";
                if ((cabecera.Colspan > 1 && valorAnterior != item.Text) || cabecera.Rowspan > 1)
                {
                    tblCabecera.Table.AddCell(cabecera);
                }

                cont++;
            }

            foreach (SelectListItem item in cabeceraReporte)
            {
                if (item.Value != "")
                {
                    Paragraph TituloCabecera = new Paragraph();
                    TituloCabecera.Add(new Phrase(item.Value, _FontColorCabecera));
                    PdfPCell cabecera = new PdfPCell(TituloCabecera);
                    cabecera.BorderWidth         = 0.5f;
                    cabecera.BackgroundColor     = _BackgroundCabecera;
                    cabecera.HorizontalAlignment = Element.ALIGN_CENTER;
                    cabecera.VerticalAlignment   = Element.ALIGN_CENTER;
                    cabecera.BorderColor         = BaseColor.BLACK;
                    cabecera.PaddingBottom       = 4;

                    tblCabecera.Table.AddCell(cabecera);
                }
            }


            string alineamientoAnterior = "";
            string alineamientoActual   = "";
            int    filasRowSpan         = 1;

            cont = 0;
            int cantidadC = 0;

            foreach (DataRow itemDetalle in Data.Rows)
            {
                if (cont == 0)
                {
                    for (int i = 0; i < cantidadColumnas; i++)
                    {
                        filasRowSpan = 1;
                        string valorAnterior = "", valorActual = "";

                        if (i < cantidadLineamientos)
                        {
                            foreach (DataRow item in Data.Rows)
                            {
                                if (item[i].ToString() == "")
                                {
                                    break;
                                }

                                valorActual = i > 0 ? item[i - 1].ToString() + item[i].ToString() : item[i].ToString();

                                if (filasRowSpan == 1)
                                {
                                    valorAnterior = valorActual;
                                }
                                else if (valorAnterior != valorActual)
                                {
                                    break;
                                }

                                filasRowSpan++;
                            }
                        }

                        PdfPCell detalle = new PdfPCell(new Phrase(itemDetalle[i].ToString().Replace(";", "\n"), _FontColorDetalle));
                        detalle.BorderWidth         = 0.1f;
                        detalle.BorderColor         = _BorderColor;
                        detalle.HorizontalAlignment = Element.ALIGN_CENTER;
                        detalle.VerticalAlignment   = Element.ALIGN_MIDDLE;
                        detalle.PaddingTop          = 0.5f;
                        detalle.PaddingBottom       = 2f;
                        detalle.PaddingLeft         = 2f;
                        detalle.Rowspan             = filasRowSpan - 1;

                        tblDetalle.Table.AddCell(detalle);
                    }
                }
                else
                {
                    for (int i = 0; i < cantidadColumnas; i++)
                    {
                        alineamientoAnterior = i > 0 ? Data.Rows[cont - 1][i - 1].ToString() + "-" + Data.Rows[cont - 1][i].ToString() : Data.Rows[cont - 1][i].ToString();
                        alineamientoActual   = i > 0 ? itemDetalle[i - 1].ToString() + "-" + itemDetalle[i].ToString() : itemDetalle[i].ToString();

                        filasRowSpan = 1;
                        string valorAnterior = "", valorActual = "";

                        if (itemDetalle[i].ToString() == "" || i >= cantidadLineamientos)
                        {
                            PdfPCell detalle = new PdfPCell(new Phrase(itemDetalle[i].ToString().Replace(";", "\n"), _FontColorDetalle));
                            detalle.BorderWidth         = 0.1f;
                            detalle.BorderColor         = _BorderColor;
                            detalle.HorizontalAlignment = Element.ALIGN_CENTER;
                            detalle.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            detalle.PaddingTop          = 0.5f;
                            detalle.PaddingBottom       = 2f;
                            detalle.PaddingLeft         = 2f;
                            detalle.Rowspan             = filasRowSpan;

                            tblDetalle.Table.AddCell(detalle);
                        }
                        else if ((alineamientoAnterior != alineamientoActual) || i == cantidadColumnas - 1)
                        {
                            int contador = 0;
                            if (i < cantidadLineamientos)
                            {
                                foreach (DataRow item in Data.Rows)
                                {
                                    if (contador >= cont)
                                    {
                                        if (item[i].ToString() == "")
                                        {
                                            break;
                                        }

                                        valorActual = i > 0 ? item[i - 1].ToString() + item[i].ToString() : item[i].ToString();

                                        if (filasRowSpan == 1)
                                        {
                                            valorAnterior = valorActual;
                                        }
                                        else if (valorAnterior != valorActual)
                                        {
                                            break;
                                        }

                                        filasRowSpan++;
                                    }

                                    contador++;
                                }
                            }

                            PdfPCell detalle = new PdfPCell(new Phrase(itemDetalle[i].ToString().Replace(";", "\n"), _FontColorDetalle));
                            detalle.BorderWidth         = 0.1f;
                            detalle.BorderColor         = _BorderColor;
                            detalle.HorizontalAlignment = Element.ALIGN_CENTER;
                            detalle.VerticalAlignment   = Element.ALIGN_MIDDLE;
                            detalle.PaddingTop          = 0.5f;
                            detalle.PaddingBottom       = 2f;
                            detalle.PaddingLeft         = 2f;
                            detalle.Rowspan             = filasRowSpan - 1;

                            tblDetalle.Table.AddCell(detalle);
                        }
                    }
                }

                cont++;
            }

            tblPrincipal.AddCell(tblCabecera);
            tblPrincipal.AddCell(tblDetalle);
            doc.Add(tblPrincipal);
            doc.Close();
            writer.Close();

            return(rutaCompleta);
        }
Пример #27
0
 public virtual void TestGetRGBColorInPercentBlue()
 {
     Assert.AreEqual(127, WebColors.GetRGBColor(RGB_PERCENT).B);
 }
Пример #28
0
 public virtual void TestGetRGBColorInPercentAlpha()
 {
     Assert.AreEqual(255, WebColors.GetRGBColor(RGB_PERCENT).A);
 }
Пример #29
0
        public override IList <IElement> Start(IWorkerContext ctx, Tag tag)
        {
            IList <IElement> result;
            LineSeparator    lineSeparator;
            var cssUtil = CssUtils.GetInstance();

            try
            {
                IList <IElement>    list = new List <IElement>();
                HtmlPipelineContext htmlPipelineContext = this.GetHtmlPipelineContext(ctx);

                Paragraph paragraph = new Paragraph();
                IDictionary <string, string> css = tag.CSS;
                float baseValue = 12f;
                if (css.ContainsKey("font-size"))
                {
                    baseValue = cssUtil.ParsePxInCmMmPcToPt(css["font-size"]);
                }
                string text;
                css.TryGetValue("margin-top", out text);
                if (text == null)
                {
                    text = "0.5em";
                }

                string text2;
                css.TryGetValue("margin-bottom", out text2);
                if (text2 == null)
                {
                    text2 = "0.5em";
                }

                string border;
                css.TryGetValue(CSS.Property.BORDER_BOTTOM_STYLE, out border);
                lineSeparator = border != null && border == "dotted"
                    ? new DottedLineSeparator()
                    : new LineSeparator();

                var element = (LineSeparator)this.GetCssAppliers().Apply(
                    lineSeparator, tag, htmlPipelineContext
                    );

                string color;
                css.TryGetValue(CSS.Property.BORDER_BOTTOM_COLOR, out color);
                if (color != null)
                {
                    // WebColors deprecated, but docs don't state replacement
                    element.LineColor = WebColors.GetRGBColor(color);
                }

                paragraph.SpacingBefore += cssUtil.ParseValueToPt(text, baseValue);
                paragraph.SpacingAfter  += cssUtil.ParseValueToPt(text2, baseValue);
                paragraph.Leading        = 0f;
                paragraph.Add(element);
                list.Add(paragraph);
                result = list;
            }
            catch (NoCustomContextException cause)
            {
                throw new RuntimeWorkerException(
                          LocaleMessages.GetInstance().GetMessage("customcontext.404"),
                          cause
                          );
            }
            return(result);
        }
    protected void btnDownload_Click(object sender, EventArgs e)
    {
        string finalResult = string.Empty;



        Button button = (sender as Button);
        //Get the command argument
        Int64   PurchaseOrderId = Convert.ToInt64(button.CommandArgument.ToString());
        DataSet ds = new DataSet();

        SqlCommand cmd = new SqlCommand();

        cmd.CommandText = "PurchaseOrderHeader_SelectById";
        cmd.Parameters.AddWithValue("@id", PurchaseOrderId);
        //cmd.Parameters.AddWithValue("@password", password);
        cmd.CommandType = CommandType.StoredProcedure;
        SqlDataAdapter sda = new SqlDataAdapter();

        cmd.Connection    = con;
        sda.SelectCommand = cmd;



        //SqlDataAdapter da = new SqlDataAdapter(query, con);
        sda.Fill(ds);
        String       po      = ds.Tables[0].Rows[0]["PONo"].ToString();
        Document     pdfDoc  = new Document(PageSize.A4, 10, 10, 10, 10);
        MemoryStream PDFData = new MemoryStream();
        //PdfWriter pw = PdfWriter.GetInstance(
        //PdfWriter writer = PdfWriter.GetInstance(pdfDoc, new FileStream(Context.Server.MapPath("~/uploads/PurchaseOrders/") + po + ".pdf", FileMode.Create));
        PdfWriter writer = PdfWriter.GetInstance(pdfDoc, PDFData);

        var titleFont      = FontFactory.GetFont("Arial", 6, Font.NORMAL);
        var titleFontBlue  = FontFactory.GetFont("Arial", 14, Font.NORMAL, Color.BLUE);
        var boldTableFont  = FontFactory.GetFont("Arial", 8, Font.BOLD);              //8
        var boldTableFont1 = FontFactory.GetFont("Arial", 8, Font.BOLD);              //8
        var bodyFont       = FontFactory.GetFont("Arial", 7, Font.NORMAL);            //8
        var EmailFont      = FontFactory.GetFont("Arial", 8, Font.BOLD, Color.BLACK); //8
        var HeaderFont     = FontFactory.GetFont("Arial", 10, Font.BOLD, Color.BLACK);

        var   footerfont = FontFactory.GetFont("Arial", 6, Font.NORMAL, Color.BLACK);//8
        Color TabelHeaderBackGroundColor = WebColors.GetRGBColor("#EEEEEE");

        Rectangle pageSize = writer.PageSize;

        // Open the Document for writing
        pdfDoc.Open();
        //Add elements to the document here

        #region Top table
        // Create the header table
        PdfPTable headertable = new PdfPTable(3);
        headertable.HorizontalAlignment = 0;
        headertable.WidthPercentage     = 100;
        headertable.SetWidths(new float[] { 100f, 320f, 220f }); // then set the column's __relative__ widths
        headertable.DefaultCell.Border = Rectangle.NO_BORDER;
        headertable.DefaultCell.Border = Rectangle.BOX;          //for testing



        // invoice rperte

        PdfPTable Invoicetable2 = new PdfPTable(1);
        Invoicetable2.HorizontalAlignment = 0;
        Invoicetable2.WidthPercentage     = 100;
        Invoicetable2.SetWidths(new float[] { 500f });  // then set the column's __relative__ widths
        Invoicetable2.DefaultCell.Border = Rectangle.NO_BORDER;

        {
            PdfPTable mainN = new PdfPTable(1);
            // tablenew.HorizontalAlignment = 1;
            //PdfPCell cellnew = new PdfPCell(new Phrase("PURCHASE ORDER"),EmailFont);
            //    PdfPCell cellN = new PdfPCell(new Phrase("Trimurti Diagnostics \n\n Home/Clinic Collection No : 7777 8866 04/05, 9766 6600 83 | 0253 2376062 "
            //+ "\n\n28, Purab Paschim Plaza, Divya Adlabs Building, Trimurti Chowk, CIDCO, Nashik - 422008", HeaderFont)); ;
            PdfPCell cellN = new PdfPCell(new Phrase("Morya Tools \n\n 22, Pradhan Park, M.G Road, Nashik, Maharashtra, India 422001 "
                                                     + "\n\nPhone: (0253) 3014578 Email: [email protected]", HeaderFont));
            cellN.PaddingTop        = 15f;
            cellN.PaddingBottom     = 15f;
            cellN.VerticalAlignment = 1;
            //cellnew.Colspan = 2;
            cellN.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
            mainN.AddCell(cellN);
            PdfPCell nesthousingnn = new PdfPCell(mainN);

            PdfPTable tablenew = new PdfPTable(1);
            // tablenew.HorizontalAlignment = 1;
            //PdfPCell cellnew = new PdfPCell(new Phrase("PURCHASE ORDER"),EmailFont);
            PdfPCell cellnew = new PdfPCell(new Phrase("PURCHASE ORDER", EmailFont));
            cellnew.PaddingTop        = 15f;
            cellnew.PaddingBottom     = 15f;
            cellnew.VerticalAlignment = 1;
            //cellnew.Colspan = 2;
            cellnew.HorizontalAlignment = 1; //0=Left, 1=Centre, 2=Right
            tablenew.AddCell(cellnew);
            PdfPCell nesthousingn = new PdfPCell(tablenew);



            PdfPTable tablenew1 = new PdfPTable(2);

            // tablenew1.DefaultCell.FixedHeight = 100f;
            PdfPCell cellnew4 = new PdfPCell(new Phrase("PO No :    " + ds.Tables[0].Rows[0]["PONo"].ToString(), EmailFont));
            cellnew4.FixedHeight         = 30f;
            cellnew4.HorizontalAlignment = 1;
            cellnew4.PaddingTop          = 15f;
            cellnew4.PaddingBottom       = 15f;
            PdfPCell cellnew5 = new PdfPCell(new Phrase("PO Date :  " + ds.Tables[0].Rows[0]["OrderDate1"].ToString(), EmailFont));
            cellnew5.HorizontalAlignment = 1;
            cellnew5.PaddingTop          = 15f;
            cellnew5.PaddingBottom       = 15f;

            tablenew1.AddCell(cellnew4);

            tablenew1.AddCell(cellnew5);



            PdfPTable tablevendor = new PdfPTable(2);

            PdfPCell suppliername = new PdfPCell(new Phrase("VENDOR NAME :    " + ds.Tables[0].Rows[0]["vendorName"].ToString(), EmailFont));
            suppliername.MinimumHeight = 80f;
            suppliername.PaddingTop    = 10f;
            PdfPCell supplierdetails = new PdfPCell(new Phrase("VENDOR DETAILS:  \n\n\t Contact Person : " + ds.Tables[0].Rows[0]["vendorName"].ToString() + "\n\n\t Mobile No : " + ds.Tables[0].Rows[0]["MobileNo1"].ToString() + "\n\n\t Email : " + ds.Tables[0].Rows[0]["email"].ToString(), EmailFont));
            supplierdetails.PaddingTop = 10f;
            // PdfPCell termsnconditions = new PdfPCell(new Phrase("Terms & Conditions:    ", EmailFont));

            tablevendor.AddCell(suppliername);
            tablevendor.AddCell(supplierdetails);
            //tablevendor.AddCell(termsnconditions);



            PdfPCell nesthousingn1 = new PdfPCell(tablenew1);
            PdfPCell nesthousingn2 = new PdfPCell(tablevendor);
            // nesthousingn2.Height = 10f;
            //PdfPCell nesthousingn3 = new PdfPCell(tablenew3);


            nesthousingn.Border = Rectangle.NO_BORDER;

            //nesthousingn.PaddingBottom = 10f;
            Invoicetable2.AddCell(nesthousingnn);
            Invoicetable2.AddCell(nesthousingn);
            Invoicetable2.AddCell(nesthousingn1);
            Invoicetable2.AddCell(nesthousingn2);
            //Invoicetable2.AddCell(nesthousingn3);
        }
        //invoice repeat

        // Invoicetable2.AddCell(headertable);
        Invoicetable2.SpacingBefore = 3f;
        //  Invoicetable. = 10f;

        // pdfDoc.Add(Invoicetable);



        #endregion

        #region Items Table
        //Create body table
        PdfPTable itemTable = new PdfPTable(3);

        itemTable.HorizontalAlignment = 0;
        itemTable.WidthPercentage     = 100;
        // itemTable.SetWidths(new float[] { });  // then set the column's __relative__ widths
        //itemTable.SetWidths(new float[] { 4, 30, 6, 6, 6 });
        itemTable.SpacingAfter = 10;

        //itemTable.DefaultCell.Border = Rectangle.BOX;



        PdfPCell cell1 = new PdfPCell(new Phrase("PRODUCT", boldTableFont));
        //cell1.BackgroundColor = TabelHeaderBackGroundColor;
        cell1.HorizontalAlignment = Element.ALIGN_CENTER;
        itemTable.AddCell(cell1);

        PdfPCell cell2 = new PdfPCell(new Phrase("IMAGE", boldTableFont));
        //cell2.BackgroundColor = TabelHeaderBackGroundColor;
        cell2.HorizontalAlignment = 1;
        itemTable.AddCell(cell2);

        /*
         * PdfPCell cell2 = new PdfPCell(new Phrase("BRAND", boldTableFont));
         * //cell2.BackgroundColor = TabelHeaderBackGroundColor;
         * cell2.HorizontalAlignment = 1;
         * itemTable.AddCell(cell2);
         *
         *
         *
         * PdfPCell cell3 = new PdfPCell(new Phrase("SIZE", boldTableFont));
         * //cell4.BackgroundColor = TabelHeaderBackGroundColor;
         * cell3.HorizontalAlignment = 1;
         * itemTable.AddCell(cell3);
         */

        PdfPCell cell4 = new PdfPCell(new Phrase("QUANTITY", boldTableFont));
        //cell5.BackgroundColor = TabelHeaderBackGroundColor;
        cell4.HorizontalAlignment = 1;
        itemTable.AddCell(cell4);


        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            PdfPCell cell1i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["ProdName"].ToString(), bodyFont));
            //cell1.BackgroundColor = TabelHeaderBackGroundColor;
            cell1i.HorizontalAlignment = Element.ALIGN_CENTER;
            itemTable.AddCell(cell1i);


            if (!String.IsNullOrEmpty(ds.Tables[0].Rows[i]["imagename"].ToString()))
            {
                iTextSharp.text.Image myImage = iTextSharp.text.Image.GetInstance(Server.MapPath("uploads/product/" + ds.Tables[0].Rows[i]["imagename"].ToString()));
                myImage.ScaleAbsolute(20f, 20f);
                PdfPCell cell2i = new PdfPCell(myImage);
                //cell2.BackgroundColor = TabelHeaderBackGroundColor;
                cell2i.HorizontalAlignment = 1;
                itemTable.AddCell(cell2i);
            }
            else
            {
                iTextSharp.text.Image myImage = iTextSharp.text.Image.GetInstance(Server.MapPath("uploads/ImageNotFound.png"));
                myImage.ScaleAbsolute(20f, 20f);
                PdfPCell cell2i = new PdfPCell(myImage);
                //cell2.BackgroundColor = TabelHeaderBackGroundColor;
                cell2i.HorizontalAlignment = 1;
                itemTable.AddCell(cell2i);
            }

            /*
             * PdfPCell cell2i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["Brand"].ToString(), bodyFont));
             * //cell2.BackgroundColor = TabelHeaderBackGroundColor;
             * cell2i.HorizontalAlignment = 1;
             * itemTable.AddCell(cell2i);
             *
             *
             *
             * PdfPCell cell4i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["Size"].ToString(), bodyFont));
             * //cell4.BackgroundColor = TabelHeaderBackGroundColor;
             * cell4i.HorizontalAlignment = 1;
             * itemTable.AddCell(cell4i);
             */

            PdfPCell cell5i = new PdfPCell(new Phrase(ds.Tables[0].Rows[i]["Quantity1"].ToString(), bodyFont));
            //cell5.BackgroundColor = TabelHeaderBackGroundColor;
            cell5i.HorizontalAlignment = 1;
            itemTable.AddCell(cell5i);

            //    PdfPCell cell3i = new PdfPCell(new Phrase("" + dtOrderProducts.Rows[i]["Amount"], bodyFont));
            //    //cell3.BackgroundColor = TabelHeaderBackGroundColor;
            //    cell3i.HorizontalAlignment = 1;
            //    itemTable.AddCell(cell3i);
        }



        PdfPCell nesthousingn3 = new PdfPCell(itemTable);
        //  PdfPCell nesthousingn4 = new PdfPCell(totalTable);


        //nesthousingn.Border = Rectangle.NO_BORDER;

        //nesthousingn.PaddingBottom = 10f;
        Invoicetable2.AddCell(nesthousingn3);
        // Invoicetable2.AddCell(nesthousingn4);
        // pdfDoc.Add(Invoicetable2);
        #endregion



        PdfPTable noTable1 = new PdfPTable(2);

        noTable1.HorizontalAlignment = 0;
        noTable1.WidthPercentage     = 100;
        // itemTable.SetWidths(new float[] {2,30,6,6,6,6,6,6,6,6,6,4,4,7 });  // then set the column's __relative__ widths
        //amtTable.SetWidths(new float[] { 4, 30});
        // amtTable.SpacingAfter = 10;

        noTable1.DefaultCell.Border = 0;


        PdfPCell cellnote1 = new PdfPCell(new Phrase("PREPARED BY\nNAME : " + "\nSIGNATURE : " + "\nDATE & TIME : ", EmailFont));
        cellnote1.Border = 0;
        cellnote1.HorizontalAlignment = 0;//0=Left, 1=Centre, 2=Right


        noTable1.AddCell(cellnote1);



        PdfPCell cellnote3 = new PdfPCell(new Phrase("FOR MORYA TOOLS\n\n\n\nAUTHORIZED SIGNATORY", EmailFont));
        cellnote3.Border = 0;
        cellnote3.HorizontalAlignment = 2;//0=Left, 1=Centre, 2=Right


        noTable1.AddCell(cellnote3);



        PdfPCell nesthousingn5 = new PdfPCell(noTable1);
        Invoicetable2.AddCell(nesthousingn5);



        pdfDoc.Add(Invoicetable2);
        pdfDoc.Close();



        DownloadPDF(PDFData, po);



        Context.Response.Clear();
        Context.Response.ContentType = "application/json";
        Context.Response.Flush();
        Context.Response.Write(finalResult);
        Context.Response.End();
    }