コード例 #1
0
        static void Main(string[] args)
        {
            string strPath = System.AppDomain.CurrentDomain.BaseDirectory;

            // Starting with Toolkit version 10 native DLLs are no longer
            // copied to the system folder. The Toolkit constructor must
            // be called with the path to the native DLLs or place them
            // in your applications working directory. This example
            // assumes they are located in the default installation folder.
            // (Use x86 in the path for 32b applications)
            string toolkitPath = $@"{Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)}\ActivePDF\Toolkit Ultimate\bin\x64";

            // Instantiate Object
            using (APToolkitNET.Toolkit toolkit = new APToolkitNET.Toolkit(toolkitPath))
            {
                // Open the input PDF
                short result = toolkit.OpenInputFile(InputFileName: $"{strPath}Toolkit.Input.pdf");
                if (result == 0)
                {
                    // Get the input document page count.
                    int pageCount = toolkit.NumPages("");

                    // Get the Redactor object from Toolkit
                    APToolkitNET.Rasterizer rasterizer = toolkit.GetRasterizer();

                    // Rotate the image files 90 degrees
                    rasterizer.Rotation = 90.0f;

                    for (int currentPage = 1; currentPage <= pageCount; currentPage++)
                    {
                        string outputFile = $"{strPath}RotateImage.{currentPage}.jpg";

                        // Convert each page of the input PDF to an image rotated 90 degrees.
                        if (!rasterizer.ToImage(sFileName: $"{outputFile}", eImageType: APToolkitNET.APImageType.JPEG, currentPage))
                        {
                            WriteResult($"Error writing image file to: {outputFile}", toolkit);
                        }
                        else
                        {
                            Console.WriteLine($"Creating image file: {outputFile}");
                        }
                    }

                    // Close the new file to complete PDF creation
                    toolkit.CloseInputFile();
                }
                else
                {
                    WriteResult($"Error opening input file: {result.ToString()}", toolkit);
                    return;
                }
            }

            // Process Complete
            WriteResult("Success!");
        }