270 lines
9.2 KiB
C#
270 lines
9.2 KiB
C#
using Syncfusion.DocIO;
|
|
using Syncfusion.DocIO.DLS;
|
|
|
|
using System.IO;
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using System.Xml.Linq;
|
|
using System.Text.RegularExpressions;
|
|
using DOCGEN.Klassen;
|
|
using System.Security.Cryptography;
|
|
using SkiaSharp;
|
|
using System.Web;
|
|
using Syncfusion.Pdf;
|
|
using System.Diagnostics.Eventing.Reader;
|
|
using Syncfusion.DocToPDFConverter;
|
|
using Syncfusion.OfficeChart;
|
|
using System.Drawing.Imaging;
|
|
using Syncfusion.OfficeChart;
|
|
using Syncfusion.OfficeChartToImageConverter;
|
|
|
|
namespace DocIO_Demo_SHU
|
|
{
|
|
public partial class Form1 : Form
|
|
{
|
|
public Form1()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
public void Lic()
|
|
{
|
|
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense("Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXdecXRdQ2heUU13XUI=");
|
|
}
|
|
private void Form1_Load(object sender, EventArgs e)
|
|
{
|
|
Lic();
|
|
}
|
|
|
|
|
|
private void split_doc(ref WordDocument wordDocument, ref WordDocument target, int Part, int sectionnr)
|
|
{
|
|
if (Part == 1)
|
|
{
|
|
target.Sections.Add(wordDocument.Sections[0].Clone());
|
|
}
|
|
else
|
|
{
|
|
int i = 0;
|
|
foreach (WSection section in wordDocument.Sections)
|
|
{
|
|
if (i != sectionnr)
|
|
{
|
|
target.Sections.Add(wordDocument.Sections[i].Clone());
|
|
}
|
|
i = i + 1;
|
|
}
|
|
}
|
|
}
|
|
|
|
private void button1_Click(object sender, EventArgs e)
|
|
{
|
|
string filename = @"x:\docdemo\FIN_VER_Kredit_OV928_019.dotm";
|
|
using (WordDocument wordDocument = new WordDocument(filename, FormatType.Docx))
|
|
{
|
|
//Initialize the ChartToImageConverter for converting charts during Word to image conversion.
|
|
wordDocument.ChartToImageConverter = new ChartToImageConverter();
|
|
//Set the scaling mode for charts (Normal mode reduces the file size).
|
|
wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal;
|
|
//Convert the entire Word document to images.
|
|
Image[] images = wordDocument.RenderAsImages(ImageType.Bitmap);
|
|
int i = 0;
|
|
foreach (Image image in images)
|
|
{
|
|
//Save the image as jpeg.
|
|
image.Save(@"x:\docdemo\WordToImage_" + i + ".jpeg", ImageFormat.Jpeg);
|
|
i++;
|
|
}
|
|
}
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
byte[] bytes = File.ReadAllBytes(textBox1.Text);
|
|
string dokument = Convert.ToBase64String(bytes);
|
|
|
|
|
|
var streamword = new MemoryStream(Convert.FromBase64String(dokument));
|
|
WordDocument document = new WordDocument(streamword, Syncfusion.DocIO.FormatType.Automatic);
|
|
WordDocument newDocument = new WordDocument();
|
|
WordDocument newDocument2 = new WordDocument();
|
|
WordDocument newDocument3 = new WordDocument();
|
|
string pdf = "";
|
|
SynFWord sf = new SynFWord();
|
|
DOCGEN.DocGet dg = new DOCGEN.DocGet("");
|
|
|
|
|
|
|
|
pdf = dg.Convert_Word_To_PDF(dokument, null);
|
|
File.WriteAllBytes(textBox1.Text + "_3_" + ".pdf", Convert.FromBase64String(pdf));
|
|
|
|
split_doc(ref document, ref newDocument, 1, 0);
|
|
sf.Replace_Text(ref newDocument, "Bausteine", "");
|
|
sf.Replace_Fieldtext(ref newDocument, "BesBest", "");
|
|
|
|
MemoryStream outputStream = new MemoryStream();
|
|
newDocument.Save(outputStream,FormatType.Dotm);
|
|
|
|
bytes = outputStream.ToArray();
|
|
dokument= Convert.ToBase64String(bytes);
|
|
|
|
//DOCGEN.DocGet dg = new DOCGEN.DocGet("");
|
|
pdf = dg.Convert_Word_To_PDF(dokument, null);
|
|
File.WriteAllBytes(textBox1.Text + "_1_" + ".pdf", Convert.FromBase64String(pdf));
|
|
return;
|
|
|
|
//Vertrag Kunde
|
|
split_doc(ref document, ref newDocument2, 2, 0);
|
|
sf.Replace_Fieldtext(ref newDocument2, "BesBest", "");
|
|
sf.Replace_Fieldtext(ref newDocument2, "txtDruckenExemplar", "den Kunden");
|
|
newDocument2.UpdateDocumentFields();
|
|
newDocument2.Save(outputStream, FormatType.Dotm);
|
|
|
|
bytes = outputStream.ToArray();
|
|
dokument = Convert.ToBase64String(bytes);
|
|
|
|
pdf = dg.Convert_Word_To_PDF(dokument, null);
|
|
File.WriteAllBytes(textBox1.Text + "_2_" + ".pdf", Convert.FromBase64String(pdf));
|
|
|
|
//Vertrag Kunde
|
|
split_doc(ref document, ref newDocument3, 2, 0);
|
|
sf.Replace_Fieldtext(ref newDocument3, "BesBest", "");
|
|
sf.Replace_Fieldtext(ref newDocument3, "txtDruckenExemplar", "den Kunden");
|
|
newDocument3.UpdateDocumentFields();
|
|
newDocument3.Save(outputStream, FormatType.Dotm);
|
|
bytes = outputStream.ToArray();
|
|
dokument = Convert.ToBase64String(bytes);
|
|
|
|
pdf = dg.Convert_Word_To_PDF(dokument, null);
|
|
File.WriteAllBytes(textBox1.Text + "_3_" + ".pdf", Convert.FromBase64String(pdf));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//using (FileStream outputStream = new FileStream(textBox1.Text + "_1_" + ".dotm", FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
|
//{
|
|
// newDocument.Save(outputStream, FormatType.Dotm);
|
|
//}
|
|
|
|
//int i = 0;
|
|
//foreach (WSection section in document.Sections)
|
|
//{
|
|
// if (i != 0)
|
|
// {
|
|
// newDocument1.Sections.Add(document.Sections[i].Clone());
|
|
// }
|
|
// i = i + 1;
|
|
//}
|
|
//sf.Replace_Fieldtext(ref newDocument1, "txtDruckenExemplar", "den Kunden");
|
|
//sf.Replace_Text(ref newDocument1, "Bausteine", "");
|
|
//newDocument1.UpdateDocumentFields();
|
|
|
|
//using (FileStream outputStream = new FileStream(textBox1.Text + "_2_" + ".dotm", FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
|
//{
|
|
// newDocument1.Save(outputStream, FormatType.Dotm);
|
|
//}
|
|
//sf.Replace_Fieldtext(ref newDocument1, "txtDruckenExemplar", "die Bank");
|
|
|
|
//newDocument1.UpdateDocumentFields();
|
|
|
|
//using (FileStream outputStream = new FileStream(textBox1.Text + "_3_" + ".dotm", FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
|
//{
|
|
// newDocument1.Save(outputStream, FormatType.Dotm);
|
|
//}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//foreach (WSection section in document.Sections)
|
|
//{
|
|
// int fileId = 0;
|
|
// //Create new Word document
|
|
// using (WordDocument newDocument = new WordDocument())
|
|
// {
|
|
// //Add cloned section into new Word document
|
|
// newDocument.Sections.Add(section.Clone());
|
|
// //Saves the Word document to MemoryStream
|
|
// using (FileStream outputStream = new FileStream(textBox1.Text + fileId + ".docx", FileMode.OpenOrCreate, FileAccess.ReadWrite))
|
|
// {
|
|
// newDocument.Save(outputStream, FormatType.Dotm);
|
|
// }
|
|
// }
|
|
// fileId++;
|
|
//}
|
|
//return;
|
|
|
|
//document.Open(textBox1.Text);
|
|
//document.UpdateDocumentFields();
|
|
//document.Save(textBox1.Text + ".dotm");
|
|
//try
|
|
//{
|
|
// foreach (WSection section in document.Sections)
|
|
// //Iterates through section child elements
|
|
// foreach (WTextBody textBody in section.ChildEntities)
|
|
// {
|
|
// //Iterates through form fields
|
|
// foreach (WFormField formField in textBody.FormFields)
|
|
// {
|
|
// if (formField.Name == "txtDruckenExemplar")
|
|
// {
|
|
// formField.Text = "für die Bank";
|
|
// break;
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
//}
|
|
//catch { }
|
|
//try
|
|
//{
|
|
// foreach (WSection section in document.Sections)
|
|
// //Iterates through section child elements
|
|
// foreach (WTextBody textBody in section.ChildEntities)
|
|
// {
|
|
// //Iterates through form fields
|
|
// foreach (WFormField formField in textBody.FormFields)
|
|
// {
|
|
// if (formField.Name == "BesBest")
|
|
// {
|
|
// formField.Text = "";
|
|
// break;
|
|
// }
|
|
|
|
// }
|
|
// }
|
|
//}
|
|
//catch { }
|
|
|
|
////BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
|
|
////bookmarkNavigator.MoveToBookmark("txtDruckenExemplar");
|
|
////bookmarkNavigator.InsertText("für die anderen");
|
|
//document.UpdateDocumentFields();
|
|
//document.Save(textBox1.Text + ".dotm.dotm");
|
|
|
|
}
|
|
}
|
|
|