Initial replacement of old repository.

This commit is contained in:
Simon Martens
2021-09-15 13:31:10 +02:00
commit 3125edf027
222 changed files with 582725 additions and 0 deletions

View File

@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk.WindowsDesktop">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
<ItemGroup>
<Compile Update="Form1.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="Form1.Designer.cs">
<DependentUpon>Form1.cs</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Update="Form1.resx">
<DependentUpon>Form1.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
</Project>

123
DocxToPdf/Form1.Designer.cs generated Normal file
View File

@@ -0,0 +1,123 @@
namespace DocAcrobat
{
partial class Form1
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.PathBox = new System.Windows.Forms.TextBox();
this.ConvertButton = new System.Windows.Forms.Button();
this.OpenButton = new System.Windows.Forms.Button();
this.folderBrowserDialog1 = new System.Windows.Forms.FolderBrowserDialog();
this.backgroundWorker = new System.ComponentModel.BackgroundWorker();
this.statusStrip1 = new System.Windows.Forms.StatusStrip();
this.StatusLabel = new System.Windows.Forms.ToolStripStatusLabel();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
//
// PathBox
//
this.PathBox.Enabled = false;
this.PathBox.Location = new System.Drawing.Point(12, 12);
this.PathBox.Name = "PathBox";
this.PathBox.Size = new System.Drawing.Size(988, 26);
this.PathBox.TabIndex = 0;
//
// ConvertButton
//
this.ConvertButton.Location = new System.Drawing.Point(1134, 9);
this.ConvertButton.Name = "ConvertButton";
this.ConvertButton.Size = new System.Drawing.Size(139, 32);
this.ConvertButton.TabIndex = 2;
this.ConvertButton.Text = "Konvertieren";
this.ConvertButton.UseVisualStyleBackColor = true;
this.ConvertButton.Click += new System.EventHandler(this.ConvertButton_Click);
//
// OpenButton
//
this.OpenButton.Location = new System.Drawing.Point(1027, 9);
this.OpenButton.Name = "OpenButton";
this.OpenButton.Size = new System.Drawing.Size(101, 32);
this.OpenButton.TabIndex = 3;
this.OpenButton.Text = "Öffnen";
this.OpenButton.UseVisualStyleBackColor = true;
this.OpenButton.Click += new System.EventHandler(this.OpenButton_Click);
//
// statusStrip1
//
this.statusStrip1.ImageScalingSize = new System.Drawing.Size(24, 24);
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.StatusLabel});
this.statusStrip1.Location = new System.Drawing.Point(0, 74);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(1285, 32);
this.statusStrip1.SizingGrip = false;
this.statusStrip1.TabIndex = 5;
this.statusStrip1.Text = "statusStrip1";
//
// StatusLabel
//
this.StatusLabel.Name = "StatusLabel";
this.StatusLabel.Overflow = System.Windows.Forms.ToolStripItemOverflow.Never;
this.StatusLabel.Size = new System.Drawing.Size(530, 25);
this.StatusLabel.Text = "Bereit. Dateien mit gleichem Namen werden mglw. überschrieben.";
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(1285, 106);
this.Controls.Add(this.statusStrip1);
this.Controls.Add(this.OpenButton);
this.Controls.Add(this.ConvertButton);
this.Controls.Add(this.PathBox);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(1307, 162);
this.MinimizeBox = false;
this.MinimumSize = new System.Drawing.Size(1307, 162);
this.Name = "Form1";
this.ShowIcon = false;
this.Text = "DocAcrobat";
this.Load += new System.EventHandler(this.Form1_Load);
this.statusStrip1.ResumeLayout(false);
this.statusStrip1.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox PathBox;
private System.Windows.Forms.Button ConvertButton;
private System.Windows.Forms.Button OpenButton;
private System.Windows.Forms.FolderBrowserDialog folderBrowserDialog1;
private System.ComponentModel.BackgroundWorker backgroundWorker;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripStatusLabel StatusLabel;
}
}

159
DocxToPdf/Form1.cs Normal file
View File

@@ -0,0 +1,159 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Microsoft.Office.Interop.Word;
namespace DocAcrobat
{
public partial class Form1 : Form
{
double progess = 0;
double file = 0;
public Form1()
{
InitializeComponent();
ConvertButton.Enabled = false;
InitializeBackgroundWorker();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void OpenButton_Click(object sender, EventArgs e)
{
if (folderBrowserDialog1.ShowDialog() == DialogResult.OK)
{
PathBox.Text = folderBrowserDialog1.SelectedPath;
ConvertButton.Enabled = true;
}
}
public static bool PrepareWordAutomation()
{
////Wenn man das Programm abbricht, bleiben leider manchmal Wordinstanzen aktiv, die dann Dokumente blokieren. Deswegen kann man das ruig öfter laufen lassen.
//if (Process.GetProcessesByName("winword").Any())
//{
// if (Process.GetProcessesByName("winword").Any())
// {
// var answer = Helper.SayYesNo("Also es scheint immernoch Word zu laufen. Veilleicht ist das ein verwaister Prozess. Wenn du dir sicher bist, dass du Word nicht laufen hast, dann mach einfach weiter. Weitermachen?");
// if (answer == System.Windows.MessageBoxResult.No)
// {
// return false;
// }
// }
//}
return true;
}
public static void DocToPdf(string path, Microsoft.Office.Interop.Word.Application appWORD)
{
string dir = Path.GetDirectoryName(path) + @"\";
var file = Path.GetFileName(path);
var pdfDirectory = Directory.CreateDirectory(dir + @"pdf\").FullName;
var pdfFile = file.Replace(".docx", ".pdf");
Document wordDocument = appWORD.Documents.Open(path, ConfirmConversions: false, ReadOnly: true, AddToRecentFiles: false, Visible: true);
wordDocument.ExportAsFixedFormat((pdfDirectory + pdfFile), WdExportFormat.wdExportFormatPDF);
wordDocument.Close(false);
wordDocument = null;
GC.Collect();
}
private void ConvertButton_Click(object sender, EventArgs e)
{
if (backgroundWorker.IsBusy != true)
{
ConvertButton.Enabled = false;
OpenButton.Enabled = false;
StatusLabel.Text = "Konvertiere...";
backgroundWorker.RunWorkerAsync();
}
}
private void Convert(string paths, BackgroundWorker worker, DoWorkEventArgs e)
{
if (PrepareWordAutomation())
{
var appWORD = new Microsoft.Office.Interop.Word.Application();
appWORD.Visible = false;
appWORD.ScreenUpdating = false;
var files = System.IO.Directory.GetFiles(paths, "*.doc");
var files2 = System.IO.Directory.GetFiles(paths, "*.docx");
file = 100.0 / (files.Length + files2.Length);
foreach (string path in files.Concat(files2))
{
DocToPdf(path, appWORD);
progess += file;
worker.ReportProgress((int)Math.Round(progess));
}
appWORD.Quit(false);
appWORD = null;
GC.Collect();
GC.WaitForPendingFinalizers();
}
}
private void InitializeBackgroundWorker()
{
backgroundWorker.WorkerReportsProgress = true;
backgroundWorker.WorkerSupportsCancellation = true;
backgroundWorker.DoWork +=
new DoWorkEventHandler(backgroundWorker_DoWork);
backgroundWorker.RunWorkerCompleted +=
new RunWorkerCompletedEventHandler(
backgroundWorker_RunWorkerCompleted);
backgroundWorker.ProgressChanged +=
new ProgressChangedEventHandler(
backgroundWorker_ProgressChanged);
}
private void backgroundWorker_DoWork(object sender,
DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
Convert(PathBox.Text, worker, e);
}
private void backgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e)
{
StatusLabel.Text = ("Das Konvertieren vieler Dateien kann eine Weile in Anspruch nehmen. Fortschritt: " + e.ProgressPercentage.ToString() + "%");
}
private void backgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
if (e.Cancelled == true)
{
StatusLabel.Text = "Canceled!";
}
else if (e.Error != null)
{
StatusLabel.Text = "Error: " + e.Error.Message;
}
else
{
StatusLabel.Text = "Done!";
}
ConvertButton.Enabled = true;
OpenButton.Enabled = true;
progess = 0;
}
}
}

129
DocxToPdf/Form1.resx Normal file
View File

@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="folderBrowserDialog1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="backgroundWorker.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>255, 17</value>
</metadata>
<metadata name="statusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>475, 17</value>
</metadata>
</root>

23
DocxToPdf/Program.cs Normal file
View File

@@ -0,0 +1,23 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace DocxToPdf
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}