improved input dir handling
This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,23 +0,0 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "D:\\Gitea\\RCEU_PDFWorkflowManager\\PDFWorkflowManager\\",
|
||||
"Documents": [],
|
||||
"DocumentGroupContainers": [
|
||||
{
|
||||
"Orientation": 0,
|
||||
"VerticalTabListWidth": 256,
|
||||
"DocumentGroups": [
|
||||
{
|
||||
"DockedWidth": 200,
|
||||
"SelectedChildIndex": -1,
|
||||
"Children": [
|
||||
{
|
||||
"$type": "Bookmark",
|
||||
"Name": "ST:0:0:{56df62a4-05a3-4e5b-aa1a-99371ccfb997}"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
File diff suppressed because one or more lines are too long
56
PDFWorkflowManager/PDFWorkflowManager/ImageService.cs
Normal file
56
PDFWorkflowManager/PDFWorkflowManager/ImageService.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using ImageMagick;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
|
||||
namespace PDFWorkflowManager
|
||||
{
|
||||
public static class ImageService
|
||||
{
|
||||
public static void ConvertToJpeg(string sourceFileName, string destinationFileName, int compressionLevel, int dpi = 300)
|
||||
{
|
||||
using (Image sourceImage = Image.FromFile(sourceFileName))
|
||||
{
|
||||
float scaleFactor = dpi / sourceImage.HorizontalResolution;
|
||||
int newWidth = (int)(sourceImage.Width * scaleFactor);
|
||||
int newHeight = (int)(sourceImage.Height * scaleFactor);
|
||||
|
||||
using (var newImage = new Bitmap(newWidth, newHeight))
|
||||
{
|
||||
newImage.SetResolution(dpi, dpi);
|
||||
using (Graphics graphics = Graphics.FromImage(newImage))
|
||||
{
|
||||
graphics.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||||
graphics.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||
graphics.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
graphics.DrawImage(sourceImage, 0, 0, newWidth, newHeight);
|
||||
}
|
||||
EncoderParameters encoderParameters = new EncoderParameters(1);
|
||||
encoderParameters.Param[0] = new EncoderParameter(Encoder.Quality, compressionLevel);
|
||||
ImageCodecInfo jpegCodec = GetEncoderInfo(ImageFormat.Jpeg);
|
||||
newImage.Save(destinationFileName, jpegCodec, encoderParameters);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static ImageCodecInfo GetEncoderInfo(ImageFormat format)
|
||||
{
|
||||
foreach (ImageCodecInfo codec in ImageCodecInfo.GetImageDecoders())
|
||||
{
|
||||
if (codec.FormatID == format.Guid)
|
||||
return codec;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void CreateThumbnail(string fileName, string outputPath)
|
||||
{
|
||||
using (var image = new MagickImage(fileName))
|
||||
{
|
||||
var size = new MagickGeometry(240, 340) { IgnoreAspectRatio = false };
|
||||
image.Resize(size);
|
||||
image.Write(outputPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
39
PDFWorkflowManager/PDFWorkflowManager/LanguageService.cs
Normal file
39
PDFWorkflowManager/PDFWorkflowManager/LanguageService.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace PDFWorkflowManager
|
||||
{
|
||||
public static class LanguageService
|
||||
{
|
||||
public static readonly Dictionary<string, string> LanguageCodes = new Dictionary<string, string>
|
||||
{
|
||||
{"Afrikaans","af"}, {"Amharic","am"}, {"Arabic","ar"}, {"Assamese","as"}, {"Azerbaijani","az"},
|
||||
{"Belarusian","be"}, {"Bengali","bn"}, {"Bokmal","nb"}, {"Bulgarian","bg"}, {"Catalan","ca"},
|
||||
{"Chinese(Simplified)","zh-CN"}, {"Chinese(Traditional)","zh-TW"}, {"Croatian","hr"}, {"Czech","cs"},
|
||||
{"Danish","da"}, {"Dutch","nl"}, {"English","en"}, {"Estonian","et"}, {"Finnish","fi"},
|
||||
{"French","fr"}, {"German","de"}, {"Greek","el"}, {"Gujarati","gu"}, {"Hebrew","he"},
|
||||
{"Hindi","hi"}, {"Hungarian","hu"}, {"Icelandic","is"}, {"Indonesian","id"}, {"Italian","it"},
|
||||
{"Japanese","ja"}, {"Kannada","kn"}, {"Korean","ko"}, {"Latvian","lv"}, {"Lithuanian","lt"},
|
||||
{"Malayalam","ml"}, {"Marathi","mr"}, {"Nepali","ne"}, {"Norwegian","no"}, {"Oriya","or"},
|
||||
{"Polish","pl"}, {"Portuguese","pt"}, {"Punjabi","pa"}, {"Romanian","ro"}, {"Russian","ru"},
|
||||
{"Slovak","sk"}, {"Slovenian","sl"}, {"Spanish","es"}, {"Swahili","sw"}, {"Swedish","sv"},
|
||||
{"Tamil","ta"}, {"Telugu","te"}, {"Thai","th"}, {"Tibetan","bo"}, {"Turkish","tr"},
|
||||
{"Ukrainian","uk"}, {"Urdu","ur"}, {"Vietnamese","vi"}
|
||||
};
|
||||
|
||||
public static readonly Dictionary<string, string> TrainLanguage = new Dictionary<string, string>
|
||||
{
|
||||
{"Afrikaans","afr"}, {"Amharic","amh"}, {"Arabic","ara"}, {"Assamese","asm"}, {"Azerbaijani","aze"},
|
||||
{"Belarusian","bel"}, {"Bengali","ben"}, {"Bokmal","nb"}, {"Bulgarian","bul"}, {"Catalan","ca"},
|
||||
{"Chinese(Simplified)","chi_sim"}, {"Chinese(Traditional)","chi_tra"}, {"Croatian","chr"}, {"Czech","ces"},
|
||||
{"Danish","dan"}, {"Dutch","nld"}, {"English","eng"}, {"Estonian","est"}, {"Finnish","fin"},
|
||||
{"French","fra"}, {"German","deu"}, {"Greek","ell"}, {"Gujarati","guj"}, {"Hebrew","heb"},
|
||||
{"Hindi","hin"}, {"Hungarian","hun"}, {"Icelandic","isl"}, {"Indonesian","ind"}, {"Italian","ita"},
|
||||
{"Japanese","jpn"}, {"Kannada","kan"}, {"Korean","kor"}, {"Latvian","lav"}, {"Lithuanian","lit"},
|
||||
{"Malayalam","mal"}, {"Marathi","mar"}, {"Nepali","nep"}, {"Norwegian","nor"}, {"Oriya","ori"},
|
||||
{"Polish","pol"}, {"Portuguese","por"}, {"Punjabi","pan"}, {"Romanian","ron"}, {"Russian","rus"},
|
||||
{"Slovak","slk"}, {"Slovenian","slv"}, {"Spanish","spa"}, {"Swahili","swa"}, {"Swedish","swe"},
|
||||
{"Tamil","tam"}, {"Telugu","tel"}, {"Thai","tha"}, {"Tibetan","bod"}, {"Turkish","tur"},
|
||||
{"Ukrainian","ukr"}, {"Urdu","urd"}, {"Vietnamese","vie"}
|
||||
};
|
||||
}
|
||||
}
|
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace PDFWorkflowManager
|
||||
namespace PDFWorkflowManager
|
||||
{
|
||||
partial class MainForm
|
||||
{
|
||||
@@ -944,6 +943,7 @@ namespace PDFWorkflowManager
|
||||
this.txtProjectDir.Name = "txtProjectDir";
|
||||
this.txtProjectDir.Size = new System.Drawing.Size(280, 20);
|
||||
this.txtProjectDir.TabIndex = 50;
|
||||
this.txtProjectDir.Leave += new System.EventHandler(this.txtProjectDir_Leave);
|
||||
//
|
||||
// watcherOut
|
||||
//
|
||||
|
@@ -280,6 +280,16 @@ namespace PDFWorkflowManager
|
||||
checkSimplex.Enabled = true;
|
||||
}
|
||||
|
||||
// FIXME - Call a function here to check dirs and files
|
||||
check_input_dir();
|
||||
}
|
||||
|
||||
|
||||
// Check input dir for origs dir and files
|
||||
private void check_input_dir()
|
||||
{
|
||||
|
||||
Cursor.Current = Cursors.WaitCursor;
|
||||
|
||||
if (!Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.OrigsDir)))
|
||||
{
|
||||
@@ -294,7 +304,7 @@ namespace PDFWorkflowManager
|
||||
return;
|
||||
}
|
||||
|
||||
if (Directory.Exists(Path.Combine(txtProjectDir.Text, origsDir)) && !Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkDir)))
|
||||
if (Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.OrigsDir)) && !Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkDir)))
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -410,6 +420,8 @@ namespace PDFWorkflowManager
|
||||
catch
|
||||
{
|
||||
}
|
||||
|
||||
Cursor.Current = Cursors.Default;
|
||||
}
|
||||
|
||||
|
||||
@@ -1294,7 +1306,7 @@ namespace PDFWorkflowManager
|
||||
|
||||
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
|
||||
{
|
||||
MessageBox.Show("PDF Workflow Manager v0.9.3 \r\n\r\nCopyright (c) 2023-2024 https://retro-commodore.eu", "Version", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
MessageBox.Show("PDF Workflow Manager v0.9.4 \r\n\r\nCopyright (c) 2023-2025 https://retro-commodore.eu", "Version", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
}
|
||||
|
||||
private void button1_Click(object sender, EventArgs e)
|
||||
@@ -1352,5 +1364,14 @@ namespace PDFWorkflowManager
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void txtProjectDir_Leave(object sender, EventArgs e)
|
||||
{
|
||||
// Use OrigsDir from settings instead of txtOrigsDir
|
||||
if (Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.OrigsDir)))
|
||||
{
|
||||
check_input_dir();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
34
PDFWorkflowManager/PDFWorkflowManager/MetadataService.cs
Normal file
34
PDFWorkflowManager/PDFWorkflowManager/MetadataService.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
|
||||
namespace PDFWorkflowManager
|
||||
{
|
||||
public static class MetadataService
|
||||
{
|
||||
public static void WriteMetadata(string filePath, string contents)
|
||||
{
|
||||
File.WriteAllText(filePath, contents);
|
||||
}
|
||||
|
||||
public static string GetMD5(string file)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
using (var stream = File.OpenRead(file))
|
||||
{
|
||||
var hash = md5.ComputeHash(stream);
|
||||
return BitConverter.ToString(hash).Replace("-", "").ToLower();
|
||||
}
|
||||
}
|
||||
|
||||
public static string GetSHA1(string file)
|
||||
{
|
||||
using (var sha1 = SHA1.Create())
|
||||
using (var stream = File.OpenRead(file))
|
||||
{
|
||||
var hash = sha1.ComputeHash(stream);
|
||||
return BitConverter.ToString(hash).Replace("-", "").ToLower();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@@ -104,6 +104,8 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="ImageService.cs" />
|
||||
<Compile Include="LanguageService.cs" />
|
||||
<Compile Include="LanguagesForm.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
@@ -116,6 +118,8 @@
|
||||
<Compile Include="MainForm.Designer.cs">
|
||||
<DependentUpon>MainForm.cs</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="MetadataService.cs" />
|
||||
<Compile Include="PdfService.cs" />
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="SettingsForm.cs">
|
||||
|
40
PDFWorkflowManager/PDFWorkflowManager/PdfService.cs
Normal file
40
PDFWorkflowManager/PDFWorkflowManager/PdfService.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
|
||||
namespace PDFWorkflowManager
|
||||
{
|
||||
public static class PdfService
|
||||
{
|
||||
public static void MergePdfs(string pdfToolkitPath, string inputPattern, string bannerPage, string outputFile)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = pdfToolkitPath,
|
||||
Arguments = $"\"{inputPattern}\" {bannerPage} cat output \"{outputFile}\"",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
using (var process = Process.Start(startInfo))
|
||||
{
|
||||
process.WaitForExit();
|
||||
}
|
||||
}
|
||||
|
||||
public static void UpdatePdfMetadata(string ghostScriptPath, string tempFile, string metadataFile, string outputFile)
|
||||
{
|
||||
var startInfo = new ProcessStartInfo
|
||||
{
|
||||
FileName = ghostScriptPath,
|
||||
Arguments = $"-dBATCH -dNOPAUSE -dAutoRotatePages=/None -sDEVICE=pdfwrite -sOutputFile=\"{outputFile}\" \"{tempFile}\" \"{metadataFile}\"",
|
||||
UseShellExecute = false,
|
||||
RedirectStandardOutput = true,
|
||||
CreateNoWindow = true
|
||||
};
|
||||
using (var process = Process.Start(startInfo))
|
||||
{
|
||||
process.WaitForExit(120000);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user