update 20250326

This commit is contained in:
Stefan Hutter
2025-03-26 20:46:46 +01:00
parent c767e2ed82
commit e0d3dbbbff
460 changed files with 122504 additions and 1125 deletions

View File

@@ -4,10 +4,12 @@ using System.Data.SqlTypes;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Remoting.Messaging;
using System.Security;
using System.Security.Principal;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;
@@ -37,13 +39,25 @@ namespace Versandstrasse
int width = 0;
string pages = "";
string xml = "";
string resturi = "";
string apikey = "";
public string Prepare_PDF(string dokumentid, string tempdir, string connectionstring, versandscript vs = null)
public string Prepare_PDF(string dokumentid, string tempdir, string connectionstring, string resturi, string apikey, string startuppath, versandscript vs = null, serienbrief sb = null, string sbsourcedok="")
{
Lic();
OnDocOffice.OfficeToPDF officeToPDF = new OnDocOffice.OfficeToPDF();
this.resturi=resturi;
this.apikey=apikey;
clsdok dok = new clsdok("", "", "", "");
dok.dokument = officeToPDF.word_to_pdf(dokumentid, connectionstring, tempdir);
if (sbsourcedok != "")
{
dok.dokument = sbsourcedok;
}
else
{
OnDocOffice.OfficeToPDF officeToPDF = new OnDocOffice.OfficeToPDF();
dok.dokument = officeToPDF.word_to_pdf(dokumentid, connectionstring, tempdir);
}
//var stream = new MemoryStream(Convert.FromBase64String(dok.dokument));
////Originalfile laden
@@ -52,6 +66,9 @@ namespace Versandstrasse
Database.DB db = new Database.DB(connectionstring);
db.clear_parameter();
db.add_parameter("@dokumentid", dokumentid);
if (sb != null) {
db.add_parameter("@doktyp", sb.dokumenttypnr.ToString());
}
db.Get_Tabledata("ondoc_get_versandstrasse_parameter", true, false);
@@ -102,9 +119,9 @@ namespace Versandstrasse
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
if (vdok.Logo)
{
Add_Logo(ref loadedDocument, vdok.LogoColor, vdok.LogoLeft, vdok.LogoTop, vdok.LogoWidth, vdok.LogoHeigth, vdok.LogoOnPages);
Add_Logo(ref loadedDocument, vdok.LogoColor, vdok.LogoLeft, vdok.LogoTop, vdok.LogoWidth, vdok.LogoHeigth, vdok.LogoOnPages,this.resturi,this.apikey,startuppath);
}
loadedDocument.Save(@"x:\output1.pdf");
if (vdok.TextReplaces.Count > 0)
{
foreach (TextReplace tr in vdok.TextReplaces)
@@ -201,15 +218,57 @@ namespace Versandstrasse
}
}
private string get_logo(bool color)
private string get_logo(bool color, string resturi, string apikey)
{
if (color) { return @"E:\Software-Projekte\OnDoc\Images\tkb_logo_ohne_claim_sw.jpg"; } else { return @"E:\Software-Projekte\OnDoc\Images\tkb_logo_ohne_claim_4c_c.jpg"; }
int imageid = 0;
if (color) { imageid = 4; } else { imageid = 5; }
return get_image(imageid,-1,-1,resturi,apikey);
}
private void Add_Logo(ref PdfLoadedDocument document, bool color, int left, int top, int width, int height, string pages)
private string get_image(int imageid, int width, int heigh, string resturi, string apikey)
{
string URL = resturi + "API/GetImageAsBase64?imageid=" + imageid.ToString() + "&ImageWidth=" + width.ToString() + "&ImageHeight=" + height.ToString();
HttpWebRequest webRequest = HttpWebRequest.Create(URL) as HttpWebRequest;
webRequest.Method = WebRequestMethods.Http.Get;
webRequest.Headers["Authorization"] = "Bearer " + apikey;
try
{
using (HttpWebResponse response = webRequest.GetResponse() as HttpWebResponse)
{
if (response.StatusCode == HttpStatusCode.OK)
{
StreamReader reader = new StreamReader(response.GetResponseStream());
string responseContent = reader.ReadToEnd();
return responseContent;
}
else
{
//Logging.Logging.Error(URL + ": " + response.StatusCode.ToString() + " / " + response.StatusDescription, "Client - GetImage", "");
return "";
}
}
}
catch (Exception ex)
{
return "";
}
}
private void Add_Logo(ref PdfLoadedDocument document, bool color, int left, int top, int width, int height, string pages, string resturi, string apikey, string startuppath)
{
string imagefile = "";
imagefile = get_logo(color);
imagefile = startuppath + @"\images\tkb_logo_ohne_claim_sw.jpg";
if (color)
{
imagefile = startuppath + @"\images\tkb_logo_ohne_claim_4c_c.jpg";
}
//imagefile = get_logo(color,resturi,apikey);
//byte[] bytes = Convert.FromBase64String(imagefile);
//MemoryStream ms = new MemoryStream(bytes);
PdfBitmap image = new PdfBitmap(imagefile);
if (pages == "0") { return; }