Compare commits

...

5 Commits

Author SHA1 Message Date
tomse
e330e5123a cleanup 2026-02-01 16:09:14 +01:00
tomse
990c103b39 fix output image not being loaded 2026-02-01 14:34:25 +01:00
tomse
acd0304294 add debug into to message 2026-02-01 14:29:21 +01:00
tomse
b523228679 load project file if one is existing when opening a project 2026-02-01 14:14:52 +01:00
tomse
3e074c2264 updated convert function for magazines 2026-02-01 14:08:10 +01:00

View File

@@ -340,7 +340,6 @@ namespace PDFWorkflowManager
if (Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.OrigsDir)) && !Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkDir)))
{
// Replace the selected code block with this version
try
{
string[] strOrigFiles = Directory.GetFiles(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.OrigsDir), "*.tif*");
@@ -365,7 +364,6 @@ namespace PDFWorkflowManager
btnCopyPathWorkDir.Enabled = true;
btnConvertToPDF.Enabled = true;
// Replace the selected code block with this version
try
{
string[] strWorkFiles = Directory.GetFiles(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkDir), "*.tif");
@@ -381,9 +379,9 @@ namespace PDFWorkflowManager
GC.WaitForPendingFinalizers();
}
}
catch
catch (Exception ex)
{
MessageBox.Show("Could not load preview image from Work directory.", "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Could not load preview image from Work directory." + ex.Message, "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
if (Directory.Exists(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkOutDir)))
@@ -393,23 +391,18 @@ namespace PDFWorkflowManager
string[] strOutFiles = Directory.GetFiles(Path.Combine(txtProjectDir.Text, Properties.Settings.Default.WorkOutDir), "*.tif");
if (strOutFiles.Length > 0)
{
string tempCopyPath = Path.Combine(tempDir, "preview_out.tif");
File.Copy(strOutFiles[0], tempCopyPath, true);
using (var memoryStream = new MemoryStream(File.ReadAllBytes(tempCopyPath)))
using (var memoryStream = new MemoryStream(File.ReadAllBytes(strOutFiles[0])))
using (var bitmap = new Bitmap(memoryStream))
{
// Create a copy of the bitmap to ensure the file is released
pictureBox2.Image = new Bitmap(bitmap);
}
// Release file handle so tempCopyPath is writeable
GC.Collect();
GC.WaitForPendingFinalizers();
File.Delete(tempCopyPath);
// At this point, the file is fully released
}
}
catch
catch (Exception ex)
{
MessageBox.Show("Could not load preview image from Work\\out directory.", "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show("Could not load preview image from Work\\out directory. " + ex.Message, "Error loading preview image.", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
}
@@ -791,6 +784,7 @@ namespace PDFWorkflowManager
}
*/
}
private async Task prepConvertToTempOutdir(string[] strFiles)
{
try
@@ -807,32 +801,25 @@ namespace PDFWorkflowManager
toolStripProgressBar1.Value = 0;
toolStripStatusLabel1.Text = "Converting files to jpg.";
List<Task> tasks = new List<Task>();
// Convert to jpg 300 DPI
await Task.Run(() =>
{
Parallel.ForEach(strFiles, async inputFile =>
Parallel.ForEach(strFiles, inputFile =>
{
outputFile = Path.Combine(tempJpg300Dir, Path.GetFileNameWithoutExtension(inputFile) + ".jpg");
convertToJpeg(inputFile, outputFile, 85, 300);
//Interlocked.Increment(ref toolStripProgressBar1.Value);
//UpdateProgressBar();
});
});
// Convert to jpg 150 DPI
await Task.Run(() =>
{
Parallel.ForEach(strFiles, async inputFile =>
Parallel.ForEach(strFiles, inputFile =>
{
outputFile = Path.Combine(tempJpg150Dir, Path.GetFileNameWithoutExtension(inputFile) + ".jpg");
convertToJpeg(inputFile, outputFile, 85, 150);
//Interlocked.Increment(ref toolStripProgressBar1.Value);
//UpdateProgressBar();
});
});
await Task.WhenAll(tasks);
}
finally
{
@@ -854,6 +841,7 @@ namespace PDFWorkflowManager
toolStripProgressBar1.Value++;
}
}
private async void btnConvertToPDF_Click(object sender, EventArgs e)
{
try
@@ -1434,8 +1422,58 @@ namespace PDFWorkflowManager
{
check_input_dir();
}
// Load the first .pdfproj file if it exists
string[] pdfProjFiles = Directory.GetFiles(txtProjectDir.Text, "*.pdfproj");
if (pdfProjFiles.Length > 0)
{
string firstPdfProjFile = pdfProjFiles[0];
LoadProjectFile(firstPdfProjFile);
}
}
private void LoadProjectFile(string filePath)
{
var lines = File.ReadAllLines(filePath);
var dict = new Dictionary<string, string>();
foreach (var line in lines)
{
var parts = line.Split(new[] { '=' }, 2);
if (parts.Length == 2)
dict[parts[0]] = parts[1];
}
txtFileName.Text = dict.ContainsKey("FileName") ? dict["FileName"] : "";
txtTitle.Text = dict.ContainsKey("Title") ? dict["Title"] : "";
cmbLanguage.SelectedIndex = cmbLanguage.FindStringExact(dict.ContainsKey("Language") ? dict["Language"] : "");
txtLanguages.Text = dict.ContainsKey("Languages") ? dict["Languages"] : "";
txtType.Text = dict.ContainsKey("Type") ? dict["Type"] : "";
txtPublisher.Text = dict.ContainsKey("Publisher") ? dict["Publisher"] : "";
txtAuthor.Text = dict.ContainsKey("Author") ? dict["Author"] : "";
txtISBN.Text = dict.ContainsKey("ISBN") ? dict["ISBN"] : "";
txtDate.Text = dict.ContainsKey("Date") ? dict["Date"] : "";
txtPageCount.Text = dict.ContainsKey("PageCount") ? dict["PageCount"] : "";
cmbResolution.SelectedIndex = cmbResolution.FindStringExact(dict.ContainsKey("Resolution") ? dict["Resolution"] : "");
checkPhotocopy.Checked = dict.ContainsKey("Photocopy") ? dict["Photocopy"] == "True" : false;
checkReplace.Checked = dict.ContainsKey("Replace") ? dict["Replace"] == "True" : false;
txtPartnumber.Text = dict.ContainsKey("Partnumber") ? dict["Partnumber"] : "";
if (int.TryParse(dict.ContainsKey("Quality") ? dict["Quality"] : "4", out int quality))
trackBar1.Value = Math.Max(trackBar1.Minimum, Math.Min(trackBar1.Maximum, quality));
txtContributor.Text = dict.ContainsKey("Contributor") ? dict["Contributor"] : "";
txtContributorURL.Text = dict.ContainsKey("ContributorURL") ? dict["ContributorURL"] : "";
txtPostProcessor.Text = dict.ContainsKey("PostProcessor") ? dict["PostProcessor"] : "";
txtTimeSpent.Text = dict.ContainsKey("TimeSpent") ? dict["TimeSpent"] : "";
txtPDFAuthor.Text = dict.ContainsKey("PDFMetaAuthor") ? dict["PDFMetaAuthor"] : "";
txtPDFKeywords.Text = dict.ContainsKey("PDFKeywords") ? dict["PDFKeywords"] : "";
cmbBanner.SelectedIndex = cmbBanner.FindStringExact(dict.ContainsKey("Banner") ? dict["Banner"] : "");
chkMagazines.Checked = dict.ContainsKey("Magazine") ? dict["Magazine"] == "True" : false;
checkSimplex.Checked = dict.ContainsKey("Simplex") ? dict["Simplex"] == "True" : false;
txtProjectDir.Text = dict.ContainsKey("ProjectDir") ? dict["ProjectDir"] : "";
toolStripStatusLabel1.Text = "Project file loaded: " + filePath;
}
private void loadToolStripMenuItem_Click(object sender, EventArgs e)
{
using (OpenFileDialog openFileDialog = new OpenFileDialog())
@@ -1484,7 +1522,7 @@ namespace PDFWorkflowManager
txtProjectDir.Text = dict.ContainsKey("ProjectDir") ? dict["ProjectDir"] : "";
// MessageBox.Show("Loaded file: " + loadedProjectFilePath, "File Loaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
toolStripStatusLabel1.Text = "Project file loaded: ";
toolStripStatusLabel1.Text = "Project file loaded.";
}
}
}