コード例 #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();
        }
コード例 #3
0
        public Program()
        {
            // Initializing libraries
            Console.WriteLine("//////////////////////////");
            Console.WriteLine("  Initializing libraries");
            Console.WriteLine("//////////////////////////");
            Console.WriteLine();

            sdk = new CNcodeSDK();
            lib = new PDFControl();

            // This is sample app key for testing.
            // If you have your app key, enter here.
            string appKey_NcodeSDK = "184b265d3aed5ccfab05c6b5167f3";

            if (!sdk.Init(appKey_NcodeSDK))
            {
                Console.WriteLine("Initializing Ncode SDK failed.");
                return;
            }
            else
            {
                Console.WriteLine("Ncode SDK version : " + sdk.GetVersion());
                Console.WriteLine();
            }

            // Enter resource folder path
            string libPath = Directory.GetCurrentDirectory();

            // This libKey is not the license key.
            // Please refer below description of Datalogics' sample code.
            // This libKey is needed for remove K from CMYK color space.
            // If you don't need remove K, leave libKey blank.

            // Datalogics description

            /* You may find that you receive exceptions when you attempt to open
             * PDF files that contain permissions restrictions on content or image
             * extraction.  This is due to the APIs used for viewing: these can
             * also be used in other contexts for content extraction or enabling
             * save-as-image capabilities. If you are making a PDF file viewer and
             * you encounter this situation, please contact your support
             * representative or [email protected] to request a key to enable
             * bypassing this restriction check.
             */
            string libKey = "";

            if (!lib.init(libPath, libKey))
            {
                Console.WriteLine("Initializing Adobe PDF lib failed.");
                return;
            }



            Console.WriteLine("///////////////////");
            Console.WriteLine("  Creating Ncode");
            Console.WriteLine("///////////////////");
            Console.WriteLine();

            IPDFDocument doc       = lib.openDocument("input_sample.pdf");
            int          pageCount = doc.getPageCount();

            ncodeImageFilename = new string[pageCount];
            GenerateNcode(pageCount);



            Console.WriteLine("////////////////////////");
            Console.WriteLine("  Creating Ncoded PDF");
            Console.WriteLine("////////////////////////");

            RemoveK_and_AddNcode_from_Image("input_sample.pdf", "output.pdf", ncodeImageFilename);
            lib.libraryCleanUp();



            Console.WriteLine();
            Console.WriteLine("-- Complete --");
            Console.ReadLine();
        }