예제 #1
0
        /// <summary>
        /// Draws content on a page using colors created from a calibrated ICC colorspace.
        /// </summary>
        /// <param name="page">The page to draw to.</param>
        private static void DrawICCColorSpace(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("ICC colorspace", font, null, blackBrush, 50, 50);
            page.Canvas.DrawString("ICC colorspace", font, blackBrush, 50, 50);

            // Read the ICC profile from disk.
            FileStream fs = new FileStream("..\\..\\..\\..\\..\\SupportFiles\\rgb.icc", FileMode.Open, FileAccess.Read);

            byte[] profileData = new byte[fs.Length];
            fs.Read(profileData, 0, profileData.Length);
            fs.Close();

            //PDF4NET v5: PDFICCColorSpace iccCS = new PDFICCColorSpace();
            PDFIccColorSpace iccCS = new PDFIccColorSpace();

            iccCS.IccProfile = profileData;
            //PDF4NET v5: PDFICCColor red = new PDFICCColor(iccCS);
            PDFIccColor red = new PDFIccColor(iccCS);

            red.ColorComponents = new double[] { 192, 0, 0 };
            //PDF4NET v5: PDFICCColor blue = new PDFICCColor(iccCS);
            PDFIccColor blue = new PDFIccColor(iccCS);

            blue.ColorComponents = new double[] { 0, 0, 192 };
            PDFBrush blueBrush = new PDFBrush(blue);
            PDFPen   redPen    = new PDFPen(red, 5);

            page.Canvas.DrawRoundRectangle(redPen, blueBrush, 50, 100, 400, 150, 20, 20);
        }
예제 #2
0
        private static PDFFixedDocument CreatePDFA1bDocument(Stream iccInput, Stream ttfInput)
        {
            iccInput.Position = 0;
            ttfInput.Position = 0;

            PDFFixedDocument document = new PDFFixedDocument();

            // Setup the document by creating a PDF/A output intent, based on a RGB ICC profile,
            // and document information and metadata
            PDFIccColorSpace icc = new PDFIccColorSpace();

            byte[] profilePayload = new byte[iccInput.Length];
            iccInput.Read(profilePayload, 0, profilePayload.Length);
            icc.IccProfile = profilePayload;
            PDFOutputIntent oi = new PDFOutputIntent();

            oi.Type = PDFOutputIntentType.PDFA1;
            oi.Info = "sRGB IEC61966-2.1";
            oi.OutputConditionIdentifier = "Custom";
            oi.DestinationOutputProfile  = icc;
            document.OutputIntents       = new PDFOutputIntentCollection();
            document.OutputIntents.Add(oi);

            document.DocumentInformation          = new PDFDocumentInformation();
            document.DocumentInformation.Author   = "O2 Solutions";
            document.DocumentInformation.Title    = "PDF4NET PDF/A-1B Demo";
            document.DocumentInformation.Creator  = "PDF4NET PDF/A-1B Demo Application";
            document.DocumentInformation.Producer = "PDF4NET";
            document.DocumentInformation.Keywords = "pdf/a";
            document.DocumentInformation.Subject  = "PDF/A-1B Sample produced by PDF4NET";
            document.XmpMetadata = new PDFXmpMetadata();

            PDFPage page = document.Pages.Add();

            page.Rotation = 90;

            // All fonts must be embedded in a PDF/A document.
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = new PDFAnsiTrueTypeFont(ttfInput, 24, true);
            sao.Brush = new PDFBrush(new PDFRgbColor(0, 0, 128));

            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = page.Width / 2;
            slo.Y = page.Height / 2 - 10;
            page.Canvas.DrawString("PDF4NET", sao, slo);
            slo.Y             = page.Height / 2 + 10;
            slo.VerticalAlign = PDFStringVerticalAlign.Top;
            sao.Font.Size     = 16;
            page.Canvas.DrawString("This is a sample PDF/A-1B document that shows the PDF/A-1B capabilities in PDF4NET library", sao, slo);

            return(document);
        }
예제 #3
0
        private static PDFFixedDocument CreatePDFA2uDocument(Stream iccInput, Stream ttfInput)
        {
            iccInput.Position = 0;
            ttfInput.Position = 0;

            PDFFixedDocument document = new PDFFixedDocument();

            document.OptionalContentProperties = new PDFOptionalContentProperties();

            // Setup the document by creating a PDF/A output intent, based on a RGB ICC profile,
            // and document information and metadata
            PDFIccColorSpace icc = new PDFIccColorSpace();

            byte[] profilePayload = new byte[iccInput.Length];
            iccInput.Read(profilePayload, 0, profilePayload.Length);
            icc.IccProfile = profilePayload;
            PDFOutputIntent oi = new PDFOutputIntent();

            oi.Type = PDFOutputIntentType.PDFA1;
            oi.Info = "sRGB IEC61966-2.1";
            oi.OutputConditionIdentifier = "Custom";
            oi.DestinationOutputProfile  = icc;
            document.OutputIntents       = new PDFOutputIntentCollection();
            document.OutputIntents.Add(oi);

            document.DocumentInformation          = new PDFDocumentInformation();
            document.DocumentInformation.Author   = "O2 Solutions";
            document.DocumentInformation.Title    = "PDF4NET PDF/A-2B/U Demo";
            document.DocumentInformation.Creator  = "PDF4NET PDF/A-2B/U Demo Application";
            document.DocumentInformation.Producer = "PDF4NET";
            document.DocumentInformation.Keywords = "pdf/a";
            document.DocumentInformation.Subject  = "PDF/A-2B/U Sample produced by PDF4NET";
            document.XmpMetadata = new PDFXmpMetadata();

            PDFPage page = document.Pages.Add();

            page.Rotation = 90;

            // All fonts must be embedded in a PDF/A document.
            PDFStringAppearanceOptions sao = new PDFStringAppearanceOptions();

            sao.Font  = new PDFAnsiTrueTypeFont(ttfInput, 24, true);
            sao.Brush = new PDFBrush(new PDFRgbColor(0, 0, 128));

            PDFStringLayoutOptions slo = new PDFStringLayoutOptions();

            slo.HorizontalAlign = PDFStringHorizontalAlign.Center;
            slo.VerticalAlign   = PDFStringVerticalAlign.Bottom;
            slo.X = page.Width / 2;
            slo.Y = page.Height / 2 - 10;
            page.Canvas.DrawString("PDF4NET", sao, slo);
            slo.Y             = page.Height / 2 + 10;
            slo.VerticalAlign = PDFStringVerticalAlign.Top;
            sao.Font.Size     = 14;
            page.Canvas.DrawString("This is a sample PDF/A-2B/U document that shows the PDF/A-2B/U capabilities in PDF4NET library", sao, slo);

            // PDF/A-2 documents support optional content and transparency.
            PDFOptionalContentGroup ocgPage1 = new PDFOptionalContentGroup();

            ocgPage1.Name = "Green Rectangle";
            page.Canvas.BeginOptionalContentGroup(ocgPage1);
            page.Canvas.SaveGraphicsState();
            PDFExtendedGraphicState gs = new PDFExtendedGraphicState();

            gs.FillAlpha   = 0.8;
            gs.StrokeAlpha = 0.2;
            gs.BlendMode   = PDFBlendMode.Luminosity;
            page.Canvas.SetExtendedGraphicState(gs);

            PDFBrush greenBrush = new PDFBrush(PDFRgbColor.DarkGreen);
            PDFPen   bluePen    = new PDFPen(PDFRgbColor.DarkBlue, 5);

            page.Canvas.DrawRectangle(bluePen, greenBrush, 20, 20, page.Width - 40, page.Height - 40);

            page.Canvas.RestoreGraphicsState();
            page.Canvas.EndOptionalContentGroup();

            // Build the display tree for the optional content,
            // how its structure and relationships between optional content groups are presented to the user.
            PDFOptionalContentDisplayTreeNode ocgPage1Node = new PDFOptionalContentDisplayTreeNode(ocgPage1);

            document.OptionalContentProperties.DisplayTree.Nodes.Add(ocgPage1Node);

            return(document);
        }
예제 #4
0
        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();
        }