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.
226 lines
8.2 KiB
226 lines
8.2 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;
|
|
|
|
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)
|
|
{
|
|
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("OFFEDK0082025002491692",tempdir,connectionstring);
|
|
var stream = new MemoryStream(Convert.FromBase64String(pdfdokument));
|
|
pdfViewerControl1.Load(stream);
|
|
}
|
|
}
|
|
|
|
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; } = "";
|
|
}
|
|
} |