/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream iccInput, Stream ttfInput) { 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 = "XFINIUM Software"; document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-1B Demo"; document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-1B Demo"; document.DocumentInformation.Producer = "XFINIUM.PDF"; document.DocumentInformation.Keywords = "pdf/a"; document.DocumentInformation.Subject = "PDF/A-1B Sample produced by XFINIUM.PDF"; 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.Graphics.DrawString("XFINIUM.PDF", sao, slo); slo.Y = page.Height / 2 + 10; slo.VerticalAlign = PdfStringVerticalAlign.Top; sao.Font.Size = 16; page.Graphics.DrawString("This is a sample PDF/A document that shows the PDF/A capabilities in XFINIUM.PDF library", sao, slo); // The document is formatted as PDF/A using the PdfAFormatter class: // PdfAFormatter.Save(document, outputStream, PdfAFormat.PdfA1b); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pdfa.pdf") }; return(output); }
/// <summary> /// Main method for running the sample. /// </summary> public static SampleOutputInfo[] Run(Stream iccInput, Stream ttfInput) { 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 = "XFINIUM Software"; document.DocumentInformation.Title = "XFINIUM.PDF PDF/A-1B Demo"; document.DocumentInformation.Creator = "XFINIUM.PDF PDF/A-1B Demo"; document.DocumentInformation.Producer = "XFINIUM.PDF"; document.DocumentInformation.Keywords = "pdf/a"; document.DocumentInformation.Subject = "PDF/A-1B Sample produced by XFINIUM.PDF"; 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.Graphics.DrawString("XFINIUM.PDF", sao, slo); slo.Y = page.Height / 2 + 10; slo.VerticalAlign = PdfStringVerticalAlign.Top; sao.Font.Size = 16; page.Graphics.DrawString("This is a sample PDF/A document that shows the PDF/A capabilities in XFINIUM.PDF library", sao, slo); // The document is formatted as PDF/A using the PdfAFormatter class: // PdfAFormatter.Save(document, outputStream, PdfAFormat.PdfA1b); SampleOutputInfo[] output = new SampleOutputInfo[] { new SampleOutputInfo(document, "xfinium.pdf.sample.pdfa.pdf") }; return output; }
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(); }