コード例 #1
0
ファイル: ColorSpaces.cs プロジェクト: sss-software/pdf4net
        /// <summary>
        /// Draws content on a page using colors created from a calibrated gray colorspace.
        /// </summary>
        /// <param name="page">The page to draw to.</param>
        private static void DrawCalGrayColorSpace(PDFPage page)
        {
            PDFRgbColor black      = new PDFRgbColor(0, 0, 0);
            PDFBrush    blackBrush = new PDFBrush(black);
            //PDF4NET v5: PDFFont font = new PDFFont(PDFFontFace.Helvetica, 16);
            PDFStandardFont font = new PDFStandardFont(PDFStandardFontFace.Helvetica, 16);

            //PDF4NET v5: page.Canvas.DrawText("CalGray colorspace", font, null, blackBrush, 50, 50);
            page.Canvas.DrawString("CalGray colorspace", font, blackBrush, 50, 50);

            PDFCalGrayColorSpace calGrayCS = new PDFCalGrayColorSpace();
            PDFCalGrayColor      dkGray    = new PDFCalGrayColor(calGrayCS);

            dkGray.Gray = 0.1;
            PDFCalGrayColor ltGray = new PDFCalGrayColor(calGrayCS);

            ltGray.Gray = 0.8;
            PDFBrush dkBrush = new PDFBrush(dkGray);
            PDFPen   ltPen   = new PDFPen(ltGray, 5);

            page.Canvas.DrawRoundRectangle(ltPen, dkBrush, 50, 100, 400, 150, 20, 20);
        }
コード例 #2
0
ファイル: VectorGraphics.cs プロジェクト: o2solutions/pdf4net
        private static void DrawColorsAndColorSpaces(PDFPage page, PDFFont titleFont, PDFFont sectionFont, Stream iccStream)
        {
            PDFBrush brush = new PDFBrush();

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

            page.Canvas.DrawString("DeviceRGB", sectionFont, brush, 20, 70);
            PDFPen   rgbPen   = new PDFPen(PDFRgbColor.DarkRed, 4);
            PDFBrush rgbBrush = new PDFBrush(PDFRgbColor.LightGoldenrodYellow);

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

            page.Canvas.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.Canvas.DrawRectangle(cmykPen, cmykBrush, 340, 85, 250, 100);

            page.Canvas.DrawString("DeviceGray", sectionFont, brush, 20, 200);
            PDFPen   grayPen   = new PDFPen(new PDFGrayColor(0.1), 4);
            PDFBrush grayBrush = new PDFBrush(new PDFGrayColor(0.75));

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

            page.Canvas.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.Canvas.DrawRectangle(indexedPen, indexedBrush, 340, 215, 250, 100);

            page.Canvas.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.Canvas.DrawRectangle(calGrayPen, calGrayBrush, 20, 345, 250, 100);

            page.Canvas.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.Canvas.DrawRectangle(calRgbPen, calRgbBrush, 340, 345, 250, 100);

            page.Canvas.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.Canvas.DrawRectangle(labPen, labBrush, 20, 475, 250, 100);

            page.Canvas.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.Canvas.DrawRectangle(iccPen, iccBrush, 340, 475, 250, 100);

            page.Canvas.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.Canvas.DrawRectangle(separationPen, separationBrush, 20, 605, 250, 100);

            page.Canvas.DrawString("Pantone", sectionFont, brush, 340, 590);
            PDFPen   pantonePen   = new PDFPen(PDFPantoneColor.ReflexBlue, 4);
            PDFBrush pantoneBrush = new PDFBrush(PDFPantoneColor.RhodamineRed);

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

            page.Canvas.CompressAndClose();
        }