OutputIntents.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Drawing;
  8. using System.Text;
  9. using GrapeCity.Documents.Pdf;
  10. using GrapeCity.Documents.Text;
  11. using GrapeCity.Documents.Drawing;
  12. using GCTEXT = GrapeCity.Documents.Text;
  13. using GCDRAW = GrapeCity.Documents.Drawing;
  14.  
  15. namespace DsPdfWeb.Demos
  16. {
  17. // This sample shows how to add output intents to a PDF.
  18. // It adds several versions of the ICC Probe Profile
  19. // which deliberately distorts the rendered colors, so that it is easy
  20. // to make sure that a profile is actually being used. To see the effect
  21. // in this PDF, you may open it in Adobe Acrobat Reader DC, and set the
  22. // Edit | Preferences | Page Display | Show Overprint Preview option to 'Always'.
  23. // Then the deliberate color distortion added by the Probe Profile will be obvious.
  24. // For details please see the "Output Intents" section of the PDF Specification.
  25. public class OutputIntents
  26. {
  27. public int CreatePDF(Stream stream)
  28. {
  29. // The different versions of the ICC Probe profile:
  30. var profiles = new (string, string)[] {
  31. ("Probev2_ICCv4.icc", @"https://www.color.org/probeprofile.xalter"),
  32. ("Probev1_ICCv4.icc", @"https://www.color.org/probeprofile.xalter"),
  33. ("Probev1_ICCv2.icc", @"https://www.color.org/probeprofile.xalter"),
  34. };
  35. //
  36. var doc = new GcPdfDocument();
  37. var page = doc.NewPage();
  38. var g = page.Graphics;
  39. var sb = new StringBuilder();
  40. const string bullet = "\x2022\x2003";
  41. sb.AppendLine("This document contains the following output intents (first one is the default):");
  42. int i = 0;
  43. foreach (var profile in profiles)
  44. {
  45. sb.AppendLine($"{bullet}{profile.Item1}, source: {profile.Item2}");
  46. using (FileStream fs = File.OpenRead(Path.Combine("Resources", "Misc", profile.Item1)))
  47. {
  48. var oi = OutputIntent.Create($"Output intent testing {i++}", "", "http://www.color.org", profile.Item1, fs);
  49. doc.OutputIntents.Add(oi);
  50. }
  51. }
  52. sb.AppendLine(
  53. "Colors processed via the ICC Probe Profile are deliberately distorted, " +
  54. "so that it is easy to visually confirm that a profile is being used. " +
  55. "To see the effect in this PDF, you may open it in Adobe Acrobat Reader DC and make sure that " +
  56. "Edit | Preferences | Page Display | Show Overprint Preview is set to 'Always', " +
  57. "then the deliberate color distortion will be obvious.");
  58. var rc = Common.Util.AddNote(sb.ToString(), page);
  59. g.DrawImage(GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "roofs.jpg")),
  60. new RectangleF(rc.Left, rc.Bottom + 24, rc.Width, rc.Width), null, ImageAlign.StretchImage);
  61. //
  62. doc.Save(stream);
  63. return doc.Pages.Count;
  64. }
  65. }
  66. }
  67.