示例#1
0
        /// <summary>
        /// 1) Remove carbon black field(K) from CMYK colorspace from PDF file.
        /// 2) Make Ncoded PDF with Ncode image files.
        /// </summary>
        /// <param name="inputPdfFilename"></param>
        /// <param name="outputPdfFilename"></param>
        /// <param name="ncodeIamgeFilenames"></param>
        void RemoveK_and_AddNcode(string inputPdfFilename, string outputPdfFilename, string[] ncodeIamgeFilenames)
        {
            Console.WriteLine("2) Remove carbon black field(K) from CMYK colorspace from PDF file");
            Console.WriteLine();
            IPDFDocument doc    = lib.openDocument(inputPdfFilename);
            IPDFDocument newDoc = lib.copyDocumentOnlyPageStructure(doc);

            for (int i = 0; i < newDoc.getPageCount(); i++)
            {
                using (IPDFPage newPage = newDoc.getPageObj(i))
                {
                    newPage.convertColorSpaceToCMY(doc);
                }
            }



            Console.WriteLine("3) Make Ncoded PDF with Ncode image files.");
            Console.WriteLine();
            /////////////////////////////////////////////////////////////////////
            // caution : This code will not work unless Ncode image's bpp is 1.
            /////////////////////////////////////////////////////////////////////
            System.IO.MemoryStream[] ms = new System.IO.MemoryStream[ncodeIamgeFilenames.Length];

            for (int i = 0; i < ncodeIamgeFilenames.Length; ++i)
            {
                ms[i] = new System.IO.MemoryStream();
                System.Drawing.Image ss = System.Drawing.Image.FromFile(ncodeIamgeFilenames[i]);
                ss.Save(ms[i], System.Drawing.Imaging.ImageFormat.Tiff);
            }

            for (int j = 0; j < newDoc.getPageCount(); ++j)
            {
                using (var page = newDoc.getPageObj(j))
                {
                    double x0, y0, x1, y1;
                    x0 = y0 = x1 = y1 = 0;

                    page.getPageMediaBox(ref x0, ref y0, ref x1, ref y1, true);
                    page.addImageContentOver_usingStream(ms[j], true, x0, y0, x1, y1);
                }

                ms[j].Dispose();
            }

            newDoc.saveDocumentAs(outputPdfFilename);
            newDoc.closeDocument();
        }
示例#2
0
        /// <summary>
        /// 1) Remove carbon black field(K) from CMYK colorspace from PDF file.
        /// 2) Make Ncoded PDF with Ncode image files.
        /// </summary>
        /// <param name="inputPdfFilename"></param>
        /// <param name="outputPdfFilename"></param>
        /// <param name="ncodeIamgeFilenames"></param>
        void RemoveK_and_AddNcode_from_Image(string inputPdfFilename, string outputPdfFilename, string[] ncodeIamgeFilenames)
        {
            IPDFDocument doc    = lib.openDocument(inputPdfFilename);
            IPDFDocument newDoc = lib.copyDocument(doc);

            if (doc == null)
            {
                Console.WriteLine("   Cannot open input PDF file.");
                return;
            }

            if (doc.getPageCount() != ncodeImageFilename.Length)
            {
                Console.WriteLine("   Page count is not correct");
                Console.WriteLine("   input PDF pages : " + doc.getPageCount().ToString());
                Console.WriteLine("   Ncode image pages : " + ncodeImageFilename.Length.ToString());

                return;
            }

            Console.WriteLine();
            Console.WriteLine("1) Removing carbon black field(K) from CMYK colorspace from PDF file");
            Console.WriteLine(" ! This step does not work if you have not entered the correct libKey.");
            Console.WriteLine();

            if (newDoc.controller().IsLibKeyOk() == true)
            {
                for (int i = 0; i < newDoc.getPageCount(); i++)
                {
                    using (IPDFPage newPage = newDoc.getPageObj(i))
                    {
                        if (newPage.convertColorSpaceToCMY(doc, 200) == false)
                        {
                            Console.WriteLine(newPage.lastErrorMsg());
                            return;
                        }
                    }
                }
            }

            Console.WriteLine("2) Making Ncoded PDF with Ncode image files.");
            Console.WriteLine();
            /////////////////////////////////////////////////////////////////////
            // caution : This code will not work unless Ncode image's bpp is 1.
            /////////////////////////////////////////////////////////////////////
            System.IO.MemoryStream[] ms = new System.IO.MemoryStream[ncodeIamgeFilenames.Length];

            for (int i = 0; i < ncodeIamgeFilenames.Length; ++i)
            {
                ms[i] = new System.IO.MemoryStream();
                System.Drawing.Image ss = System.Drawing.Image.FromFile(ncodeIamgeFilenames[i]);
                ss.Save(ms[i], System.Drawing.Imaging.ImageFormat.Tiff);

                using (var page = newDoc.getPageObj(i))
                {
                    double x0, y0, x1, y1;
                    x0 = y0 = 0;
                    x1 = ss.Width * 72 / 600;
                    y1 = ss.Height * 72 / 600;

                    if (page.addImageContentOver_usingStream(ms[i], true, x0, y0, x1, y1) == false)
                    {
                        Console.WriteLine(page.lastErrorMsg());
                        return;
                    }
                }

                ms[i].Dispose();
            }

            newDoc.saveDocumentAs(outputPdfFilename);
            newDoc.closeDocument();
            doc.closeDocument();
        }