{"id":31904483,"url":"https://github.com/cwksc/multiple-file-pdf-converter","last_synced_at":"2025-10-13T13:50:25.197Z","repository":{"id":244524934,"uuid":"815492280","full_name":"CWKSC/multiple-file-pdf-converter","owner":"CWKSC","description":null,"archived":false,"fork":false,"pushed_at":"2025-04-17T08:39:36.000Z","size":15,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-17T20:28:47.285Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CWKSC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2024-06-15T10:17:27.000Z","updated_at":"2025-04-17T08:39:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"890b0029-0cfa-47fb-bd9c-8ac9c24bd7f7","html_url":"https://github.com/CWKSC/multiple-file-pdf-converter","commit_stats":null,"previous_names":["cwksc/multiple_file_pdf_converter","cwksc/multiple-file-pdf-converter"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CWKSC/multiple-file-pdf-converter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWKSC%2Fmultiple-file-pdf-converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWKSC%2Fmultiple-file-pdf-converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWKSC%2Fmultiple-file-pdf-converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWKSC%2Fmultiple-file-pdf-converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CWKSC","download_url":"https://codeload.github.com/CWKSC/multiple-file-pdf-converter/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CWKSC%2Fmultiple-file-pdf-converter/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279015357,"owners_count":26085686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-13T02:00:06.723Z","response_time":61,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-10-13T13:49:22.987Z","updated_at":"2025-10-13T13:50:25.193Z","avatar_url":"https://github.com/CWKSC.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# multiple-file-pdf-converter\n\n\u003e [!NOTE]\n\u003e \n\u003e Created when I am in Higher Diploma\n\u003e \n\u003e Teacher gives a lot of doc and ppt, open those file is slow\n\u003e \n\u003e pdf can open in web browser, this is much convenient\n\u003e \n\n\u003e [!NOTE]\n\u003e \n\u003e The project is old (2020), I just recreated to update project from:\n\u003e \n\u003e https://github.com/CWKSC/multithread_pdf_converter_backup\n\u003e \n\u003e In fact I don't think it really run in multithread, so I rename it to multiple-file in this repo\n\n## Expected output\n\n```\n[1 / 3] aaa.pdf\n[2 / 3] bbb.pdf\n[3 / 3] ccc.pdf\n\nAll work finsih! Spent 7.5423706 seconds\nPress any Enter to exit ...\n```\n\n## Source code\n\n```csharp\nusing Microsoft.Office.Interop.PowerPoint;\nusing Microsoft.Office.Interop.Word;\nusing System;\nusing System.Diagnostics;\nusing System.Windows.Forms;\nusing Task = System.Threading.Tasks.Task;\n\nnamespace multiple_file_pdf_converter\n{\n    public class FileDialog\n    {\n        public static string[] GetFilepaths()\n        {\n            var fileDialog = new OpenFileDialog\n            {\n                Multiselect = true,\n                Title = \"Please select doc, docx, ppt, pptx files that need to be converted to pdf\",\n                Filter = \"(*.doc, *.docx, *.ppt, *pptx)|*.doc;*.docx;*.ppt;*.pptx\"\n            };\n\n            var isOk = fileDialog.ShowDialog();\n            fileDialog.Dispose();\n            if (isOk != DialogResult.OK) { Environment.Exit(1); }\n\n            return fileDialog.FileNames;\n        }\n    }\n\n    public class Program\n    {\n        [STAThread]\n        static void Main(string[] args)\n        {\n            var filepaths = FileDialog.GetFilepaths();\n            totalWork = filepaths.Length;\n\n            var stopwatch = Stopwatch.StartNew();\n\n            Task[] tasks = new Task[totalWork];\n\n            for (int i = 0; i \u003c totalWork; i++)\n            {\n                string filepath = filepaths[i];\n\n                string extension = System.IO.Path.GetExtension(filepath);\n\n                string sourcePath = filepath;\n                string targetPath = filepath.Substring(0, filepath.Length - extension.Length) + \".pdf\";\n\n                if (IsWord(extension))\n                {\n                    tasks[i] = Task.Run(() =\u003e WordToPDF(sourcePath, targetPath));\n                }\n                else if (IsPowerPoint(extension))\n                {\n                    tasks[i] = Task.Run(() =\u003e PowerPointToPDF(sourcePath, targetPath));\n                }\n            }\n\n            Task.WhenAll(tasks).Wait();\n\n            stopwatch.Stop();\n            Console.WriteLine(\"\\nAll work finsih! Spent \" + stopwatch.Elapsed.TotalSeconds + \" seconds\");\n            Console.Write(\"Press any Enter to exit ...\");\n            Console.ReadLine();\n        }\n\n        public static bool IsWord(string extension) =\u003e extension.Equals(\".doc\") || extension.Equals(\".docx\");\n        public static bool IsPowerPoint(string extension) =\u003e extension.Equals(\".ppt\") || extension.Equals(\".pptx\");\n\n        public static void WordToPDF(string sourcePath, string targetPath)\n        {\n            Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();\n            Document document = null;\n            try\n            {\n                application.Visible = false;\n                document = application.Documents.Open(sourcePath);\n                document.ExportAsFixedFormat(targetPath, WdExportFormat.wdExportFormatPDF);\n            }\n            catch (Exception ex)\n            {\n                Console.WriteLine(ex.Message);\n            }\n            finally\n            {\n                FinishedWorkAddOne_ShowProgress(targetPath);\n                document.Close();\n                application.Quit();\n            }\n        }\n\n        public static void PowerPointToPDF(string sourcePath, string targetPath)\n        {\n            Microsoft.Office.Interop.PowerPoint.Application application = new Microsoft.Office.Interop.PowerPoint.Application();\n            Presentation presentation = application.Presentations.Open(sourcePath, WithWindow: Microsoft.Office.Core.MsoTriState.msoFalse);\n            try\n            {\n                presentation.ExportAsFixedFormat(targetPath, PpFixedFormatType.ppFixedFormatTypePDF);\n            }\n            catch (Exception ex)\n            {\n                Console.WriteLine(ex.Message);\n            }\n            finally\n            {\n                FinishedWorkAddOne_ShowProgress(targetPath);\n                presentation.Close();\n                application.Quit();\n            }\n        }\n\n\n        public static int totalWork = 0;\n\n        public static int finishedWorkNumber = 0;\n        public static readonly object Lock = new object();\n        public static void FinishedWorkAddOne_ShowProgress(string targetPath)\n        {\n            lock (Lock)\n            {\n                finishedWorkNumber++;\n                Console.WriteLine($\"[{finishedWorkNumber} / {totalWork}] {targetPath}\");\n            }\n        }\n\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcwksc%2Fmultiple-file-pdf-converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcwksc%2Fmultiple-file-pdf-converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcwksc%2Fmultiple-file-pdf-converter/lists"}