// This code is part of Document Solutions for PDF demos.
// Copyright (c) MESCIUS inc. All rights reserved.
using System;
using System.IO;
using System.Drawing;
using System.Text;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Drawing;
using GCTEXT = GrapeCity.Documents.Text;
using GCDRAW = GrapeCity.Documents.Drawing;

namespace DsPdfWeb.Demos
    // This sample shows how to add output intents to a PDF.
    // It adds several versions of the ICC Probe Profile
    // which deliberately distorts the rendered colors, so that it is easy
    // to make sure that a profile is actually being used. To see the effect
    // in this PDF, you may open it in Adobe Acrobat Reader DC, and set the
    // Edit | Preferences | Page Display | Show Overprint Preview option to 'Always'.
    // Then the deliberate color distortion added by the Probe Profile will be obvious.
    // For details please see the "Output Intents" section of the PDF Specification.
    public class OutputIntents
        public int CreatePDF(Stream stream)
            // The different versions of the ICC Probe profile:
            var profiles = new (string, string)[] {
                ("Probev2_ICCv4.icc", @"https://www.color.org/probeprofile.xalter"),
                ("Probev1_ICCv4.icc", @"https://www.color.org/probeprofile.xalter"),
                ("Probev1_ICCv2.icc", @"https://www.color.org/probeprofile.xalter"),
            var doc = new GcPdfDocument();
            var page = doc.NewPage();
            var g = page.Graphics;
            var sb = new StringBuilder();
            const string bullet = "\x2022\x2003";
            sb.AppendLine("This document contains the following output intents (first one is the default):");
            int i = 0;
            foreach (var profile in profiles)
                sb.AppendLine($"{bullet}{profile.Item1}, source: {profile.Item2}");
                using (FileStream fs = File.OpenRead(Path.Combine("Resources", "Misc", profile.Item1)))
                    var oi = OutputIntent.Create($"Output intent testing {i++}", "", "http://www.color.org", profile.Item1, fs);
                "Colors processed via the ICC Probe Profile are deliberately distorted, " +
                "so that it is easy to visually confirm that a profile is being used. " +
                "To see the effect in this PDF, you may open it in Adobe Acrobat Reader DC and make sure that " +
                "Edit | Preferences | Page Display | Show Overprint Preview is set to 'Always', " +
                "then the deliberate color distortion will be obvious.");
            var rc = Common.Util.AddNote(sb.ToString(), page);
            g.DrawImage(GCDRAW.Image.FromFile(Path.Combine("Resources", "Images", "roofs.jpg")),
                new RectangleF(rc.Left, rc.Bottom + 24, rc.Width, rc.Width), null, ImageAlign.StretchImage);
            return doc.Pages.Count;