Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawingTemplate.pdf");
            //Create one page
            PdfPageBase page = pdf.Pages[0];

            //Save graphics state
            PdfGraphicsState state = page.Canvas.Save();

            //Draw rectangles
            //Set rectangle display location and size
            int x      = 130;
            int y      = 100;
            int width  = 300;
            int height = 400;

            //Create one page
            PdfPen pen = new PdfPen(Color.Black, 0.1f);

            page.Canvas.DrawRectangle(pen, new Rectangle(new Point(x, y), new Size(width, height)));

            y      = y + height - 50;
            width  = 100;
            height = 50;
            //Initialize an instance of PdfSeparationColorSpace
            PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MyColor", Color.FromArgb(0, 100, 0, 0));
            PdfPen pen1 = new PdfPen(Color.Red, 1f);
            //Create a brush with spot color
            PdfBrush brush = new PdfSolidBrush(new PdfSeparationColor(cs, 0.1f));

            page.Canvas.DrawRectangle(pen1, brush, new Rectangle(new Point(x, y), new Size(width, height)));

            //Restor graphics
            page.Canvas.Restore(state);

            String result = "DrawRectangles_out.pdf";

            //Save the document
            pdf.SaveToFile(result);
            //Launch the Pdf file
            PDFDocumentViewer(result);
        }
Пример #2
0
        private static void DrawColorsAndColorSpaces(PdfPage page, PdfFont titleFont, PdfFont sectionFont, Stream iccStream)
        {
            PdfBrush brush = new PdfBrush();

            page.Graphics.DrawString("Colors and colorspaces", titleFont, brush, 20, 50);

            page.Graphics.DrawString("DeviceRGB", sectionFont, brush, 20, 70);
            PdfPen   rgbPen   = new PdfPen(PdfRgbColor.DarkRed, 4);
            PdfBrush rgbBrush = new PdfBrush(PdfRgbColor.LightGoldenrodYellow);

            page.Graphics.DrawRectangle(rgbPen, rgbBrush, 20, 85, 250, 100);

            page.Graphics.DrawString("DeviceCMYK", sectionFont, brush, 340, 70);
            PdfPen   cmykPen   = new PdfPen(new PdfCmykColor(1, 0.5, 0, 0.1), 4);
            PdfBrush cmykBrush = new PdfBrush(new PdfCmykColor(0, 0.5, 0.43, 0));

            page.Graphics.DrawRectangle(cmykPen, cmykBrush, 340, 85, 250, 100);

            page.Graphics.DrawString("DeviceGray", sectionFont, brush, 20, 200);
            PdfPen   grayPen   = new PdfPen(new PdfGrayColor(0.1), 4);
            PdfBrush grayBrush = new PdfBrush(new PdfGrayColor(0.75));

            page.Graphics.DrawRectangle(grayPen, grayBrush, 20, 215, 250, 100);

            page.Graphics.DrawString("Indexed", sectionFont, brush, 340, 200);
            PdfIndexedColorSpace indexedColorSpace = new PdfIndexedColorSpace();

            indexedColorSpace.ColorCount     = 2;
            indexedColorSpace.BaseColorSpace = new PdfRgbColorSpace();
            indexedColorSpace.ColorTable     = new byte[] { 192, 0, 0, 0, 0, 128 };
            PdfIndexedColor indexedColor0 = new PdfIndexedColor(indexedColorSpace);

            indexedColor0.ColorIndex = 0;
            PdfIndexedColor indexedColor1 = new PdfIndexedColor(indexedColorSpace);

            indexedColor1.ColorIndex = 1;
            PdfPen   indexedPen   = new PdfPen(indexedColor0, 4);
            PdfBrush indexedBrush = new PdfBrush(indexedColor1);

            page.Graphics.DrawRectangle(indexedPen, indexedBrush, 340, 215, 250, 100);

            page.Graphics.DrawString("CalGray", sectionFont, brush, 20, 330);
            PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace();
            PdfCalGrayColor      calGrayColor1     = new PdfCalGrayColor(calGrayColorSpace);

            calGrayColor1.Gray = 0.6;
            PdfCalGrayColor calGrayColor2 = new PdfCalGrayColor(calGrayColorSpace);

            calGrayColor2.Gray = 0.2;
            PdfPen   calGrayPen   = new PdfPen(calGrayColor1, 4);
            PdfBrush calGrayBrush = new PdfBrush(calGrayColor2);

            page.Graphics.DrawRectangle(calGrayPen, calGrayBrush, 20, 345, 250, 100);

            page.Graphics.DrawString("CalRGB", sectionFont, brush, 340, 330);
            PdfCalRgbColorSpace calRgbColorSpace = new PdfCalRgbColorSpace();
            PdfCalRgbColor      calRgbColor1     = new PdfCalRgbColor(calRgbColorSpace);

            calRgbColor1.Red   = 0.1;
            calRgbColor1.Green = 0.5;
            calRgbColor1.Blue  = 0.25;
            PdfCalRgbColor calRgbColor2 = new PdfCalRgbColor(calRgbColorSpace);

            calRgbColor2.Red   = 0.6;
            calRgbColor2.Green = 0.1;
            calRgbColor2.Blue  = 0.9;
            PdfPen   calRgbPen   = new PdfPen(calRgbColor1, 4);
            PdfBrush calRgbBrush = new PdfBrush(calRgbColor2);

            page.Graphics.DrawRectangle(calRgbPen, calRgbBrush, 340, 345, 250, 100);

            page.Graphics.DrawString("L*a*b", sectionFont, brush, 20, 460);
            PdfLabColorSpace labColorSpace = new PdfLabColorSpace();
            PdfLabColor      labColor1     = new PdfLabColor(labColorSpace);

            labColor1.L = 90;
            labColor1.A = -40;
            labColor1.B = 120;
            PdfLabColor labColor2 = new PdfLabColor(labColorSpace);

            labColor2.L = 45;
            labColor2.A = 90;
            labColor2.B = -34;
            PdfPen   labPen   = new PdfPen(labColor1, 4);
            PdfBrush labBrush = new PdfBrush(labColor2);

            page.Graphics.DrawRectangle(labPen, labBrush, 20, 475, 250, 100);

            page.Graphics.DrawString("Icc", sectionFont, brush, 340, 460);
            PdfIccColorSpace iccColorSpace = new PdfIccColorSpace();

            byte[] iccData = new byte[iccStream.Length];
            iccStream.Read(iccData, 0, iccData.Length);
            iccColorSpace.IccProfile          = iccData;
            iccColorSpace.AlternateColorSpace = new PdfRgbColorSpace();
            iccColorSpace.ColorComponents     = 3;
            PdfIccColor iccColor1 = new PdfIccColor(iccColorSpace);

            iccColor1.ColorComponents = new double[] { 0.45, 0.1, 0.22 };
            PdfIccColor iccColor2 = new PdfIccColor(iccColorSpace);

            iccColor2.ColorComponents = new double[] { 0.21, 0.76, 0.31 };
            PdfPen   iccPen   = new PdfPen(iccColor1, 4);
            PdfBrush iccBrush = new PdfBrush(iccColor2);

            page.Graphics.DrawRectangle(iccPen, iccBrush, 340, 475, 250, 100);

            page.Graphics.DrawString("Separation", sectionFont, brush, 20, 590);
            PdfExponentialFunction tintTransform = new PdfExponentialFunction();

            tintTransform.Domain   = new double[] { 0, 1 };
            tintTransform.Range    = new double[] { 0, 1, 0, 1, 0, 1, 0, 1 };
            tintTransform.Exponent = 1;
            tintTransform.C0       = new double[] { 0, 0, 0, 0 };
            tintTransform.C1       = new double[] { 1, 0.5, 0, 0.1 };

            PdfSeparationColorSpace separationColorSpace = new PdfSeparationColorSpace();

            separationColorSpace.AlternateColorSpace = new PdfCmykColorSpace();
            separationColorSpace.Colorant            = "Custom Blue";
            separationColorSpace.TintTransform       = tintTransform;

            PdfSeparationColor separationColor1 = new PdfSeparationColor(separationColorSpace);

            separationColor1.Tint = 0.23;
            PdfSeparationColor separationColor2 = new PdfSeparationColor(separationColorSpace);

            separationColor2.Tint = 0.74;

            PdfPen   separationPen   = new PdfPen(separationColor1, 4);
            PdfBrush separationBrush = new PdfBrush(separationColor2);

            page.Graphics.DrawRectangle(separationPen, separationBrush, 20, 605, 250, 100);

            page.Graphics.DrawString("Pantone", sectionFont, brush, 340, 590);
            PdfPen   pantonePen   = new PdfPen(PdfPantoneColor.ReflexBlue, 4);
            PdfBrush pantoneBrush = new PdfBrush(PdfPantoneColor.RhodamineRed);

            page.Graphics.DrawRectangle(pantonePen, pantoneBrush, 340, 605, 250, 100);

            page.Graphics.CompressAndClose();
        }
Пример #3
0
        private static void DrawColorsAndColorSpaces(PdfPage page, PdfFont titleFont, PdfFont sectionFont, Stream iccStream)
        {
            PdfBrush brush = new PdfBrush();

            page.Graphics.DrawString("Colors and colorspaces", titleFont, brush, 20, 50);

            page.Graphics.DrawString("DeviceRGB", sectionFont, brush, 20, 70);
            PdfPen rgbPen = new PdfPen(PdfRgbColor.DarkRed, 4);
            PdfBrush rgbBrush = new PdfBrush(PdfRgbColor.LightGoldenrodYellow);
            page.Graphics.DrawRectangle(rgbPen, rgbBrush, 20, 85, 250, 100);

            page.Graphics.DrawString("DeviceCMYK", sectionFont, brush, 340, 70);
            PdfPen cmykPen = new PdfPen(new PdfCmykColor(1, 0.5, 0, 0.1), 4);
            PdfBrush cmykBrush = new PdfBrush(new PdfCmykColor(0, 0.5, 0.43, 0));
            page.Graphics.DrawRectangle(cmykPen, cmykBrush, 340, 85, 250, 100);

            page.Graphics.DrawString("DeviceGray", sectionFont, brush, 20, 200);
            PdfPen grayPen = new PdfPen(new PdfGrayColor(0.1), 4);
            PdfBrush grayBrush = new PdfBrush(new PdfGrayColor(0.75));
            page.Graphics.DrawRectangle(grayPen, grayBrush, 20, 215, 250, 100);

            page.Graphics.DrawString("Indexed", sectionFont, brush, 340, 200);
            PdfIndexedColorSpace indexedColorSpace = new PdfIndexedColorSpace();
            indexedColorSpace.ColorCount = 2;
            indexedColorSpace.BaseColorSpace = new PdfRgbColorSpace();
            indexedColorSpace.ColorTable = new byte[] { 192, 0, 0, 0, 0, 128 };
            PdfIndexedColor indexedColor0 = new PdfIndexedColor(indexedColorSpace);
            indexedColor0.ColorIndex = 0;
            PdfIndexedColor indexedColor1 = new PdfIndexedColor(indexedColorSpace);
            indexedColor1.ColorIndex = 1;
            PdfPen indexedPen = new PdfPen(indexedColor0, 4);
            PdfBrush indexedBrush = new PdfBrush(indexedColor1);
            page.Graphics.DrawRectangle(indexedPen, indexedBrush, 340, 215, 250, 100);

            page.Graphics.DrawString("CalGray", sectionFont, brush, 20, 330);
            PdfCalGrayColorSpace calGrayColorSpace = new PdfCalGrayColorSpace();
            PdfCalGrayColor calGrayColor1 = new PdfCalGrayColor(calGrayColorSpace);
            calGrayColor1.Gray = 0.6;
            PdfCalGrayColor calGrayColor2 = new PdfCalGrayColor(calGrayColorSpace);
            calGrayColor2.Gray = 0.2;
            PdfPen calGrayPen = new PdfPen(calGrayColor1, 4);
            PdfBrush calGrayBrush = new PdfBrush(calGrayColor2);
            page.Graphics.DrawRectangle(calGrayPen, calGrayBrush, 20, 345, 250, 100);

            page.Graphics.DrawString("CalRGB", sectionFont, brush, 340, 330);
            PdfCalRgbColorSpace calRgbColorSpace = new PdfCalRgbColorSpace();
            PdfCalRgbColor calRgbColor1 = new PdfCalRgbColor(calRgbColorSpace);
            calRgbColor1.Red = 0.1;
            calRgbColor1.Green = 0.5;
            calRgbColor1.Blue = 0.25;
            PdfCalRgbColor calRgbColor2 = new PdfCalRgbColor(calRgbColorSpace);
            calRgbColor2.Red = 0.6;
            calRgbColor2.Green = 0.1;
            calRgbColor2.Blue = 0.9;
            PdfPen calRgbPen = new PdfPen(calRgbColor1, 4);
            PdfBrush calRgbBrush = new PdfBrush(calRgbColor2);
            page.Graphics.DrawRectangle(calRgbPen, calRgbBrush, 340, 345, 250, 100);

            page.Graphics.DrawString("L*a*b", sectionFont, brush, 20, 460);
            PdfLabColorSpace labColorSpace = new PdfLabColorSpace();
            PdfLabColor labColor1 = new PdfLabColor(labColorSpace);
            labColor1.L = 90;
            labColor1.A = -40;
            labColor1.B = 120;
            PdfLabColor labColor2 = new PdfLabColor(labColorSpace);
            labColor2.L = 45;
            labColor2.A = 90;
            labColor2.B = -34;
            PdfPen labPen = new PdfPen(labColor1, 4);
            PdfBrush labBrush = new PdfBrush(labColor2);
            page.Graphics.DrawRectangle(labPen, labBrush, 20, 475, 250, 100);

            page.Graphics.DrawString("Icc", sectionFont, brush, 340, 460);
            PdfIccColorSpace iccColorSpace = new PdfIccColorSpace();
            byte[] iccData = new byte[iccStream.Length];
            iccStream.Read(iccData, 0, iccData.Length);
            iccColorSpace.IccProfile = iccData;
            iccColorSpace.AlternateColorSpace = new PdfRgbColorSpace();
            iccColorSpace.ColorComponents = 3;
            PdfIccColor iccColor1 = new PdfIccColor(iccColorSpace);
            iccColor1.ColorComponents = new double[] { 0.45, 0.1, 0.22 };
            PdfIccColor iccColor2 = new PdfIccColor(iccColorSpace);
            iccColor2.ColorComponents = new double[] { 0.21, 0.76, 0.31 };
            PdfPen iccPen = new PdfPen(iccColor1, 4);
            PdfBrush iccBrush = new PdfBrush(iccColor2);
            page.Graphics.DrawRectangle(iccPen, iccBrush, 340, 475, 250, 100);

            page.Graphics.DrawString("Separation", sectionFont, brush, 20, 590);
            PdfExponentialFunction tintTransform = new PdfExponentialFunction();
            tintTransform.Domain = new double[] { 0, 1 };
            tintTransform.Range = new double[] { 0, 1, 0, 1, 0, 1, 0, 1 };
            tintTransform.Exponent = 1;
            tintTransform.C0 = new double[] { 0, 0, 0, 0 };
            tintTransform.C1 = new double[] { 1, 0.5, 0, 0.1 };

            PdfSeparationColorSpace separationColorSpace = new PdfSeparationColorSpace();
            separationColorSpace.AlternateColorSpace = new PdfCmykColorSpace();
            separationColorSpace.Colorant = "Custom Blue";
            separationColorSpace.TintTransform = tintTransform;

            PdfSeparationColor separationColor1 = new PdfSeparationColor(separationColorSpace);
            separationColor1.Tint = 0.23;
            PdfSeparationColor separationColor2 = new PdfSeparationColor(separationColorSpace);
            separationColor2.Tint = 0.74;

            PdfPen separationPen = new PdfPen(separationColor1, 4);
            PdfBrush separationBrush = new PdfBrush(separationColor2);
            page.Graphics.DrawRectangle(separationPen, separationBrush, 20, 605, 250, 100);

            page.Graphics.DrawString("Pantone", sectionFont, brush, 340, 590);
            PdfPen pantonePen = new PdfPen(PdfPantoneColor.ReflexBlue, 4);
            PdfBrush pantoneBrush = new PdfBrush(PdfPantoneColor.RhodamineRed);
            page.Graphics.DrawRectangle(pantonePen, pantoneBrush, 340, 605, 250, 100);

            page.Graphics.CompressAndClose();
        }
Пример #4
0
        private void button1_Click(object sender, EventArgs e)
        {
            //Load the document from disk
            PdfDocument pdf = new PdfDocument();

            pdf.LoadFromFile(@"..\..\..\..\..\..\Data\DrawContentWithSpotColor.pdf");

            //Get the first page
            PdfPageBase page = pdf.Pages[0];

            //Initialize an instance of PdfSeparationColorSpace
            PdfSeparationColorSpace cs = new PdfSeparationColorSpace("MySpotColor", Color.DarkViolet);

            //Set tini = 1 for the cs
            PdfSeparationColor color = new PdfSeparationColor(cs, 1f);

            //Create a brush with spot color
            PdfSolidBrush brush = new PdfSolidBrush(color);

            //Draw a string
            page.Canvas.DrawString("Tint=1.0", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new PointF(160, 160));

            //Draw pie with spot color(DarkViolet)
            page.Canvas.DrawPie(brush, 148, 200, 60, 60, 360, 360);

            page.Canvas.DrawString("Tint=0.7", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new PointF(230, 160));
            color = new PdfSeparationColor(cs, 0.7f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 218, 200, 60, 60, 360, 360);

            page.Canvas.DrawString("Tint=0.4", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new PointF(300, 160));
            color = new PdfSeparationColor(cs, 0.4f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 288, 200, 60, 60, 360, 360);

            page.Canvas.DrawString("Tint=0.1", new PdfFont(PdfFontFamily.Helvetica, 10f), brush, new PointF(370, 160));
            color = new PdfSeparationColor(cs, 0.1f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 358, 200, 60, 60, 360, 360);

            //Draw pie with spot color(Purple)
            cs    = new PdfSeparationColorSpace("MySpotColor", Color.Purple);
            color = new PdfSeparationColor(cs, 1f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 148, 280, 60, 60, 360, 360);

            color = new PdfSeparationColor(cs, 0.7f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 218, 280, 60, 60, 360, 360);

            color = new PdfSeparationColor(cs, 0.4f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 288, 280, 60, 60, 360, 360);

            color = new PdfSeparationColor(cs, 0.1f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 358, 280, 60, 60, 360, 360);

            //Draw pie with spot color(DarkSlateBlue)
            cs    = new PdfSeparationColorSpace("MySpotColor", Color.DarkSlateBlue);
            color = new PdfSeparationColor(cs, 1f);
            brush = new PdfSolidBrush(color);

            page.Canvas.DrawPie(brush, 148, 360, 60, 60, 360, 360);

            color = new PdfSeparationColor(cs, 0.7f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 218, 360, 60, 60, 360, 360);

            color = new PdfSeparationColor(cs, 0.4f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 288, 360, 60, 60, 360, 360);

            color = new PdfSeparationColor(cs, 0.1f);
            brush = new PdfSolidBrush(color);
            page.Canvas.DrawPie(brush, 358, 360, 60, 60, 360, 360);

            //Save the document
            pdf.SaveToFile("SpotColor.pdf");

            //View the pdf document
            PDFDocumentViewer("SpotColor.pdf");
        }