update 20250324
This commit is contained in:
@@ -1,13 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlTypes;
|
||||
using System.Drawing;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Runtime.Remoting.Messaging;
|
||||
using System.Security;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Xml.Serialization;
|
||||
using edoka_dms;
|
||||
using Model;
|
||||
using Syncfusion.Pdf;
|
||||
@@ -19,61 +22,166 @@ namespace Versandstrasse
|
||||
{
|
||||
public class clsVersandstrasse
|
||||
{
|
||||
private List<PdfLoadedDocument> loadedDocuments = new List<PdfLoadedDocument>();
|
||||
public void Lic()
|
||||
{
|
||||
string lickey = "MzYzODg2NkAzMjM4MmUzMDJlMzBTOWljRmxNelA1d1VGOHpGR0lxQzB6UTAwKzIxK2VBNEhBZFp5alcxb1NVPQ==";
|
||||
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(lickey);
|
||||
}
|
||||
public string Prepare_PDF(string dokumentid, string tempdir, string connectionstring)
|
||||
|
||||
bool logo = false;
|
||||
bool color = false;
|
||||
int left = 0;
|
||||
int top = 0;
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
string pages = "";
|
||||
string xml = "";
|
||||
|
||||
public string Prepare_PDF(string dokumentid, string tempdir, string connectionstring, versandscript vs = null)
|
||||
{
|
||||
Lic();
|
||||
OnDocOffice.OfficeToPDF officeToPDF = new OnDocOffice.OfficeToPDF();
|
||||
clsdok dok = new clsdok("", "", "", "");
|
||||
dok.dokument = officeToPDF.word_to_pdf(dokumentid, connectionstring, tempdir);
|
||||
//var stream = new MemoryStream(Convert.FromBase64String(dok.dokument));
|
||||
|
||||
|
||||
var stream = new MemoryStream(Convert.FromBase64String(dok.dokument));
|
||||
|
||||
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
|
||||
////Originalfile laden
|
||||
//PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
|
||||
|
||||
Database.DB db = new Database.DB(connectionstring);
|
||||
db.clear_parameter();
|
||||
db.add_parameter("@dokumentid", dokumentid);
|
||||
db.Get_Tabledata("ondoc_get_versandstrasse_parameter", true, false);
|
||||
|
||||
int logo = 0;
|
||||
int color = 0;
|
||||
int left = 0;
|
||||
int top = 0;
|
||||
string pages = "";
|
||||
|
||||
logo = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["logo"]);
|
||||
color = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["logocolor"]);
|
||||
versandscript vscript = new versandscript();
|
||||
|
||||
|
||||
|
||||
logo = Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["logo"]);
|
||||
color = Convert.ToBoolean(db.dsdaten.Tables[0].Rows[0]["logocolor"]);
|
||||
top = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["logotop"]);
|
||||
left = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["logoleft"]);
|
||||
top = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["logocolor"]);
|
||||
height = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["logoheight"]);
|
||||
width = Convert.ToInt32(db.dsdaten.Tables[0].Rows[0]["logowidth"]);
|
||||
|
||||
pages = db.dsdaten.Tables[0].Rows[0]["pages"].ToString();
|
||||
xml = db.dsdaten.Tables[0].Rows[0]["vscript"].ToString();
|
||||
|
||||
if (xml != "")
|
||||
{
|
||||
|
||||
if (logo == 1)
|
||||
{
|
||||
Add_Logo(ref loadedDocument, color, left, top, pages);
|
||||
}
|
||||
if (loadedDocument.Pages.Count % 2 == 0)
|
||||
{
|
||||
XmlSerializer serializer = new XmlSerializer(typeof(versandscript));
|
||||
using (StringReader reader = new StringReader(xml))
|
||||
{
|
||||
vscript = (versandscript)(serializer.Deserialize(reader));
|
||||
}
|
||||
if (vscript.PartCopies != "")
|
||||
{
|
||||
create_copies(ref vscript, dok.dokument);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Add_EmptyPage(ref loadedDocument);
|
||||
vsdokument d = new vsdokument();
|
||||
d.LogoTop = top;
|
||||
d.LogoLeft = left;
|
||||
d.LogoHeigth = height;
|
||||
d.LogoWidth = width;
|
||||
d.LogoColor = color;
|
||||
d.Logo = logo;
|
||||
d.LogoOnPages = "1";
|
||||
d.sourcedokument = dok.dokument;
|
||||
vscript.dokuments.Add(d);
|
||||
}
|
||||
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
loadedDocument.Save(outputStream);
|
||||
byte[] bytes;
|
||||
bytes = outputStream.ToArray();
|
||||
dok.dokument = Convert.ToBase64String(bytes);
|
||||
return dok.dokument;
|
||||
foreach (vsdokument vdok in vscript.dokuments)
|
||||
{
|
||||
var stream = new MemoryStream(Convert.FromBase64String(vdok.sourcedokument));
|
||||
PdfLoadedDocument loadedDocument = new PdfLoadedDocument(stream);
|
||||
if (vdok.Logo)
|
||||
{
|
||||
Add_Logo(ref loadedDocument, vdok.LogoColor, vdok.LogoLeft, vdok.LogoTop, vdok.LogoWidth, vdok.LogoHeigth, vdok.LogoOnPages);
|
||||
}
|
||||
loadedDocument.Save(@"x:\output1.pdf");
|
||||
if (vdok.TextReplaces.Count > 0)
|
||||
{
|
||||
foreach (TextReplace tr in vdok.TextReplaces)
|
||||
{
|
||||
if (tr.TextToReplace.Trim() != "")
|
||||
{
|
||||
Replace_Text(ref loadedDocument, tr.TextToReplace, tr.NewText);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (loadedDocument.Pages.Count % 2 == 0) { } else { Add_EmptyPage(ref loadedDocument); }
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
loadedDocument.Save(outputStream);
|
||||
byte[] bytes;
|
||||
bytes = outputStream.ToArray();
|
||||
vdok.pdfdokument = Convert.ToBase64String(bytes);
|
||||
|
||||
}
|
||||
if (vscript.dokuments.Count > 1)
|
||||
{
|
||||
int i = 0;
|
||||
Stream[] streams = new Stream[vscript.dokuments.Count];
|
||||
|
||||
foreach (vsdokument vdoc in vscript.dokuments)
|
||||
{
|
||||
var stream = new MemoryStream(Convert.FromBase64String(vdoc.pdfdokument));
|
||||
streams[i] = stream;
|
||||
i++;
|
||||
|
||||
}
|
||||
PdfDocument finalDoc = new PdfDocument();
|
||||
PdfDocumentBase.Merge(finalDoc, streams);
|
||||
MemoryStream outputStream = new MemoryStream();
|
||||
finalDoc.Save(outputStream);
|
||||
byte[] bytes;
|
||||
bytes = outputStream.ToArray();
|
||||
dok.dokument = Convert.ToBase64String(bytes);
|
||||
vscript.FinalDoc = Convert.ToBase64String(bytes);
|
||||
finalDoc.Close();
|
||||
finalDoc.Dispose();
|
||||
streams = null;
|
||||
vscript.FinalDoc = vscript.FinalDoc;
|
||||
}
|
||||
else
|
||||
{
|
||||
vscript.FinalDoc = vscript.dokuments[0].pdfdokument.ToString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return vscript.FinalDoc;
|
||||
}
|
||||
|
||||
private void create_copies(ref versandscript vscript, string dokument)
|
||||
{
|
||||
vsdokument vsd = vscript.dokuments[0];
|
||||
if (vsd.LogoTop == 0) { vsd.LogoTop = top; }
|
||||
if (vsd.LogoLeft == 0) { vsd.LogoLeft = left; }
|
||||
if (vsd.LogoHeigth == 0) { vsd.LogoHeigth = height; }
|
||||
if (vsd.LogoWidth == 0) { vsd.LogoWidth = width; }
|
||||
vsd.sourcedokument = dokument;
|
||||
|
||||
int i = 1;
|
||||
List<String> copyparts = vscript.PartCopies.Split(';').ToList();
|
||||
foreach (string cp in copyparts)
|
||||
{
|
||||
string[] part = cp.Split(':');
|
||||
int part1 = Convert.ToInt32(part[0]);
|
||||
int part2 = Convert.ToInt32(part[1]);
|
||||
|
||||
vsdokument source = vscript.dokuments[part1 - 1];
|
||||
if (vscript.dokuments.Count >= part2) { vscript.dokuments[i] = source; } else { vscript.dokuments.Add(source); }
|
||||
}
|
||||
|
||||
}
|
||||
private void Replace_Text(ref PdfLoadedDocument document, string texttoreplace, string newtext)
|
||||
{
|
||||
PdfLoadedPage loadedPage = document.Pages[0] as PdfLoadedPage;
|
||||
@@ -84,7 +192,7 @@ namespace Versandstrasse
|
||||
for (int i = 0; i < matchedTextbounds.Count; i++)
|
||||
|
||||
{
|
||||
loadedPage = (PdfLoadedPage)document.Pages[i];
|
||||
loadedPage = (PdfLoadedPage)document.Pages[0];
|
||||
foreach (RectangleF rectangle in matchedTextbounds[i])
|
||||
{
|
||||
loadedPage.Graphics.DrawRectangle(PdfBrushes.White, rectangle);
|
||||
@@ -93,14 +201,18 @@ namespace Versandstrasse
|
||||
}
|
||||
}
|
||||
|
||||
private void Add_Logo(ref PdfLoadedDocument document, int color, int left, int top, string pages)
|
||||
private string get_logo(bool color)
|
||||
{
|
||||
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"; }
|
||||
}
|
||||
private void Add_Logo(ref PdfLoadedDocument document, bool color, int left, int top, int width, int height, string pages)
|
||||
{
|
||||
string imagefile = "";
|
||||
imagefile = @"E:\Software-Projekte\OnDoc\Images\tkb_logo_ohne_claim_4c_c.jpg";
|
||||
if (color == 0) { imagefile = @"E:\Software-Projekte\OnDoc\Images\tkb_logo_ohne_claim_sw.jpg"; }
|
||||
|
||||
imagefile = get_logo(color);
|
||||
PdfBitmap image = new PdfBitmap(imagefile);
|
||||
|
||||
if (pages=="0") { return; }
|
||||
if (pages == "0") { return; }
|
||||
if (pages == "All")
|
||||
{
|
||||
for (int i = 0; i < document.Pages.Count; i++)
|
||||
@@ -113,8 +225,6 @@ namespace Versandstrasse
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
|
||||
int docpages = document.Pages.Count;
|
||||
string[] page = pages.Split(';');
|
||||
|
||||
@@ -136,4 +246,37 @@ namespace Versandstrasse
|
||||
|
||||
|
||||
}
|
||||
public class versandscript
|
||||
{
|
||||
public string bezeichnung { get; set; } = "Versandstrassenparaemter";
|
||||
public int dokumenttypnr { get; set; } = 0;
|
||||
public string Split_Doc { get; set; } = "";
|
||||
public string PartCopies { get; set; } = "";
|
||||
|
||||
public string FinalDoc { get; set; } = "";
|
||||
public List<vsdokument> dokuments { get; set; } = new List<vsdokument>();
|
||||
|
||||
}
|
||||
|
||||
public class vsdokument
|
||||
{
|
||||
public bool Logo { get; set; } = true;
|
||||
public bool LogoColor { get; set; } = false;
|
||||
public int LogoTop { get; set; } = 0;
|
||||
public int LogoLeft { get; set; } = 0;
|
||||
public int LogoHeigth { get; set; } = 0;
|
||||
public int LogoWidth { get; set; } = 0;
|
||||
public string LogoOnPages { get; set; } = "1";
|
||||
|
||||
public string sourcedokument { get; set; } = "";
|
||||
public string pdfdokument { get; set; } = "";
|
||||
|
||||
public List<TextReplace> TextReplaces { get; set; } = new List<TextReplace>();
|
||||
}
|
||||
|
||||
public class TextReplace
|
||||
{
|
||||
public string TextToReplace { get; set; } = "";
|
||||
public string NewText { get; set; } = "";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user