private void Init(IImageObject image, byte[] buffer, GraphicsState state) { this.state = state; this.image = image; this.buffer = buffer; imageMask = image.ImageMask; decode = image.Decode; matte = image.Matte; size = image.Size; bitPerComponent = image.BitsPerComponent; maximum = Math.Pow(2, bitPerComponent) - 1; min = 0D; max = indexed ? maximum : 1D; sMask = image.SMask; if (sMask != null) { sMaskLoader = new ImageLoader(sMask, state); } if (imageMask) { return; } colorSpace = image.ColorSpace; componentsCount = colorSpace.ComponentCount; iccColorSpace = colorSpace as ICCBasedColorSpace; if (colorSpace is IndexedColorSpace indexedColorSpace) { indexed = true; iccColorSpace = indexedColorSpace.BaseSpace as ICCBasedColorSpace; } }
public void export_doc_images_type(Document doc, PDFStream profileStream, ImageType imtype) { exporttype = imtype; ColorSpace cs = new ICCBasedColorSpace(profileStream); for (int pgno = 0; pgno < doc.NumPages; pgno++) { Page pg = doc.GetPage(pgno); Export_Image(pg.Content, cs, pg, pgno); } }
static void Main(string[] args) { using (Library lib = new Library()) { String sInput = Library.ResourceDirectory + "Sample_Input/sRGB_IEC61966-2-1_noBPC.icc"; String sOutput = "../ICCBased-out.pdf"; if (args.Length > 0) { sInput = args[0]; } if (args.Length > 1) { sOutput = args[1]; } Console.WriteLine("Writing to output " + sOutput); Document doc = new Document(); Page page = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72)); Content content = page.Content; Font font = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset); FileStream stream = new FileStream(sInput, FileMode.Open); PDFStream pdfStream = new PDFStream(stream, doc, null, null); ColorSpace cs = new ICCBasedColorSpace(pdfStream, 3); GraphicState gs = new GraphicState(); gs.FillColor = new Color(cs, new Double[] { 1.0, 0.0, 0.0 }); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); text.AddRun(textRun); content.AddElement(text); page.UpdateContent(); doc.EmbedFonts(); doc.Save(SaveFlags.Full, sOutput); } }
static void Main(string[] args) { // ReSharper disable once UnusedVariable using (Library lib = new Library()) { String sInput = Library.ResourceDirectory + "Sample_Input/sRGB_IEC61966-2-1_noBPC.icc"; String sOutput = "ICCBased-out.pdf"; if (args.Length > 0) { sInput = args[0]; } if (args.Length > 1) { sOutput = args[1]; } Console.WriteLine("Writing to output " + sOutput); Document doc = new Document(); Page page = doc.CreatePage(Document.BeforeFirstPage, new Rect(0, 0, 5 * 72, 4 * 72)); Content content = page.Content; Font font; try { font = new Font("Times-Roman", FontCreateFlags.Embedded | FontCreateFlags.Subset); } catch (ApplicationException ex) { if (ex.Message.Equals("The specified font could not be found.") && System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices .OSPlatform.Linux) && !Directory.Exists("/usr/share/fonts/msttcore/")) { Console.WriteLine("Please install Microsoft Core Fonts on Linux first."); return; } throw; } FileStream stream = new FileStream(sInput, FileMode.Open); PDFStream pdfStream = new PDFStream(stream, doc, null, null); ColorSpace cs = new ICCBasedColorSpace(pdfStream, 3); GraphicState gs = new GraphicState(); gs.FillColor = new Color(cs, new[] { 1.0, 0.0, 0.0 }); Matrix textMatrix = new Matrix(24, 0, 0, 24, // Set font width and height to 24 point size 1 * 72, 2 * 72); // x, y coordinate on page, 1" x 2" TextRun textRun = new TextRun("Hello World!", font, gs, new TextState(), textMatrix); Text text = new Text(); text.AddRun(textRun); content.AddElement(text); page.UpdateContent(); doc.EmbedFonts(); doc.Save(SaveFlags.Full, sOutput); } }