commit 0c9c5cb085850606dda542fd01a26fc60cbcbfb5 Author: dev-mkoebis Date: Thu Jul 9 15:43:52 2026 +0200 Initial Commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..110754f --- /dev/null +++ b/.gitignore @@ -0,0 +1,191 @@ +## Ignore Visual Studio temporary files, build results, and +## files generated by popular Visual Studio add-ons. + +# User-specific files +*.suo +*.user +*.sln.docstates +*.cache +*.v2 + +# Build results +[Dd]ebug/ +[Dd]ebugPublic/ +[Rr]elease/ +x64/ +build/ +bld/ +[Bb]in/ +[Oo]bj/ + +# Roslyn cache directories +*.ide/ + +# MSTest test Results +[Tt]est[Rr]esult*/ +[Bb]uild[Ll]og.* + +#NUNIT +*.VisualState.xml +TestResult.xml + +# Build Results of an ATL Project +[Dd]ebugPS/ +[Rr]eleasePS/ +dlldata.c + +*_i.c +*_p.c +*_i.h +*.ilk +*.meta +*.obj +*.pch +*.pdb +*.pgc +*.pgd +*.rsp +*.sbr +*.tlb +*.tli +*.tlh +*.tmp +*.tmp_proj +*.log +*.vspscc +*.vssscc +.builds +*.pidb +*.svclog +*.scc + +# Chutzpah Test files +_Chutzpah* + +# Visual C++ cache files +ipch/ +*.aps +*.ncb +*.opensdf +*.sdf +*.cachefile + +# Visual Studio profiler +*.psess +*.vsp +*.vspx + +# TFS 2012 Local Workspace +$tf/ + +# Guidance Automation Toolkit +*.gpState + +# ReSharper is a .NET coding add-in +_ReSharper*/ +*.[Rr]e[Ss]harper +*.DotSettings.user + +# JustCode is a .NET coding addin-in +.JustCode + +# TeamCity is a build add-in +_TeamCity* + +# DotCover is a Code Coverage Tool +*.dotCover + +# NCrunch +_NCrunch_* +.*crunch*.local.xml + +# MightyMoose +*.mm.* +AutoTest.Net/ + +# Web workbench (sass) +.sass-cache/ + +# Installshield output folder +[Ee]xpress/ + +# DocProject is a documentation generator add-in +DocProject/buildhelp/ +DocProject/Help/*.HxT +DocProject/Help/*.HxC +DocProject/Help/*.hhc +DocProject/Help/*.hhk +DocProject/Help/*.hhp +DocProject/Help/Html2 +DocProject/Help/html + +# Click-Once directory +publish/ + +# Publish Web Output +*.[Pp]ublish.xml +*.azurePubxml +## TODO: Comment the next line if you want to checkin your +## web deploy settings but do note that will include unencrypted +## passwords +#*.pubxml + +# NuGet Packages Directory +packages/* +## TODO: If the tool you use requires repositories.config +## uncomment the next line +#!packages/repositories.config + +# Enable "build/" folder in the NuGet Packages folder since +# NuGet packages use it for MSBuild targets. +# This line needs to be after the ignore of the build folder +# (and the packages folder if the line above has been uncommented) +!packages/build/ + +# Windows Azure Build Output +csx/ +*.build.csdef + +# Windows Store app package directory +AppPackages/ + +# Others +sql/ +*.Cache +ClientBin/ +[Ss]tyle[Cc]op.* +~$* +*~ +*.dbmdl +*.dbproj.schemaview +*.pfx +*.publishsettings +node_modules/ + +# RIA/Silverlight projects +Generated_Code/ + +# Backup & report files from converting an old project file +# to a newer Visual Studio version. Backup files are not needed, +# because we have git ;-) +_UpgradeReport_Files/ +Backup*/ +UpgradeLog*.XML +UpgradeLog*.htm + +# SQL Server files +*.mdf +*.ldf + +# Business Intelligence projects +*.rdl.data +*.bim.layout +*.bim_*.settings + +# Microsoft Fakes +FakesAssemblies/ + +# LightSwitch generated files +GeneratedArtifacts/ +_Pvt_Extensions/ +ModelManifest.xml \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7a4abc0 --- /dev/null +++ b/README.md @@ -0,0 +1,92 @@ +# splitpdf + + + +## Getting started + +To make it easy for you to get started with GitLab, here's a list of recommended next steps. + +Already a pro? Just edit this README.md and make it your own. Want to make it easy? [Use the template at the bottom](#editing-this-readme)! + +## Add your files + +- [ ] [Create](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file) or [upload](https://docs.gitlab.com/ee/user/project/repository/web_editor.html#upload-a-file) files +- [ ] [Add files using the command line](https://docs.gitlab.com/ee/gitlab-basics/add-file.html#add-a-file-using-the-command-line) or push an existing Git repository with the following command: + +``` +cd existing_repo +git remote add origin https://gitserv.stadtdo.de/fb61/entwicklung/splitpdf.git +git branch -M main +git push -uf origin main +``` + +## Integrate with your tools + +- [ ] [Set up project integrations](https://gitserv.stadtdo.de/fb61/entwicklung/splitpdf/-/settings/integrations) + +## Collaborate with your team + +- [ ] [Invite team members and collaborators](https://docs.gitlab.com/ee/user/project/members/) +- [ ] [Create a new merge request](https://docs.gitlab.com/ee/user/project/merge_requests/creating_merge_requests.html) +- [ ] [Automatically close issues from merge requests](https://docs.gitlab.com/ee/user/project/issues/managing_issues.html#closing-issues-automatically) +- [ ] [Enable merge request approvals](https://docs.gitlab.com/ee/user/project/merge_requests/approvals/) +- [ ] [Set auto-merge](https://docs.gitlab.com/ee/user/project/merge_requests/merge_when_pipeline_succeeds.html) + +## Test and Deploy + +Use the built-in continuous integration in GitLab. + +- [ ] [Get started with GitLab CI/CD](https://docs.gitlab.com/ee/ci/quick_start/index.html) +- [ ] [Analyze your code for known vulnerabilities with Static Application Security Testing(SAST)](https://docs.gitlab.com/ee/user/application_security/sast/) +- [ ] [Deploy to Kubernetes, Amazon EC2, or Amazon ECS using Auto Deploy](https://docs.gitlab.com/ee/topics/autodevops/requirements.html) +- [ ] [Use pull-based deployments for improved Kubernetes management](https://docs.gitlab.com/ee/user/clusters/agent/) +- [ ] [Set up protected environments](https://docs.gitlab.com/ee/ci/environments/protected_environments.html) + +*** + +# Editing this README + +When you're ready to make this README your own, just edit this file and use the handy template below (or feel free to structure it however you want - this is just a starting point!). Thank you to [makeareadme.com](https://www.makeareadme.com/) for this template. + +## Suggestions for a good README +Every project is different, so consider which of these sections apply to yours. The sections used in the template are suggestions for most open source projects. Also keep in mind that while a README can be too long and detailed, too long is better than too short. If you think your README is too long, consider utilizing another form of documentation rather than cutting out information. + +## Name +Choose a self-explaining name for your project. + +## Description +Let people know what your project can do specifically. Provide context and add a link to any reference visitors might be unfamiliar with. A list of Features or a Background subsection can also be added here. If there are alternatives to your project, this is a good place to list differentiating factors. + +## Badges +On some READMEs, you may see small images that convey metadata, such as whether or not all the tests are passing for the project. You can use Shields to add some to your README. Many services also have instructions for adding a badge. + +## Visuals +Depending on what you are making, it can be a good idea to include screenshots or even a video (you'll frequently see GIFs rather than actual videos). Tools like ttygif can help, but check out Asciinema for a more sophisticated method. + +## Installation +Within a particular ecosystem, there may be a common way of installing things, such as using Yarn, NuGet, or Homebrew. However, consider the possibility that whoever is reading your README is a novice and would like more guidance. Listing specific steps helps remove ambiguity and gets people to using your project as quickly as possible. If it only runs in a specific context like a particular programming language version or operating system or has dependencies that have to be installed manually, also add a Requirements subsection. + +## Usage +Use examples liberally, and show the expected output if you can. It's helpful to have inline the smallest example of usage that you can demonstrate, while providing links to more sophisticated examples if they are too long to reasonably include in the README. + +## Support +Tell people where they can go to for help. It can be any combination of an issue tracker, a chat room, an email address, etc. + +## Roadmap +If you have ideas for releases in the future, it is a good idea to list them in the README. + +## Contributing +State if you are open to contributions and what your requirements are for accepting them. + +For people who want to make changes to your project, it's helpful to have some documentation on how to get started. Perhaps there is a script that they should run or some environment variables that they need to set. Make these steps explicit. These instructions could also be useful to your future self. + +You can also document commands to lint the code or run tests. These steps help to ensure high code quality and reduce the likelihood that the changes inadvertently break something. Having instructions for running tests is especially helpful if it requires external setup, such as starting a Selenium server for testing in a browser. + +## Authors and acknowledgment +Show your appreciation to those who have contributed to the project. + +## License +For open source projects, say how it is licensed. + +## Project status +If you have run out of energy or time for your project, put a note at the top of the README saying that development has slowed down or stopped completely. Someone may choose to fork your project or volunteer to step in as a maintainer or owner, allowing your project to keep going. You can also make an explicit request for maintainers. diff --git a/SplitPdf.Testing/PdfTests.cs b/SplitPdf.Testing/PdfTests.cs new file mode 100644 index 0000000..94b5bcc --- /dev/null +++ b/SplitPdf.Testing/PdfTests.cs @@ -0,0 +1,106 @@ +using NUnit.Framework; +using System.Collections.Generic; +using System.IO; +using System.Linq; + +namespace SplitPdf.Testing +{ + public class PdfTests + { + List splittedVorgänge; + + [SetUp] + public void Setup() + { + this.splittedVorgänge = new List() + { + "Rheinlanddamm 24 632-1-116 Zeichnungen 1-20 - Teil 1", + "Rheinlanddamm 24 632-1-116 Zeichnungen 1-20 - Teil 2", + "Rheinlanddamm 24 632-1-116 Zeichnungen 1-20 - Teil 3" + }; + + Pdf.splittedVorgänge = this.splittedVorgänge; + } + + [Test] + public void CreateImportFilesTest() + { + Pdf.GenerateNewImportFiles(splittedVorgänge); + var files = Directory.GetFiles(@"D:\S2C_Testing\import"); + bool newimportFile = false; + + foreach (var item in files) + { + if(item.Contains("new")) + { + newimportFile = true; + } + } + Assert.IsTrue(newimportFile); + } + + [Test] + public void CopyFilesBigger30MBTest() + { + var path = @"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\WORKING_DIR\Current"; + var destination = @"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\30MB Schranke"; + var files = Directory.GetFiles(path,"*.pdf", SearchOption.AllDirectories); + foreach (var file in files) + { + var fileInfo = new FileInfo(file); + if(fileInfo.Length>33000000) + { + File.Copy(file, Path.Combine(destination, fileInfo.Name)); + } + } + } + + [Test] + public void CopyFilesSmaller30MBTest() + { + var path = @"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\WORKING_DIR\Current\alle Dokumente"; + var destination = @"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\WORKING_DIR\Current"; + var files = Directory.GetFiles(path, "*.pdf", SearchOption.AllDirectories); + foreach (var file in files) + { + var fileInfo = new FileInfo(file); + if (fileInfo.Length < 33000000) + { + File.Copy(file, Path.Combine(destination, fileInfo.Name)); + } + } + } + + [Test] + public void MoveFoldersWithPlusOrCommaTest() + { + var path = @"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\WORKING_DIR"; + var destination = @"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\Aussortiert_Plus_Komma"; + var files = Directory.GetFiles(path, "*.pdf",SearchOption.AllDirectories); + + + foreach (var file in files) + { + var info = new FileInfo(file); + if(info.Name.Contains('+') || info.Name.Contains(',')) + { + File.Move(file,Path.Combine(destination, Path.GetFileName(file))); + } + } + + } + + [Test] + public void PullFilesTest() + { + string extension = "*.pdf"; + var files = Directory.GetFiles(@"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\COMPRESSOR_DONE", extension,SearchOption.AllDirectories).ToList(); + int countFiles = 0; + foreach (var file in files) + { + File.Copy(file, Path.Combine(@"S:\Bauvorhaben\0_EIGENSCAN\Nachbearbeitung\Aussortiert_Plus_Komma", Path.GetFileName(file))); + countFiles++; + } + } + } +} \ No newline at end of file diff --git a/SplitPdf.Testing/SplitPdf.Testing.csproj b/SplitPdf.Testing/SplitPdf.Testing.csproj new file mode 100644 index 0000000..0574c58 --- /dev/null +++ b/SplitPdf.Testing/SplitPdf.Testing.csproj @@ -0,0 +1,20 @@ + + + + netcoreapp3.1 + + false + + + + + + + + + + + + + + diff --git a/SplitPdf.sln b/SplitPdf.sln new file mode 100644 index 0000000..fcbcf87 --- /dev/null +++ b/SplitPdf.sln @@ -0,0 +1,31 @@ +ï»ż +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.31515.178 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SplitPdf", "SplitPdfConsole\SplitPdf.csproj", "{062CCF60-6E06-4116-B653-06CD1D1FA822}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SplitPdf.Testing", "SplitPdf.Testing\SplitPdf.Testing.csproj", "{79D07108-494C-4FAE-867E-6E5C4540DA3B}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {062CCF60-6E06-4116-B653-06CD1D1FA822}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {062CCF60-6E06-4116-B653-06CD1D1FA822}.Debug|Any CPU.Build.0 = Debug|Any CPU + {062CCF60-6E06-4116-B653-06CD1D1FA822}.Release|Any CPU.ActiveCfg = Release|Any CPU + {062CCF60-6E06-4116-B653-06CD1D1FA822}.Release|Any CPU.Build.0 = Release|Any CPU + {79D07108-494C-4FAE-867E-6E5C4540DA3B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {79D07108-494C-4FAE-867E-6E5C4540DA3B}.Debug|Any CPU.Build.0 = Debug|Any CPU + {79D07108-494C-4FAE-867E-6E5C4540DA3B}.Release|Any CPU.ActiveCfg = Release|Any CPU + {79D07108-494C-4FAE-867E-6E5C4540DA3B}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {055E8019-6189-49E2-8ECD-CB017107C065} + EndGlobalSection +EndGlobal diff --git a/SplitPdfConsole/Pdf.cs b/SplitPdfConsole/Pdf.cs new file mode 100644 index 0000000..2b02286 --- /dev/null +++ b/SplitPdfConsole/Pdf.cs @@ -0,0 +1,246 @@ +ï»żusing PdfSharp.Pdf; +using PdfSharp.Pdf.IO; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Text; + +namespace SplitPdf +{ + public class Pdf + { + public static List splittedVorgĂ€nge = new List(); + + public static void GenerateNewImportFiles(List vorgĂ€nge) + { + WriteNewImportFiles(vorgĂ€nge); + } + + /// + /// Schreibt neue Importfiles, falls in einer der Importfiles ein geteilter Vorgang gefunden wurde + /// + /// + public static void WriteNewImportFiles(List vorgĂ€nge) + { + string newImportFilePath = string.Empty; + DirectoryInfo info; + + info = new DirectoryInfo(Program.importFilesPath); + var files = info.GetFiles(); + + StringBuilder builder = new StringBuilder(); + + bool found = false; + string line = string.Empty; + + for (int i = 0; i < vorgĂ€nge.Count; i++) + { + if (splittedVorgĂ€nge.Count != 0) + { + string addedTeile = string.Empty; + string vorgang = string.Concat(vorgĂ€nge[i], ".pdf");//Dateiname in Importdatei + + try + { + foreach (var file in files) //CM-File und Inpro-File + { + //Letzte ID in Textdatei + int lastId = Convert.ToInt32(File.ReadLines(file.FullName).Last().Split(';').FirstOrDefault()); + + builder.Clear(); + + Console.WriteLine("checking import... {0}", file.Name); + using (StreamReader sr = new StreamReader(file.FullName)) + { + while (!sr.EndOfStream) + { + line = sr.ReadLine(); + + //ist Vorgang in aktueller Zeile enthalten? + if (line.Contains(vorgang)) + { + //Zerteile Zeile und ĂŒberspringe letztes Element, da Dateiname + string cuttedLine = string.Join(';', line.Split(';').SkipLast(1)); + addedTeile = AddSplittedVorgĂ€nge(cuttedLine, lastId, vorgang); + found = true; + continue; + } + + builder.AppendLine(line); + + //Wenn Ende erreicht, dann Teile anhĂ€ngen + if (sr.EndOfStream) + { + builder.AppendLine(addedTeile); + } + } + } + if (found) + { + using (StreamWriter sw = new StreamWriter(file.FullName)) + { + sw.Write(""); + sw.WriteLine(builder.ToString().Trim()); + builder.Clear(); + found = false; + } + } + } + } + catch (Exception ex) + { + Console.WriteLine(ex.InnerException); + throw; + } + } + } + } + + /// + /// Sucht in liste der geteilten Dateien nach aktuellem Vorgang und inkrementiert letzte ID aus Importdatei entsprechend der Anzahl an Teilen. + /// Entfernt gleichzeitig Vorgang aus Liste geteilter VorgĂ€nge. + /// + /// + /// + /// + /// + //Werden als letztes an Datei angehĂ€ngt + private static string AddSplittedVorgĂ€nge(string source, int lastId, string vorgang) + { + string result = string.Empty; + StringBuilder sb = new StringBuilder(); + + source = string.Join(';', source.Split(';').Skip(1)); + lastId++; + foreach (var splittedVorgang in splittedVorgĂ€nge.Where(x => x.Contains(vorgang.Split('.').FirstOrDefault()))) + { + sb.AppendLine(string.Concat(lastId, ";", source, ";", splittedVorgang)); + lastId++; + } + + var temp = splittedVorgĂ€nge.Where(x => !x.Contains(vorgang.Split('.').FirstOrDefault())); + splittedVorgĂ€nge = temp.ToList(); + return sb.ToString(); + } + + public static bool SplitBySize(string sourceFile, long limit, ref int teil) + { + System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + teil = 0; + int part = 1; + + try + { + PdfDocument input = PdfReader.Open(sourceFile, PdfDocumentOpenMode.Import); + PdfDocument output = new PdfDocument(); + + + string filename = Path.GetFileNameWithoutExtension(sourceFile); + bool fileCreated = false; + + string newFile = String.Format("{0} - Teil {1}.pdf", filename, part); + + //string newFilePath = Path.Combine(Path.GetDirectoryName(sourceFile), newFile); + string newFilePath = Path.Combine(@"C:\temp_out", newFile); + splittedVorgĂ€nge.Add(newFile); //FĂŒlle Liste mit splitted VorgĂ€ngen + + for (int i = 0; i < input.PageCount; i++) + { + output.AddPage(input.Pages[i]); + output.Save(newFilePath); + + if (i == input.PageCount - 1) + { + break; + } + + FileInfo info = new FileInfo(newFilePath); + + if (info.Length <= limit) + { + continue; + } + else + { + part++; + newFile = String.Format("{0} - Teil {1}.pdf", filename, part); + splittedVorgĂ€nge.Add(newFile); //FĂŒlle Liste mit splitted VorgĂ€ngen + //newFilePath = Path.Combine(Path.GetDirectoryName(sourceFile), newFile); + newFilePath = Path.Combine(@"C:\temp_out", newFile); + output = new PdfDocument(); + fileCreated = true; + } + } + return fileCreated; + + } + catch (ArgumentOutOfRangeException ex) + { + throw; + } + + } + + #region obsolete + //Zu Zwecken falls mehrere Dateien geteilt werden mĂŒssen, die zu einem Vorgang gehören z.B. Westfalendamm 100 (2GB groß) + //public static bool SplitBySize(string sourceFile, long limit, ref int teil) + //{ + // System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); + // int part = 1; + // if(teil !=0) + // { + // part = Convert.ToInt32(++teil); + // } + // try + // { + // PdfDocument input = PdfReader.Open(sourceFile, PdfDocumentOpenMode.Import); + // PdfDocument output = new PdfDocument(); + + // string filename = Path.GetFileNameWithoutExtension(sourceFile); + // bool fileCreated = false; + // string newFile = string.Empty; + + // newFile = String.Format("{0} - Teil {1}.pdf", filename, part); + // string newFilePath = Path.Combine(Path.GetDirectoryName(sourceFile), newFile); + // splittedVorgĂ€nge.Add(newFile); //FĂŒlle Liste mit splitted VorgĂ€ngen + + // for (int i = 0; i < input.PageCount; i++) + // { + // output.AddPage(input.Pages[i]); + // output.Save(newFilePath); + + // if (i == input.PageCount - 1) + // { + // break; + // } + + // FileInfo info = new FileInfo(newFilePath); + + // if (info.Length <= limit) + // { + // continue; + // } + // else + // { + // part++; + // newFile = String.Format("{0} - Teil {1}.pdf", filename, part); + // splittedVorgĂ€nge.Add(newFile); //FĂŒlle Liste mit splitted VorgĂ€ngen + // newFilePath = Path.Combine(Path.GetDirectoryName(sourceFile), newFile); + // output = new PdfDocument(); + // fileCreated = true; + // } + // } + // teil = part; + // return fileCreated; + + // } + // catch (ArgumentOutOfRangeException ex) + // { + // throw; + // } + + //} + #endregion + } +} diff --git a/SplitPdfConsole/Program.cs b/SplitPdfConsole/Program.cs new file mode 100644 index 0000000..bd4d4cc --- /dev/null +++ b/SplitPdfConsole/Program.cs @@ -0,0 +1,117 @@ +ï»żusing System; +using System.IO; +using System.Reflection; +using System.Threading; +using System.Linq; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace SplitPdf +{ + class Program + { + public static string importFilesPath = @"\\fsdeg002\DatenStA61_S\Bauvorhaben\Import"; + + //private static string sourcePdfFilesPath = @"C:\Test\Compressor_In"; + private static string sourcePdfFilesPath = @"C:\TEMP"; + + //private static string destinationPdfFilesPath = @"C:\Test\Compressor_Out"; + private static string destinationPdfFilesPath = @"C:\temp_out"; + + public static List vorgĂ€nge = new List(); + + const int LIMIT = 30000000; + static async Task Main(string[] args) + { + try + { + await SplitPdfInSubDir(sourcePdfFilesPath); + + //CopyFolderAndFiles(new DirectoryInfo(sourcePdfFilesPath), new DirectoryInfo(destinationPdfFilesPath)); + + //DeleteSourceFiles(new DirectoryInfo(sourcePdfFilesPath)); + + //Pdf.GenerateNewImportFiles(vorgĂ€nge); + } + catch (Exception ex) + { + Console.WriteLine(ex.Message); + } + } + + public static async Task SplitPdfInSubDir(string path) + { + var info = new DirectoryInfo(path); + var countDir = info.GetDirectories().Length; + bool result = false; + int teil = 0; + + if (countDir != 0) + { + foreach (var dir in info.GetDirectories()) + { + await SplitPdfInSubDir(dir.ToString()); + } + } + else + { + var count = Directory.GetFiles(path, "*.pdf").Length; + if (count != 0) + { + foreach (var file in Directory.GetFiles(path)) + { + var fi = new FileInfo(file); + vorgĂ€nge.Add(path.Split('\\').LastOrDefault()); + if (fi.Length < LIMIT)// || fi.FullName.Contains("Teil")) + continue; + Console.WriteLine("splitting... {0}", fi.Name); + + await Task.Run(() => + { + result = Pdf.SplitBySize(file, LIMIT, ref teil); + }); + + File.Delete(fi.FullName); + } + } + } + return result; + } + + public static void CopyFolderAndFiles(DirectoryInfo source, DirectoryInfo target) + { + Directory.CreateDirectory(target.FullName); + + if (source.GetFiles().Length > 1) + { + foreach (FileInfo fi in source.GetFiles().Where(x => x.FullName.Contains("Teil"))) + { + Console.WriteLine("copying... {0}", fi.Name); + fi.CopyTo(Path.Combine(target.FullName, fi.Name), true); + } + } + else + { + foreach (FileInfo fi in source.GetFiles()) + { + fi.CopyTo(Path.Combine(target.FullName, fi.Name), true); + } + } + //Directories + foreach (DirectoryInfo diSourceSubDir in source.GetDirectories()) + { + DirectoryInfo nextTargetSubDir = target.CreateSubdirectory(diSourceSubDir.Name); + + CopyFolderAndFiles(diSourceSubDir, nextTargetSubDir); + } + } + + public static void DeleteSourceFiles(DirectoryInfo source) + { + foreach (var item in source.GetDirectories()) + { + Directory.Delete(item.FullName, true); + } + } + } +} diff --git a/SplitPdfConsole/Properties/PublishProfiles/FolderProfile.pubxml b/SplitPdfConsole/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000..3c402c0 --- /dev/null +++ b/SplitPdfConsole/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,18 @@ +ï»ż + + + + Release + Any CPU + C:\Test\SplitPdf + FileSystem + netcoreapp3.1 + win-x86 + true + True + False + False + + \ No newline at end of file diff --git a/SplitPdfConsole/SplitPdf.csproj b/SplitPdfConsole/SplitPdf.csproj new file mode 100644 index 0000000..e90ab19 --- /dev/null +++ b/SplitPdfConsole/SplitPdf.csproj @@ -0,0 +1,18 @@ +ï»ż + + + Exe + netcoreapp3.1 + SplitPdf + SplitPdf + + + + + + + + + + +