update nach anpassungen clsgetdoc

This commit is contained in:
Stefan Hutter
2024-06-01 21:43:57 +02:00
parent 511a741857
commit f22627a1a8
571 changed files with 3770600 additions and 117 deletions

View File

@@ -10,9 +10,13 @@ using System.Text;
using System.Threading.Tasks;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Syncfusion.Pdf;
using Syncfusion.XlsIO;
using static System.Net.Mime.MediaTypeNames;
using Syncfusion.Pdf.Parsing;
using System.Xml.Linq;
using Model;
using SkiaSharp;
namespace DOCGEN
@@ -24,32 +28,115 @@ namespace DOCGEN
public clsGetDoc(string Connectionstring)
{
this.connectionstring = Connectionstring;
Lic();
}
public void Lic()
{
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NBaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXxccXVWR2VdUUZ3VkM=");
}
public string test_filetype(string filename)
{
string b64 = ConvertFileToBase64(filename);
string type = get_doc_filetype(b64);
var streamword = new MemoryStream(Convert.FromBase64String(b64));
var streamexcel = new MemoryStream(Convert.FromBase64String(b64));
try
{
if (Is_WordDocument(streamword) == true)
{
return "Word";
}
if (Is_ExcelDocument(streamexcel) == true)
{
return "Excel";
}
if (Is_PDFDocument(b64))
{
return "PDF";
}
}
catch {
return "";
}
finally {
streamword.Dispose();
streamexcel.Dispose();
}
return "";
}
public string Get_FileType(string b64)
{
var streamword = new MemoryStream(Convert.FromBase64String(b64));
var streamexcel = new MemoryStream(Convert.FromBase64String(b64));
try
{
if (Is_WordDocument(streamword) == true)
{
return "W";
}
if (Is_ExcelDocument(streamexcel) == true)
{
return "X";
}
if (Is_PDFDocument(b64))
{
return "P";
}
}
catch
{
return "";
}
finally
{
streamword.Dispose();
streamexcel.Dispose();
}
return "";
}
public string GetDocAsPDF(string Docid)
{
string doc = GetDoc(Docid);
return "";
clsdok dok = GetDoc(Docid);
try
{
switch (dok.doktype.ToUpper().Substring(0,1))
{
case "W":
return Convert_Word_To_PDF(dok.dokument.ToString());
break;
case "X":
return Convert_Excel_To_PDF(dok.dokument.ToString());
break;
case "P":
return (dok.dokument.ToString());
break;
default:
return "";
}
}
catch {
return "";
}
return dok.dokument;
}
public string GetDoc(string Docid)
public clsdok GetDoc(string Docid)
{
EDOKA_DB db = new EDOKA_DB(connectionstring);
db.GetDocumentAsBase64(Docid);
if (Docid != "")
{
return "";
}
else
{
return "";
clsdok dok = new clsdok("","","");
dok = db.GetDocumentAsBase64(Docid);
if (dok.doktype=="")
{
dok.doktype = Get_FileType(dok.dokument);
}
return dok;
}
public string ConvertFileToBase64(string fileName)
@@ -68,59 +155,95 @@ namespace DOCGEN
return ReturnValue;
}
public string get_doc_filetype(string document)
private bool Is_WordDocument(MemoryStream stream)
{
string type = "";
var stream = new MemoryStream(Convert.FromBase64String(document));
Syncfusion.DocIO.DLS.WordDocument WordDocument = new Syncfusion.DocIO.DLS.WordDocument();
try
{
Syncfusion.DocIO.DLS.WordDocument WordDocument = new Syncfusion.DocIO.DLS.WordDocument(stream);
WordDocument.Open(stream,FormatType.Automatic);
string type = "";
type = WordDocument.ActualFormatType.ToString();
WordDocument = null;
return type;
return true;
}
catch
{
catch
{
return false;
}
finally
{
WordDocument.Dispose();
WordDocument=null;
}
}
private bool Is_ExcelDocument(MemoryStream stream)
{
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
//IWorkbook workbook = application.Workbooks.Open(stream);
IWorkbook workbook;
try
{
ExcelEngine excelEngine = new ExcelEngine();
IApplication application = excelEngine.Excel;
IWorkbook workbook = application.Workbooks.Open(stream);
type = workbook.Version.ToString();
string type = "";
workbook = application.Workbooks.Open(stream);
type = workbook.Version.ToString();
return true;
}
catch
{
return false;
}
finally
{
excelEngine.Dispose();
workbook = null;
application = null;
excelEngine = null;
}
}
return type;
}
catch
{
}
finally
{
}
private bool Is_PDFDocument(string b64)
{
PdfLoadedDocument LoadedDocument;
try
{
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(Helper.EncodeExtensions.DecodeBase642ByteArray(document));
loadedDocument = null;
return "PDF";
LoadedDocument = new PdfLoadedDocument(Helper.EncodeExtensions.DecodeBase642ByteArray(b64));
return true;
}
catch
{
{
return false;
}
finally
{
LoadedDocument = null;
}
return type;
}
private string Convert_Word_To_PDF(string document)
{
var streamword = new MemoryStream(Convert.FromBase64String(document));
WordDocument wordDocument = new WordDocument(streamword, Syncfusion.DocIO.FormatType.Automatic);
using (Syncfusion.DocToPDFConverter.DocToPDFConverter converter = new Syncfusion.DocToPDFConverter.DocToPDFConverter())
{
//Converts Word document into PDF document
using (PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument))
{
MemoryStream outputStream = new MemoryStream();
pdfDocument.Save(outputStream);
byte[] bytes;
bytes = outputStream.ToArray();
return Convert.ToBase64String(bytes);
}
};
}
private string Convert_Excel_To_PDF(string document)
{
return "";
}
}
}