Update 20250222
This commit is contained in:
89
OfficeToPDFConverter/Class1.cs
Normal file
89
OfficeToPDFConverter/Class1.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.InteropServices.ComTypes;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Office.Interop.Word;
|
||||
using Microsoft.Office.Interop.Excel;
|
||||
using System.Linq.Expressions;
|
||||
|
||||
namespace OfficeToPDFConverter
|
||||
{
|
||||
public class Converter
|
||||
{
|
||||
public string Convert_Word(string B64Word,string path)
|
||||
{
|
||||
Microsoft.Office.Interop.Word.Application w = new Microsoft.Office.Interop.Word.Application();
|
||||
|
||||
try
|
||||
{
|
||||
Helper.clsFileHelper_Converter fh = new Helper.clsFileHelper_Converter();
|
||||
string outputfile = "";
|
||||
string inputfile = "";
|
||||
string tmpfilename = DateTime.Now.ToString("yyyyMMddhhmmss");
|
||||
outputfile = tmpfilename + ".pdf";
|
||||
inputfile = tmpfilename + ".tmp";
|
||||
inputfile = path + @"\" + inputfile;
|
||||
outputfile = path + @"\" + outputfile;
|
||||
|
||||
fh.SaveBase64ToFile(B64Word, path);
|
||||
w.Documents.Open(FileName: inputfile.ToString(), ReadOnly: true);
|
||||
object oMissing = System.Reflection.Missing.Value;
|
||||
w.ActiveDocument.ExportAsFixedFormat(outputfile.ToString(), Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatPDF, false, Microsoft.Office.Interop.Word.WdExportOptimizeFor.wdExportOptimizeForPrint, Microsoft.Office.Interop.Word.WdExportRange.wdExportAllDocument, 0, 0, Microsoft.Office.Interop.Word.WdExportItem.wdExportDocumentContent, true, true, Microsoft.Office.Interop.Word.WdExportCreateBookmarks.wdExportCreateNoBookmarks, true, false, false);
|
||||
w.ActiveDocument.Saved = true;
|
||||
w.ActiveDocument.Close(SaveChanges: false);
|
||||
|
||||
w.Quit(false);
|
||||
w = null;
|
||||
string b64 = fh.Base64FromFile(outputfile);
|
||||
System.IO.File.Delete(outputfile);
|
||||
return b64;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
finally
|
||||
{
|
||||
try { w.Quit(false); } catch { }
|
||||
w = null;
|
||||
}
|
||||
|
||||
}
|
||||
public string Convert_Excel(string B64Word, string path)
|
||||
{
|
||||
Microsoft.Office.Interop.Excel.Application x = new Microsoft.Office.Interop.Excel.Application();
|
||||
try
|
||||
{
|
||||
Helper.clsFileHelper_Converter fh = new Helper.clsFileHelper_Converter();
|
||||
string outputfile = "";
|
||||
string inputfile = "";
|
||||
string tmpfilename = DateTime.Now.ToString("yyyyMMddhhmmss");
|
||||
outputfile = tmpfilename + ".pdf";
|
||||
inputfile = tmpfilename + ".tmp";
|
||||
inputfile = path + @"\" + inputfile;
|
||||
outputfile = path + @"\" + outputfile;
|
||||
|
||||
fh.SaveBase64ToFile(B64Word, path);
|
||||
x.Workbooks.Open(inputfile);
|
||||
x.ActiveWorkbook.ExportAsFixedFormat(Microsoft.Office.Interop.Excel.XlFixedFormatType.xlTypePDF, outputfile.ToString(), Microsoft.Office.Interop.Excel.XlFixedFormatQuality.xlQualityStandard);
|
||||
x.ActiveWorkbook.Close(SaveChanges: false);
|
||||
x.Quit();
|
||||
x = null;
|
||||
string b64 = fh.Base64FromFile(outputfile);
|
||||
System.IO.File.Delete(outputfile);
|
||||
return b64;
|
||||
}
|
||||
catch { return ""; }
|
||||
finally { try { x.Quit(); } catch { } x = null; }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
64
OfficeToPDFConverter/OfficeToPDFConverter.csproj
Normal file
64
OfficeToPDFConverter/OfficeToPDFConverter.csproj
Normal file
@@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{17CA2501-B872-41CC-8029-8FF4CAD425FB}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>OfficeToPDFConverter</RootNamespace>
|
||||
<AssemblyName>OfficeToPDFConverter</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<Deterministic>true</Deterministic>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Microsoft.Office.Interop.Excel, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
<HintPath>..\Client\bin\Debug\Microsoft.Office.Interop.Excel.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.Office.Interop.Word, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
<HintPath>..\Client\bin\Debug\Microsoft.Office.Interop.Word.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Office, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<EmbedInteropTypes>True</EmbedInteropTypes>
|
||||
<HintPath>..\Client\bin\Debug\Office.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Net.Http" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Class1.cs" />
|
||||
<Compile Include="clsFileHelper.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
</Project>
|
||||
36
OfficeToPDFConverter/Properties/AssemblyInfo.cs
Normal file
36
OfficeToPDFConverter/Properties/AssemblyInfo.cs
Normal file
@@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// Allgemeine Informationen über eine Assembly werden über die folgenden
|
||||
// Attribute gesteuert. Ändern Sie diese Attributwerte, um die Informationen zu ändern,
|
||||
// die einer Assembly zugeordnet sind.
|
||||
[assembly: AssemblyTitle("OfficeToPDFConverter")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("HP Inc.")]
|
||||
[assembly: AssemblyProduct("OfficeToPDFConverter")]
|
||||
[assembly: AssemblyCopyright("Copyright © HP Inc. 2025")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Durch Festlegen von ComVisible auf FALSE werden die Typen in dieser Assembly
|
||||
// für COM-Komponenten unsichtbar. Wenn Sie auf einen Typ in dieser Assembly von
|
||||
// COM aus zugreifen müssen, sollten Sie das ComVisible-Attribut für diesen Typ auf "True" festlegen.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// Die folgende GUID bestimmt die ID der Typbibliothek, wenn dieses Projekt für COM verfügbar gemacht wird
|
||||
[assembly: Guid("17ca2501-b872-41cc-8029-8ff4cad425fb")]
|
||||
|
||||
// Versionsinformationen für eine Assembly bestehen aus den folgenden vier Werten:
|
||||
//
|
||||
// Hauptversion
|
||||
// Nebenversion
|
||||
// Buildnummer
|
||||
// Revision
|
||||
//
|
||||
// Sie können alle Werte angeben oder Standardwerte für die Build- und Revisionsnummern verwenden,
|
||||
// indem Sie "*" wie unten gezeigt eingeben:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
||||
BIN
OfficeToPDFConverter/bin/Debug/OfficeToPDFConverter.dll
Normal file
BIN
OfficeToPDFConverter/bin/Debug/OfficeToPDFConverter.dll
Normal file
Binary file not shown.
BIN
OfficeToPDFConverter/bin/Debug/OfficeToPDFConverter.pdb
Normal file
BIN
OfficeToPDFConverter/bin/Debug/OfficeToPDFConverter.pdb
Normal file
Binary file not shown.
62
OfficeToPDFConverter/clsFileHelper.cs
Normal file
62
OfficeToPDFConverter/clsFileHelper.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Helper
|
||||
{
|
||||
public class clsFileHelper_Converter
|
||||
{
|
||||
public string save_temp_file(string data, string dokumentid, string temppath, string extension)
|
||||
{
|
||||
string filename = "";
|
||||
filename = temppath + DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + dokumentid + "." + extension;
|
||||
|
||||
//if (docfilename != "")
|
||||
//{
|
||||
// filename = temppath + DateTime.Now.ToString("yyyyMMddhhmmss") + "_" + docfilename;
|
||||
//}
|
||||
try
|
||||
{
|
||||
System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(data));
|
||||
return filename;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
public bool SaveBase64ToFile(string Base64String, string filename)
|
||||
{
|
||||
try
|
||||
{
|
||||
System.IO.File.WriteAllBytes(filename, Convert.FromBase64String(Base64String));
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
public Stream GenerateStreamFromString(string s)
|
||||
{
|
||||
var stream = new MemoryStream();
|
||||
var writer = new StreamWriter(stream);
|
||||
writer.Write(s);
|
||||
writer.Flush();
|
||||
stream.Position = 0;
|
||||
return stream;
|
||||
}
|
||||
|
||||
public String Base64FromFile(string filename)
|
||||
{
|
||||
Byte[] bytes = File.ReadAllBytes(filename);
|
||||
return Convert.ToBase64String(bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// <autogenerated />
|
||||
using System;
|
||||
using System.Reflection;
|
||||
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
|
||||
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
|
||||
26adcd250e91980369d40f64bc7feb6761a6219081acfe8442ae185c2c016d76
|
||||
@@ -0,0 +1,6 @@
|
||||
E:\Software-Projekte\OnDoc\OnDoc\OfficeToPDFConverter\obj\Debug\OfficeToPDFConverter.csproj.AssemblyReference.cache
|
||||
E:\Software-Projekte\OnDoc\OnDoc\OfficeToPDFConverter\obj\Debug\OfficeToPDFConverter.csproj.CoreCompileInputs.cache
|
||||
E:\Software-Projekte\OnDoc\OnDoc\OfficeToPDFConverter\bin\Debug\OfficeToPDFConverter.dll
|
||||
E:\Software-Projekte\OnDoc\OnDoc\OfficeToPDFConverter\bin\Debug\OfficeToPDFConverter.pdb
|
||||
E:\Software-Projekte\OnDoc\OnDoc\OfficeToPDFConverter\obj\Debug\OfficeToPDFConverter.dll
|
||||
E:\Software-Projekte\OnDoc\OnDoc\OfficeToPDFConverter\obj\Debug\OfficeToPDFConverter.pdb
|
||||
BIN
OfficeToPDFConverter/obj/Debug/OfficeToPDFConverter.dll
Normal file
BIN
OfficeToPDFConverter/obj/Debug/OfficeToPDFConverter.dll
Normal file
Binary file not shown.
BIN
OfficeToPDFConverter/obj/Debug/OfficeToPDFConverter.pdb
Normal file
BIN
OfficeToPDFConverter/obj/Debug/OfficeToPDFConverter.pdb
Normal file
Binary file not shown.
Reference in New Issue
Block a user