Inheritance: ExtendedColor
Example #1
0
        internal PdfArray getMKColor(Color color)
        {
            PdfArray array = new PdfArray();
            int      type  = ExtendedColor.getType(color);

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY: {
                array.Add(new PdfNumber(((GrayColor)color).Gray));
                break;
            }

            case ExtendedColor.TYPE_CMYK: {
                CMYKColor cmyk = (CMYKColor)color;
                array.Add(new PdfNumber(cmyk.Cyan));
                array.Add(new PdfNumber(cmyk.Magenta));
                array.Add(new PdfNumber(cmyk.Yellow));
                array.Add(new PdfNumber(cmyk.Black));
                break;
            }

            case ExtendedColor.TYPE_SEPARATION:
            case ExtendedColor.TYPE_PATTERN:
            case ExtendedColor.TYPE_SHADING:
                throw new RuntimeException("Separations, patterns and shadings are not allowed in MK dictionary.");

            default:
                array.Add(new PdfNumber(color.R / 255f));
                array.Add(new PdfNumber(color.G / 255f));
                array.Add(new PdfNumber(color.B / 255f));
                break;
            }
            return(array);
        }
Example #2
0
        public static PdfArray GetMKColor(BaseColor color)
        {
            PdfArray array = new PdfArray();
            int      type  = ExtendedColor.GetType(color);

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY: {
                array.Add(new PdfNumber(((GrayColor)color).Gray));
                break;
            }

            case ExtendedColor.TYPE_CMYK: {
                CMYKColor cmyk = (CMYKColor)color;
                array.Add(new PdfNumber(cmyk.Cyan));
                array.Add(new PdfNumber(cmyk.Magenta));
                array.Add(new PdfNumber(cmyk.Yellow));
                array.Add(new PdfNumber(cmyk.Black));
                break;
            }

            case ExtendedColor.TYPE_SEPARATION:
            case ExtendedColor.TYPE_PATTERN:
            case ExtendedColor.TYPE_SHADING:
                throw new Exception(MessageLocalization.GetComposedMessage("separations.patterns.and.shadings.are.not.allowed.in.mk.dictionary"));

            default:
                array.Add(new PdfNumber(color.R / 255f));
                array.Add(new PdfNumber(color.G / 255f));
                array.Add(new PdfNumber(color.B / 255f));
                break;
            }
            return(array);
        }
Example #3
0
        public static float[] GetColorArray(BaseColor color)
        {
            int type = ExtendedColor.GetType(color);

            switch (type)
            {
            case ExtendedColor.TYPE_GRAY: {
                return(new float[] { ((GrayColor)color).Gray });
            }

            case ExtendedColor.TYPE_CMYK: {
                CMYKColor cmyk = (CMYKColor)color;
                return(new float[] { cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black });
            }

            case ExtendedColor.TYPE_SEPARATION: {
                return(new float[] { ((SpotColor)color).Tint });
            }

            case ExtendedColor.TYPE_RGB: {
                return(new float[] { color.R / 255f, color.G / 255f, color.B / 255f });
            }
            }
            ThrowColorSpaceError();
            return(null);
        }
 protected internal PdfObject GetSpotObject(PdfWriter writer) {
     PdfArray array = new PdfArray(PdfName.SEPARATION);
     array.Add(name);
     PdfFunction func = null;
     if (altcs is ExtendedColor) {
         int type = ((ExtendedColor)altcs).Type;
         switch (type) {
             case ExtendedColor.TYPE_GRAY:
                 array.Add(PdfName.DEVICEGRAY);
                 func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0}, new float[]{((GrayColor)altcs).Gray}, 1);
                 break;
             case ExtendedColor.TYPE_CMYK:
                 array.Add(PdfName.DEVICECMYK);
                 CMYKColor cmyk = (CMYKColor)altcs;
                 func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{0, 0, 0, 0},
                     new float[]{cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black}, 1);
                 break;
             default:
                 throw new Exception("Only RGB, Gray and CMYK are supported as alternative color spaces.");
         }
     }
     else {
         array.Add(PdfName.DEVICERGB);
         func = PdfFunction.Type2(writer, new float[]{0, 1}, null, new float[]{1, 1, 1},
             new float[]{(float)altcs.R / 255, (float)altcs.G / 255, (float)altcs.B / 255}, 1);
     }
     array.Add(func.Reference);
     return array;
 }
Example #5
0
        public override bool Equals(Object obj)
        {
            if (!(obj is CMYKColor))
            {
                return(false);
            }
            CMYKColor c2 = (CMYKColor)obj;

            return(ccyan == c2.ccyan && cmagenta == c2.cmagenta && cyellow == c2.cyellow && cblack == c2.cblack);
        }
        public virtual PdfObject GetPdfObject(PdfWriter writer)
        {
            PdfArray array = new PdfArray(PdfName.SEPARATION);

            array.Add(name);
            PdfFunction func = null;

            if (altcs is ExtendedColor)
            {
                int type = ((ExtendedColor)altcs).Type;
                switch (type)
                {
                case ExtendedColor.TYPE_GRAY:
                    array.Add(PdfName.DEVICEGRAY);
                    func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 1 },
                                             new float[] { ((GrayColor)altcs).Gray }, 1);
                    break;

                case ExtendedColor.TYPE_CMYK:
                    array.Add(PdfName.DEVICECMYK);
                    CMYKColor cmyk = (CMYKColor)altcs;
                    func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 0, 0, 0, 0 },
                                             new float[] { cmyk.Cyan, cmyk.Magenta, cmyk.Yellow, cmyk.Black }, 1);
                    break;

                case ExtendedColor.TYPE_LAB:
                    LabColor lab = (LabColor)altcs;
                    if (altColorDetails != null)
                    {
                        array.Add(altColorDetails.IndirectReference);
                    }
                    else
                    {
                        array.Add(lab.LabColorSpace.GetPdfObject(writer));
                    }
                    func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 100f, 0f, 0f },
                                             new float[] { lab.L, lab.A, lab.B }, 1);
                    break;

                default:
                    throw new Exception(
                              MessageLocalization.GetComposedMessage(
                                  "only.rgb.gray.and.cmyk.are.supported.as.alternative.color.spaces"));
                }
            }
            else
            {
                array.Add(PdfName.DEVICERGB);
                func = PdfFunction.Type2(writer, new float[] { 0, 1 }, null, new float[] { 1, 1, 1 },
                                         new float[] { (float)altcs.R / 255, (float)altcs.G / 255, (float)altcs.B / 255 }, 1);
            }
            array.Add(func.Reference);
            return(array);
        }
Example #7
0
 //public void LabelGenerator(LabelProperties prop, Size sizeInfo)
 //{
 //  // generate label
 //}
 private void drawTemplate(string color)
 {
     color = color.ToLower();
       CMYKColor chosenColor;
       switch (color)
       {
     case ("yellow"):
       chosenColor = new CMYKColor(0f, 0.2092f, 0.7741f, 0.0627f);
       break;
     case ("red"):
       chosenColor = new CMYKColor(0f, 0.7564f, 0.7372f, 0.3882f);
       break;
     case ("purple"):
       chosenColor = new CMYKColor(0.5118f, 0.6693f, 0f, 0.5020f);
       break;
     default:
       chosenColor = new CMYKColor(0f, 0f, 0f, 0f);
       break;
       }
 }
Example #8
0
        public virtual PdfObject GetPdfObject(PdfWriter writer)
        {
            PdfArray array = new PdfArray(PdfName.DEVICEN);

            PdfArray colorants = new PdfArray();

            float[]       colorantsRanges = new float[spotColors.Length * 2];
            PdfDictionary colorantsDict   = new PdfDictionary();
            String        psFunFooter     = "";

            int numberOfColorants = spotColors.Length;

            float[,] CMYK = new float[4, numberOfColorants];
            int i = 0;

            for (; i < numberOfColorants; i++)
            {
                PdfSpotColor spotColorant = spotColors[i];
                colorantsRanges[2 * i]     = 0;
                colorantsRanges[2 * i + 1] = 1;
                colorants.Add(spotColorant.Name);
                if (colorantsDict.Get(spotColorant.Name) != null)
                {
                    throw new Exception(MessageLocalization.GetComposedMessage("devicen.component.names.shall.be.different"));
                }
                if (colorantsDetails != null)
                {
                    colorantsDict.Put(spotColorant.Name, colorantsDetails[i].IndirectReference);
                }
                else
                {
                    colorantsDict.Put(spotColorant.Name, spotColorant.GetPdfObject(writer));
                }
                BaseColor color = spotColorant.AlternativeCS;
                if (color is ExtendedColor)
                {
                    int type = ((ExtendedColor)color).Type;
                    switch (type)
                    {
                    case ExtendedColor.TYPE_GRAY:
                        CMYK[0, i] = 0;
                        CMYK[1, i] = 0;
                        CMYK[2, i] = 0;
                        CMYK[3, i] = 1 - ((GrayColor)color).Gray;
                        break;

                    case ExtendedColor.TYPE_CMYK:
                        CMYK[0, i] = ((CMYKColor)color).Cyan;
                        CMYK[1, i] = ((CMYKColor)color).Magenta;
                        CMYK[2, i] = ((CMYKColor)color).Yellow;
                        CMYK[3, i] = ((CMYKColor)color).Black;
                        break;

                    case ExtendedColor.TYPE_LAB:
                        CMYKColor cmyk = ((LabColor)color).ToCmyk();
                        CMYK[0, i] = cmyk.Cyan;
                        CMYK[1, i] = cmyk.Magenta;
                        CMYK[2, i] = cmyk.Yellow;
                        CMYK[3, i] = cmyk.Black;
                        break;

                    default:
                        throw new Exception(
                                  MessageLocalization.GetComposedMessage(
                                      "only.rgb.gray.and.cmyk.are.supported.as.alternative.color.spaces"));
                    }
                }
                else
                {
                    float r = color.R;
                    float g = color.G;
                    float b = color.B;
                    float computedC = 0, computedM = 0, computedY = 0, computedK = 0;

                    // BLACK
                    if (r == 0 && g == 0 && b == 0)
                    {
                        computedK = 1;
                    }
                    else
                    {
                        computedC = 1 - (r / 255);
                        computedM = 1 - (g / 255);
                        computedY = 1 - (b / 255);

                        float minCMY = Math.Min(computedC,
                                                Math.Min(computedM, computedY));
                        computedC = (computedC - minCMY) / (1 - minCMY);
                        computedM = (computedM - minCMY) / (1 - minCMY);
                        computedY = (computedY - minCMY) / (1 - minCMY);
                        computedK = minCMY;
                    }
                    CMYK[0, i] = computedC;
                    CMYK[1, i] = computedM;
                    CMYK[2, i] = computedY;
                    CMYK[3, i] = computedK;
                }
                psFunFooter += "pop ";
            }
            array.Add(colorants);

            String psFunHeader = String.Format(NumberFormatInfo.InvariantInfo, "1.000000 {0} 1 roll ", numberOfColorants + 1);

            array.Add(PdfName.DEVICECMYK);
            psFunHeader = psFunHeader + psFunHeader + psFunHeader + psFunHeader;
            String psFun = "";

            i = numberOfColorants + 4;
            for (; i > numberOfColorants; i--)
            {
                psFun += String.Format(NumberFormatInfo.InvariantInfo, "{0} -1 roll ", i);
                for (int j = numberOfColorants; j > 0; j--)
                {
                    psFun += String.Format(NumberFormatInfo.InvariantInfo, "{0} index {1} mul 1.000000 cvr exch sub mul ", j,
                                           CMYK[numberOfColorants + 4 - i, numberOfColorants - j]);
                }
                psFun += String.Format(NumberFormatInfo.InvariantInfo, "1.000000 cvr exch sub {0} 1 roll ", i);
            }

            PdfFunction func = PdfFunction.Type4(writer, colorantsRanges, new float[] { 0, 1, 0, 1, 0, 1, 0, 1 },
                                                 "{ " + psFunHeader + psFun + psFunFooter + "}");

            array.Add(func.Reference);

            PdfDictionary attr = new PdfDictionary();

            attr.Put(PdfName.SUBTYPE, PdfName.NCHANNEL);
            attr.Put(PdfName.COLORANTS, colorantsDict);
            array.Add(attr);

            return(array);
        }
 public static Object[] SplitDAelements(String da)
 {
     PRTokeniser tk = new PRTokeniser(PdfEncodings.ConvertToBytes(da, null));
     ArrayList stack = new ArrayList();
     Object[] ret = new Object[3];
     while (tk.NextToken()) {
         if (tk.TokenType == PRTokeniser.TK_COMMENT)
             continue;
         if (tk.TokenType == PRTokeniser.TK_OTHER) {
             String oper = tk.StringValue;
             if (oper.Equals("Tf")) {
                 if (stack.Count >= 2) {
                     ret[DA_FONT] = stack[stack.Count - 2];
                     ret[DA_SIZE] = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
                 }
             }
             else if (oper.Equals("g")) {
                 if (stack.Count >= 1) {
                     float gray = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
                     if (gray != 0)
                         ret[DA_COLOR] = new GrayColor(gray);
                 }
             }
             else if (oper.Equals("rg")) {
                 if (stack.Count >= 3) {
                     float red = float.Parse((String)stack[stack.Count - 3], System.Globalization.NumberFormatInfo.InvariantInfo);
                     float green = float.Parse((String)stack[stack.Count - 2], System.Globalization.NumberFormatInfo.InvariantInfo);
                     float blue = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
                     ret[DA_COLOR] = new Color(red, green, blue);
                 }
             }
             else if (oper.Equals("k")) {
                 if (stack.Count >= 4) {
                     float cyan = float.Parse((String)stack[stack.Count - 4], System.Globalization.NumberFormatInfo.InvariantInfo);
                     float magenta = float.Parse((String)stack[stack.Count - 3], System.Globalization.NumberFormatInfo.InvariantInfo);
                     float yellow = float.Parse((String)stack[stack.Count - 2], System.Globalization.NumberFormatInfo.InvariantInfo);
                     float black = float.Parse((String)stack[stack.Count - 1], System.Globalization.NumberFormatInfo.InvariantInfo);
                     ret[DA_COLOR] = new CMYKColor(cyan, magenta, yellow, black);
                 }
             }
             stack.Clear();
         }
         else
             stack.Add(tk.StringValue);
     }
     return ret;
 }
Example #10
0
        public static void DrawSquare(PdfContentByte content, Point point, System.Data.IDataReader reader)
        {
            content.SaveState();
            var state = new PdfGState {FillOpacity = FillOpacity};
            content.SetGState(state);
            var color = new CMYKColor(reader.GetFloat(1), reader.GetFloat(2), reader.GetFloat(3), reader.GetFloat(4));
            content.SetColorFill(color);

            content.SetLineWidth(0);
            content.Rectangle(point.X, point.Y, PatchSize, PatchSize);
            content.Fill();
            content.RestoreState();
        }
Example #11
0
        /// <summary>
        /// Creates a formatted cell for a table header
        /// </summary>
        /// <param name="text">Text to be put in cell</param>
        /// <param name="backgroundColor">Background color</param>
        /// <param name="borderWidth">Border width</param>
        /// <param name="padding">Padding</param>
        /// <returns></returns>
        private PdfPCell CreateTableHeader(string text, CMYKColor backgroundColor = null, float? borderWidth = null, float? padding = null)
        {
            if (backgroundColor == null) backgroundColor = _baseColor;
            if (!borderWidth.HasValue) borderWidth = 0;
            if (!padding.HasValue) padding = 5;

            var chunk = new Chunk(text, _tableHeaderFont);
            var phrase = new Phrase(chunk);
            var cell = new PdfPCell(phrase) { BackgroundColor = backgroundColor, BorderWidth = borderWidth.Value, Padding = padding.Value };

            return cell;
        }
Example #12
0
        public static void ResetBackgroundColor(string originalFile, string watermarked, string color)
        {
            int page = 1;

              PdfReader reader = new PdfReader(originalFile);
              using (FileStream fs = new FileStream(watermarked, FileMode.Create, FileAccess.Write, FileShare.None))
              using (PdfStamper stamper = new PdfStamper(reader, fs))
              {
            PdfLayer layer = new PdfLayer("BackgroundColor", stamper.Writer);

            Rectangle rect = reader.GetPageSize(page);
            PdfContentByte cb = stamper.GetOverContent(page);

            cb.BeginLayer(layer);

            // set color
            CMYKColor chosenColor;
            CMYKColor green = new CMYKColor(0.0809f, 0f, 0.1915f, 0.0784f); //TO DO: get green color

            // set template color
            if (color.Equals("yellow", StringComparison.OrdinalIgnoreCase))
            {
              chosenColor = new CMYKColor(0f, 0.2092f, 0.7741f, 0.0627f);
            }
            else if (color.Equals("red", StringComparison.OrdinalIgnoreCase))
            {
              chosenColor = new CMYKColor(0f, 0.7564f, 0.7372f, 0.3882f);
            }
            else if (color.Equals("purple", StringComparison.OrdinalIgnoreCase))
            {
              chosenColor = new CMYKColor(0.5118f, 0.6693f, 0f, 0.5020f);
            }
            else
            {
              chosenColor = new CMYKColor(0f, 0f, 0f, 0f);
            }

            cb.SetColorFill(chosenColor);
            cb.SetColorStroke(chosenColor);

            // draw name label
            double widthDiff = 23;
            double startHeight = rect.Height - 3;
            double midHeight = rect.Height - 18;
            double endHeight = rect.Height - 27;
            double startWidth = rect.Width * 1 / 3;
            double firstMidWidth = startWidth + widthDiff;
            double endWidth = rect.Width;
            double secondMidWidth = endWidth - widthDiff;

            cb.MoveTo(rect.Width * 1 / 3, startHeight);
            cb.LineTo(rect.Width, startHeight);
            cb.LineTo(rect.Width, midHeight);
            cb.CurveTo(secondMidWidth + (endWidth - secondMidWidth) / 1.4, endHeight + (midHeight - endHeight) / 4, secondMidWidth, endHeight);
            cb.LineTo(firstMidWidth, endHeight);
            cb.CurveTo(firstMidWidth - (firstMidWidth - startWidth) / 1.4, endHeight + (midHeight - endHeight) / 4, startWidth, midHeight);
            cb.ClosePathFillStroke();

            // reset flag
            cb.SetColorFill(green);
            cb.SetColorStroke(green);

            startHeight = endHeight - 0.5;
            double heightDiff = 8.5;
            widthDiff = 13;

            cb.MoveTo(endWidth - widthDiff, startHeight);
            cb.LineTo(endWidth, startHeight);
            cb.LineTo(endWidth, startHeight - heightDiff);
            cb.LineTo(endWidth - widthDiff, startHeight - heightDiff);
            cb.ClosePathFillStroke();

            startHeight = startHeight - heightDiff - 2;
            cb.MoveTo(endWidth - widthDiff, startHeight);
            cb.LineTo(endWidth, startHeight);
            cb.LineTo(endWidth, startHeight - heightDiff);
            cb.LineTo(endWidth - widthDiff, startHeight - heightDiff);
            cb.ClosePathFillStroke();

            startHeight = startHeight - heightDiff - 2;
            cb.MoveTo(endWidth - widthDiff, startHeight);
            cb.LineTo(endWidth, startHeight);
            cb.LineTo(endWidth, startHeight - heightDiff);
            cb.LineTo(endWidth - widthDiff, startHeight - heightDiff);
            cb.ClosePathFillStroke();

            double mealLabelStartHeight = rect.Height - 30;
            double mealLabelHeight = 8;
            double mealLabelStartWidth = rect.Width / 3;
            double mealLabelWidth = 120;

            cb.MoveTo(mealLabelStartWidth, mealLabelStartHeight);
            cb.LineTo(mealLabelStartWidth + mealLabelWidth, mealLabelStartHeight);
            cb.LineTo(mealLabelStartWidth + mealLabelWidth, mealLabelStartHeight - mealLabelHeight);
            cb.LineTo(mealLabelStartWidth, mealLabelStartHeight - mealLabelHeight);
            cb.ClosePathFillStroke();

            double macrosStartHeight = rect.Height - 55;
            double macrosStartWidth = rect.Width / 3 + 5;
            double macrosWidth = 20;
            double macrosHeight = 10;

            for (int i = 0; i < 4; i++)
            {
              cb.MoveTo(macrosStartWidth, macrosStartHeight);
              cb.LineTo(macrosStartWidth + macrosWidth, macrosStartHeight);
              cb.LineTo(macrosStartWidth + macrosWidth, macrosStartHeight - macrosHeight);
              cb.LineTo(macrosStartWidth, macrosStartHeight - macrosHeight);
              cb.ClosePathFillStroke();

              macrosStartWidth = macrosStartWidth + macrosWidth + 13;
            }

            // Close the layer
            cb.EndLayer();
              }
        }
Example #13
0
        public static void ResetMacrosDetails(string originalFile, string watermarked)
        {
            int page = 1;

              PdfReader reader = new PdfReader(originalFile);
              using (FileStream fs = new FileStream(watermarked, FileMode.Create, FileAccess.Write, FileShare.None))
              using (PdfStamper stamper = new PdfStamper(reader, fs))
              {
            PdfLayer layer = new PdfLayer("Text", stamper.Writer);

            Rectangle rect = reader.GetPageSize(page);
            PdfContentByte cb = stamper.GetOverContent(page);

            CMYKColor color = new CMYKColor(0f, 0f, 0f, 0f);
            cb.SetColorFill(color);
            cb.SetColorStroke(color);

            cb.BeginLayer(layer);

            double startHeight = rect.Height - 85;
            double height = 48;

            cb.MoveTo(0, startHeight);
            cb.LineTo(rect.Width, startHeight);
            cb.LineTo(rect.Width, startHeight - height);
            cb.LineTo(0, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = rect.Height - 143;
            double startWidth = rect.Width - 85;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(rect.Width, startHeight);
            cb.LineTo(rect.Width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = rect.Height - 150;
            double width = 65;
            height = 7;
            startWidth = 5;
            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = rect.Height - 179.5;
            height = 3;
            width = 4;
            startWidth = 115;

            for (int i = 0; i < 7; i++)
            {
              cb.MoveTo(startWidth, startHeight);
              cb.LineTo(startWidth + width, startHeight);
              cb.LineTo(startWidth + width, startHeight - height);
              cb.LineTo(startWidth, startHeight - height);
              cb.ClosePathFillStroke();

              startHeight = startHeight - 5.5;
            }

            startHeight = startHeight - 13;
            height = 2.7;

            for (int i = 0; i < 4; i++)
            {
              cb.MoveTo(startWidth, startHeight);
              cb.LineTo(startWidth + width, startHeight);
              cb.LineTo(startWidth + width, startHeight - height);
              cb.LineTo(startWidth, startHeight - height);
              cb.ClosePathFillStroke();

              startHeight = startHeight - 5.5;
            }

            cb.EndLayer();
              }
        }
Example #14
0
        public static void ResetMacros(string originalFile, string watermarked)
        {
            int page = 1;

              PdfReader reader = new PdfReader(originalFile);
              using (FileStream fs = new FileStream(watermarked, FileMode.Create, FileAccess.Write, FileShare.None))
              using (PdfStamper stamper = new PdfStamper(reader, fs))
              {
            PdfLayer layer = new PdfLayer("Text", stamper.Writer);

            Rectangle rect = reader.GetPageSize(page);
            PdfContentByte cb = stamper.GetOverContent(page);

            CMYKColor color = new CMYKColor(0f, 0f, 0f, 0f);
            cb.SetColorFill(color);
            cb.SetColorStroke(color);

            cb.BeginLayer(layer);

            double mealLabelStartHeight = rect.Height - 30;
            double mealLabelHeight = 8;
            double mealLabelStartWidth = rect.Width / 3;
            double mealLabelWidth = 120;

            cb.MoveTo(mealLabelStartWidth, mealLabelStartHeight);
            cb.LineTo(mealLabelStartWidth + mealLabelWidth, mealLabelStartHeight);
            cb.LineTo(mealLabelStartWidth + mealLabelWidth, mealLabelStartHeight - mealLabelHeight);
            cb.LineTo(mealLabelStartWidth, mealLabelStartHeight - mealLabelHeight);
            cb.ClosePathFillStroke();

            double macrosStartHeight = rect.Height - 55;
            double macrosStartWidth = rect.Width / 3 + 5;
            double macrosWidth = 20;
            double macrosHeight = 10;

            for (int i = 0; i < 4; i++)
            {
              cb.MoveTo(macrosStartWidth, macrosStartHeight);
              cb.LineTo(macrosStartWidth + macrosWidth, macrosStartHeight);
              cb.LineTo(macrosStartWidth + macrosWidth, macrosStartHeight - macrosHeight);
              cb.LineTo(macrosStartWidth, macrosStartHeight - macrosHeight);
              cb.ClosePathFillStroke();

              macrosStartWidth = macrosStartWidth + macrosWidth + 13;
            }
            // Close the layer
            cb.EndLayer();
              }
        }
        public static double[] CreateEmptyLabel(string originalFile, string watermarked)
        {
            int page = 1;
              double[] dimensions = new double[2];

              PdfReader reader = new PdfReader(originalFile);
              using (FileStream fs = new FileStream(watermarked, FileMode.Create, FileAccess.Write, FileShare.None))
              using (PdfStamper stamper = new PdfStamper(reader, fs))
              {
            PdfLayer layer = new PdfLayer("BackgroundColor", stamper.Writer);

            Rectangle rect = reader.GetPageSize(page);
            PdfContentByte cb = stamper.GetOverContent(page);

            cb.BeginLayer(layer);

            CMYKColor green = new CMYKColor(0.0809f, 0f, 0.1915f, 0.0784f); //TO DO: get green color
            CMYKColor white = new CMYKColor(0f, 0f, 0f, 0f);
            cb.SetColorFill(white);
            cb.SetColorStroke(white);

            // draw name label
            double widthDiff = 23;
            double startHeight = rect.Height - 3;
            double midHeight = rect.Height - 18;
            double endHeight = rect.Height - 27;
            double startWidth = rect.Width * 1 / 3;
            double firstMidWidth = startWidth + widthDiff;
            double endWidth = rect.Width;
            double secondMidWidth = endWidth - widthDiff;

            dimensions[0] = rect.Width;
            dimensions[1] = rect.Height;

            cb.MoveTo(rect.Width * 1 / 3, startHeight);
            cb.LineTo(rect.Width, startHeight);
            cb.LineTo(rect.Width, midHeight);
            cb.CurveTo(secondMidWidth + (endWidth - secondMidWidth) / 1.4, endHeight + (midHeight - endHeight) / 4, secondMidWidth, endHeight);
            cb.LineTo(firstMidWidth, endHeight);
            cb.CurveTo(firstMidWidth - (firstMidWidth - startWidth) / 1.4, endHeight + (midHeight - endHeight) / 4, startWidth, midHeight);
            cb.ClosePathFillStroke();

            // reset flag
            cb.SetColorFill(green);
            cb.SetColorStroke(green);

            startHeight = endHeight - 0.5;
            double heightDiff = 8.5;
            widthDiff = 13;

            cb.MoveTo(endWidth - widthDiff, startHeight);
            cb.LineTo(endWidth, startHeight);
            cb.LineTo(endWidth, startHeight - heightDiff);
            cb.LineTo(endWidth - widthDiff, startHeight - heightDiff);
            cb.ClosePathFillStroke();

            startHeight = startHeight - heightDiff - 2;
            cb.MoveTo(endWidth - widthDiff, startHeight);
            cb.LineTo(endWidth, startHeight);
            cb.LineTo(endWidth, startHeight - heightDiff);
            cb.LineTo(endWidth - widthDiff, startHeight - heightDiff);
            cb.ClosePathFillStroke();

            startHeight = startHeight - heightDiff - 2;
            cb.MoveTo(endWidth - widthDiff, startHeight);
            cb.LineTo(endWidth, startHeight);
            cb.LineTo(endWidth, startHeight - heightDiff);
            cb.LineTo(endWidth - widthDiff, startHeight - heightDiff);
            cb.ClosePathFillStroke();

            cb.SetColorFill(white);
            cb.SetColorStroke(white);

            double mealLabelStartHeight = rect.Height - 30;
            double mealLabelHeight = 8;
            double mealLabelStartWidth = rect.Width / 3;
            double mealLabelWidth = 120;

            cb.MoveTo(mealLabelStartWidth, mealLabelStartHeight);
            cb.LineTo(mealLabelStartWidth + mealLabelWidth, mealLabelStartHeight);
            cb.LineTo(mealLabelStartWidth + mealLabelWidth, mealLabelStartHeight - mealLabelHeight);
            cb.LineTo(mealLabelStartWidth, mealLabelStartHeight - mealLabelHeight);
            cb.ClosePathFillStroke();

            double macrosStartHeight = rect.Height - 55;
            double macrosStartWidth = rect.Width / 3 + 5;
            double macrosWidth = 20;
            double macrosHeight = 10;

            for (int i = 0; i < 4; i++)
            {
              cb.MoveTo(macrosStartWidth, macrosStartHeight);
              cb.LineTo(macrosStartWidth + macrosWidth, macrosStartHeight);
              cb.LineTo(macrosStartWidth + macrosWidth, macrosStartHeight - macrosHeight);
              cb.LineTo(macrosStartWidth, macrosStartHeight - macrosHeight);
              cb.ClosePathFillStroke();

              macrosStartWidth = macrosStartWidth + macrosWidth + 13;
            }

            startHeight = rect.Height - 85;
            double height = 48;

            cb.MoveTo(0, startHeight);
            cb.LineTo(rect.Width, startHeight);
            cb.LineTo(rect.Width, startHeight - height);
            cb.LineTo(0, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = rect.Height - 143;
            startWidth = rect.Width - 85;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(rect.Width, startHeight);
            cb.LineTo(rect.Width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = rect.Height - 150;
            double width = 65;
            height = 7;
            startWidth = 5;
            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = rect.Height - 179.5;
            height = 3.2;
            width = 4;
            startWidth = 115;

            for (int i = 0; i < 7; i++)
            {
              cb.MoveTo(startWidth, startHeight);
              cb.LineTo(startWidth + width, startHeight);
              cb.LineTo(startWidth + width, startHeight - height);
              cb.LineTo(startWidth, startHeight - height);
              cb.ClosePathFillStroke();

              startHeight = startHeight - 5.5;
            }

            startHeight = startHeight - 13;
            height = 2.7;

            for (int i = 0; i < 4; i++)
            {
              cb.MoveTo(startWidth, startHeight);
              cb.LineTo(startWidth + width, startHeight);
              cb.LineTo(startWidth + width, startHeight - height);
              cb.LineTo(startWidth, startHeight - height);
              cb.ClosePathFillStroke();

              startHeight = startHeight - 5.5;
            }

            startHeight = rect.Height - 179.5;
            height = 3.23;
            width = 17;
            startWidth = 25;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 37;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 29;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 32;
            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 24;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 51;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 36;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 23;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = startHeight - 5.5;
            startWidth = 22;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            startHeight = rect.Height - 167;
            height = 3;
            width = 17;
            startWidth = 25;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            width = 12;
            startWidth = 112;

            cb.MoveTo(startWidth, startHeight);
            cb.LineTo(startWidth + width, startHeight);
            cb.LineTo(startWidth + width, startHeight - height);
            cb.LineTo(startWidth, startHeight - height);
            cb.ClosePathFillStroke();

            cb.EndLayer();
              }
              return dimensions;
        }