You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
344 lines
12 KiB
344 lines
12 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Xml.Serialization;
|
|
using Syncfusion.Pdf;
|
|
using Syncfusion.Pdf.Graphics;
|
|
using Syncfusion.Pdf.Interactive;
|
|
using Syncfusion.Pdf.Parsing;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
using Versandstrasse;
|
|
using System.IO;
|
|
using System.Drawing.Printing;
|
|
using Syncfusion.Windows.Forms.PdfViewer;
|
|
using Syncfusion.Windows.PdfViewer;
|
|
using Newtonsoft;
|
|
using Newtonsoft.Json;
|
|
using System.Diagnostics;
|
|
using Newtonsoft.Json.Linq;
|
|
|
|
|
|
namespace ZZPDFTest
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
string lickey = "MzYzODg2NkAzMjM4MmUzMDJlMzBTOWljRmxNelA1d1VGOHpGR0lxQzB6UTAwKzIxK2VBNEhBZFp5alcxb1NVPQ==";
|
|
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(lickey);
|
|
|
|
PdfLoadedDocument document = new PdfLoadedDocument(@"H:\tssettings\edoka\drv.pdf");
|
|
add_Logo(ref document, false, false);
|
|
replace_Text(ref document, "Bausteine", "");
|
|
//replace_Text(ref document, "Herr", Environment.NewLine+Environment.NewLine+ "Herr");
|
|
//replace_Text(ref document, "Christoph Nõgeli", "Christoph Nõgeli");
|
|
|
|
if (document.Pages.Count % 2 == 0)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
add_emptypage(ref document);
|
|
}
|
|
|
|
|
|
document.Save(@"x:\output.pdf");
|
|
|
|
//PdfBitmap image = new PdfBitmap(@"E:\Software-Projekte\OnDoc\Images\tkb_logo_ohne_claim_4c_c.jpg");
|
|
//PdfLoadedPage loadedPage = document.Pages[0] as PdfLoadedPage;
|
|
//PdfGraphics graphics = loadedPage.Graphics;
|
|
//graphics.DrawImage(image, 80, 30);
|
|
|
|
}
|
|
|
|
private void replace_Text(ref PdfLoadedDocument document, string texttoreplace, string newtext)
|
|
{
|
|
PdfLoadedPage loadedPage = document.Pages[0] as PdfLoadedPage;
|
|
PdfFont font = new PdfTrueTypeFont(new Font("Futura Book", 9));
|
|
Dictionary<int, List<RectangleF>> matchedTextbounds = new Dictionary<int, List<RectangleF>>();
|
|
document.FindText(texttoreplace, out matchedTextbounds);
|
|
|
|
for (int i = 0; i < matchedTextbounds.Count; i++)
|
|
|
|
{
|
|
loadedPage = (PdfLoadedPage)document.Pages[i];
|
|
foreach (RectangleF rectangle in matchedTextbounds[i])
|
|
{
|
|
// Draws the white filled rectangle over the searched text.
|
|
loadedPage.Graphics.DrawRectangle(PdfBrushes.White, rectangle);
|
|
|
|
loadedPage.Graphics.DrawString(newtext, font, PdfBrushes.Black, rectangle.X - 2, rectangle.Y - 2);
|
|
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void add_Logo(ref PdfLoadedDocument document, bool color, bool onlyfirstpage)
|
|
{
|
|
string imagefile = "";
|
|
if (color) { imagefile = @"E:\Software-Projekte\OnDoc\Images\tkb_logo_ohne_claim_4c_c.jpg"; }
|
|
if (!color) { imagefile = @"E:\Software-Projekte\OnDoc\Images\tkb_logo_ohne_claim_sw.jpg"; }
|
|
PdfBitmap image = new PdfBitmap(imagefile);
|
|
|
|
int pages = document.Pages.Count;
|
|
if (onlyfirstpage) { pages = 1; }
|
|
int i = 0;
|
|
while (i < pages)
|
|
{
|
|
PdfLoadedPage loadedPage = document.Pages[i] as PdfLoadedPage;
|
|
PdfGraphics graphics = loadedPage.Graphics;
|
|
graphics.DrawImage(image, 85, 30);
|
|
i++;
|
|
}
|
|
|
|
|
|
}
|
|
private void add_emptypage(ref PdfLoadedDocument document)
|
|
{
|
|
document.Pages.Add();
|
|
}
|
|
|
|
private void button2_Click(object sender, EventArgs e)
|
|
{
|
|
string lickey = "MzYzODg2NkAzMjM4MmUzMDJlMzBTOWljRmxNelA1d1VGOHpGR0lxQzB6UTAwKzIxK2VBNEhBZFp5alcxb1NVPQ==";
|
|
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(lickey);
|
|
|
|
PdfLoadedDocument document = new PdfLoadedDocument(@"H:\tssettings\edoka\drv.pdf");
|
|
//add_Logo(ref document, false, false);
|
|
SplitDoc(ref document, "Freundliche Grüsse", "");
|
|
}
|
|
|
|
private void SplitDoc(ref PdfLoadedDocument document, string texttoreplace, string newtext)
|
|
{
|
|
PdfLoadedPage loadedPage = document.Pages[0] as PdfLoadedPage;
|
|
PdfFont font = new PdfTrueTypeFont(new Font("Futura Book", 9));
|
|
TextSearchOptions to = new TextSearchOptions();
|
|
Dictionary<int, List<RectangleF>> matchedTextbounds = new Dictionary<int, List<RectangleF>>();
|
|
document.FindText(texttoreplace, out matchedTextbounds);
|
|
PdfDocument newdoc = new PdfDocument();
|
|
PdfDocument newdoc2 = new PdfDocument();
|
|
PdfDocument newdoc3 = new PdfDocument();
|
|
foreach (int index in matchedTextbounds.Keys)
|
|
{
|
|
if (matchedTextbounds[index].Count > 0)
|
|
{
|
|
newdoc.ImportPage(document, index);
|
|
newdoc2.ImportPageRange(document, index + 1, document.Pages.Count - (index + 1));
|
|
newdoc3 = newdoc2;
|
|
}
|
|
}
|
|
|
|
|
|
newdoc.Save(@"x:\output1.pdf");
|
|
newdoc2.Save(@"x:\outupt2.pdf");
|
|
newdoc3.Save(@"x:\outupt3.pdf");
|
|
|
|
|
|
|
|
PdfLoadedDocument doc = new PdfLoadedDocument(@"x:\output1.pdf");
|
|
add_Logo(ref doc, true, true);
|
|
if (doc.Pages.Count % 2 == 0)
|
|
{
|
|
}
|
|
else
|
|
{
|
|
add_emptypage(ref doc);
|
|
}
|
|
doc.Save(@"x:\output1.pdf");
|
|
doc = new PdfLoadedDocument(@"x:\outupt3.pdf");
|
|
replace_Text(ref doc, "Exemplar für den Kunden", " Exemplar für die Bank");
|
|
doc.Save(@"x:\outupt3.pdf");
|
|
document.Close(true);
|
|
newdoc.Close(true);
|
|
|
|
}
|
|
|
|
private void button3_Click(object sender, EventArgs e)
|
|
{
|
|
versandscript vscript = new versandscript();
|
|
vsdokument dok = new vsdokument();
|
|
|
|
TextReplace tReplace = new TextReplace();
|
|
tReplace.TextToReplace = "";
|
|
tReplace.NewText = "";
|
|
|
|
dok.TextReplaces.Add(tReplace);
|
|
vscript.dokuments.Add(dok);
|
|
|
|
vscript.bezeichnung = "Test";
|
|
XmlSerializer serializer = new XmlSerializer(typeof(versandscript));
|
|
serializer.Serialize(System.IO.File.Create(@"x:\file.xml"), vscript);
|
|
|
|
}
|
|
|
|
|
|
private void button4_Click(object sender, EventArgs e)
|
|
{
|
|
Model.serienbrief sb;
|
|
clsVersandstrasse vs = new clsVersandstrasse();
|
|
string tempdir = @"h:\tssettings\edoka";
|
|
string connectionstring = "data source=shu01\\shu00;initial catalog=edoka_dms;packet size=4096;user id=sa;password=*shu29";
|
|
string pdfdokument = vs.Prepare_PDF("OFFEDK0082025002493849", @"h:\tssettings\edoka\", connectionstring, "", "", Application.StartupPath);
|
|
var stream = new MemoryStream(Convert.FromBase64String(pdfdokument));
|
|
pdfViewerControl1.Load(stream);
|
|
}
|
|
|
|
private void button5_Click(object sender, EventArgs e)
|
|
{
|
|
DataTable dt = new DataTable();
|
|
dt.Columns.Add("item");
|
|
DataRow dataRow = dt.NewRow();
|
|
dataRow[0] = "Hallo";
|
|
dt.Rows.Add(dataRow);
|
|
dataRow = dt.NewRow();
|
|
dataRow[0] = "Velo";
|
|
dt.Rows.Add(dataRow);
|
|
string JSONString = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
|
|
List<string> list = new List<string>();
|
|
list.Add(JSONString);
|
|
|
|
PrintDocument pd = new PrintDocument();
|
|
pd.DefaultPageSettings.PaperSource = new PaperSource() { RawKind = (int)PaperSourceKind.Upper };
|
|
PrinterSettings printerSettings = new PrinterSettings();
|
|
printerSettings.PrinterName = "Canon MFC750 Series URF II";
|
|
pd.DefaultPageSettings.Color = true;
|
|
pd.PrinterSettings = printerSettings;
|
|
pd.PrinterSettings.Duplex = Duplex.Default;
|
|
|
|
PdfDocumentView viewer = new PdfDocumentView();
|
|
viewer.Load("pdf_file_path");
|
|
viewer.PrintDocument.PrinterSettings.PrinterName = "My Printer Name";
|
|
viewer.PrinterSettings.PageSize = PdfViewerPrintSize.ActualSize;
|
|
viewer.PrinterSettings.PageOrientation = PdfViewerPrintOrientation.Auto;
|
|
viewer.PrintDocument.DefaultPageSettings.Landscape = false;
|
|
viewer.PrintDocument.DefaultPageSettings.Margins = new Margins(0, 0, 0, 0);
|
|
viewer.PrintDocument.DefaultPageSettings.Color = true;
|
|
viewer.PrintDocument.DefaultPageSettings.PaperSource = new PaperSource() { RawKind = (int)PaperSourceKind.Upper };
|
|
viewer.PrintDocument.OriginAtMargins = false;
|
|
viewer.PrintDocument.DefaultPageSettings.Landscape = false;
|
|
viewer.PrintDocument.PrinterSettings.Duplex = Duplex.Default;
|
|
viewer.PrintDocument.Print();
|
|
}
|
|
|
|
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; } = "1:0;2:1";
|
|
|
|
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; } = "";
|
|
}
|
|
|
|
private void button6_Click(object sender, EventArgs e)
|
|
{
|
|
pdfViewerControl1.Load(@"E:\Software-Projekte\OnDoc\Office_Vorlagen\20251110_PRIIP Arete Ethik Vorsorgefonds Global Balanced.pdf");
|
|
}
|
|
|
|
private void button7_Click(object sender, EventArgs e)
|
|
|
|
{
|
|
string jsonstring = System.IO.File.ReadAllText(@"E:\Software-Projekte\OnDoc\Office_Vorlagen\essdemo.json");
|
|
|
|
dynamic dataj = JsonConvert.DeserializeObject(jsonstring);
|
|
Console.WriteLine(dataj.Bp.Zustaendiger.TgNummer);
|
|
|
|
|
|
|
|
|
|
//foreach (var bpis in JsonConvert.DeserializeObject<dynamic>(jsonstring))
|
|
//{
|
|
// Console.WriteLine(bpis.Name);
|
|
// Console.WriteLine(bpis.Value);
|
|
|
|
//}
|
|
|
|
List<docitem> docitemlist = new List<docitem>();
|
|
var jo = JObject.Parse(jsonstring);
|
|
var valueTuples = GetNodes(jo).ToList();
|
|
foreach ( var valueTuple in valueTuples)
|
|
{
|
|
docitem d = new docitem();
|
|
d.itemname= valueTuple.Item1;
|
|
d.itemtag= valueTuple.Item2;
|
|
d.itemvalue= valueTuple.Item3;
|
|
d.doclinkname = "";
|
|
docitemlist.Add(d);
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
public class docitem
|
|
{
|
|
public string itemname;
|
|
public string itemtag;
|
|
public string itemvalue;
|
|
public string doclinkname;
|
|
}
|
|
private IEnumerable<(string path, string key, string value)> GetNodes(JToken token)
|
|
{
|
|
foreach (var jt in token.Children())
|
|
{
|
|
if (!jt.Children().Any())
|
|
{
|
|
yield return (
|
|
path: jt.Path,
|
|
key: jt.Path.Split('.').Last(),
|
|
value: jt.ToString()
|
|
);
|
|
}
|
|
|
|
foreach (var (path, key, value) in GetNodes(jt))
|
|
{
|
|
yield return (path, key, value);
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|