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.

325 lines
15 KiB

using Microsoft.Office.Interop.Word;
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.Linq;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Shape = Syncfusion.DocIO.DLS.Shape;
using Syncfusion.DocIO.ReaderWriter;
using System.IO;
using Syncfusion.Pdf;
using Syncfusion.OfficeChart;
using Syncfusion.DocToPDFConverter;
using Syncfusion.OfficeChartToImageConverter;
using static System.Net.WebRequestMethods;
namespace ZZ_Signature_C
{
public partial class Form1 : Form
{
Microsoft.Office.Interop.Word.Application word;
Microsoft.Office.Interop.Word.Document docWord;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string bmname = "Unterschrift2";
//bmname = "TGEDKNameVornameLinksB";
word = new Microsoft.Office.Interop.Word.Application();
docWord = word.Documents.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\Signature.docx");
docWord.Activate();
word.Visible = true;
insert_unterschrift("TGEDKVornameNameLinksB99");
insert_unterschrift("TGEDKVornameNameRechtsB99");
word.ActiveDocument.SaveAs2(@"E:\Software-Projekte\OnDoc\Excel_Dateien\SignatureSigned.docx");
docWord = null;
word = null;
}
private void remove_unterschriften()
{
bool found = true;
MessageBox.Show(word.ActiveDocument.Shapes.Count.ToString());
int i = 1;
while (word.ActiveDocument.Shapes.Count > 0 && found==true)
{
found = false;
if (word.ActiveDocument.Shapes[i].Name.Contains("Unterschrift_"))
{
word.ActiveDocument.Shapes[i].Delete();
found= true;
}
}
//foreach (Microsoft.Office.Interop.Word.Shape sh in docWord.Shapes) {
// if (sh.Name.Contains("Unterschrift_")){
// sh.Delete();
// }
//}
}
private void insert_unterschrift(string tmn) {
object missing = Type.Missing;
Microsoft.Office.Interop.Word.Range myRange = docWord.Bookmarks[tmn].Range;
Microsoft.Office.Interop.Word.Bookmark bm = docWord.Bookmarks[tmn];
float vertical = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdVerticalPositionRelativeToPage];
float horizontal = bm.Range.Information[Microsoft.Office.Interop.Word.WdInformation.wdHorizontalPositionRelativeToPage];
docWord.Activate();
Microsoft.Office.Interop.Word.Range myRange3 = bm.Range;
Microsoft.Office.Interop.Word.Range myRange4 = bm.Range.GoTo();
Microsoft.Office.Interop.Word.Shape myShape = docWord.Shapes.AddPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg", false, true, 0, 0, 120, 50, myRange);
myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapTight;
myShape.RelativeHorizontalPosition = Microsoft.Office.Interop.Word.WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
myShape.Left = horizontal;
myShape.RelativeVerticalPosition = Microsoft.Office.Interop.Word.WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
myShape.Top = vertical - myShape.Height;
//myShape.LockAspectRatio = Microsoft.Office.Core.MsoTriState.msoTrue;
myShape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapBehind;
myShape.ZOrder(Microsoft.Office.Core.MsoZOrderCmd.msoSendBackward);
myShape.Select();
return;
//vertical = vertical - 50;
//word.ActiveDocument.Bookmarks[tmn].Select();
//Microsoft.Office.Interop.Word.Shape myshape1 = docWord.Shapes.AddShape(1, horizontal, vertical, 120, 50);
//myshape1.Fill.UserPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg");
////myshape1.Line.Weight = -2;
//myshape1.Name = "Unterschrift" + "_" + tmn;
//myshape1.Line.Visible= Microsoft.Office.Core.MsoTriState.msoFalse;
////Microsoft.Office.Interop.Word.InlineShape myshape3 = word.Selection.InlineShapes.AddPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg",false,true,myRange,);
Microsoft.Office.Interop.Word.Shape myshape = docWord.Shapes.AddTextbox(Microsoft.Office.Core
.MsoTextOrientation.msoTextOrientationHorizontal, (float)horizontal,
(float)vertical, 120, 56, ref missing);
myshape.Name = "Unterschrift" + "_" + tmn;
myshape.TextFrame.ContainingRange.Borders.OutsideLineStyle = WdLineStyle.wdLineStyleNone;
myshape.TextFrame.ContainingRange.Borders.InsideLineStyle = WdLineStyle.wdLineStyleNone;
myshape.Fill.UserPicture(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg");
myshape.WrapFormat.Type = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;
myshape.Line.Visible = Microsoft.Office.Core.MsoTriState.msoFalse;
}
public void Lic()
{
// 25. string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXdecXRdQ2heUU13XUI="
//string lickey = "Ngo9BigBOggjHTQxAR8/V1NCaF5cXmZCf1FpRmJGdld5fUVHYVZUTXxaS00DNHVRdkdnWXZeeXRQR2NZUEZ2WkE=";
string lickey = "MzYzODg2NkAzMjM4MmUzMDJlMzBTOWljRmxNelA1d1VGOHpGR0lxQzB6UTAwKzIxK2VBNEhBZFp5alcxb1NVPQ==";
Syncfusion.Licensing.SyncfusionLicenseProvider.RegisterLicense(lickey);
}
private void button2_Click(object sender, EventArgs e)
{
Lic();
WordDocument document = new WordDocument();
document.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\Signature.docx");
BookmarksNavigator bookmarkNavigator = new BookmarksNavigator(document);
bookmarkNavigator.MoveToBookmark("Unterschrift2");
Syncfusion.DocIO.DLS.Bookmark bm = document.Bookmarks["Unterschrift2"];
Shape signature = bm.BookmarkStart.OwnerParagraph.AppendShape(AutoShapeType.Rectangle, 120, 59);
//signature.WrapFormat.AllowOverlap = true;
signature.VerticalPosition = signature.VerticalPosition -50;
signature.LineFormat.DashStyle = LineDashing.Solid;
signature.LineFormat.Color = Color.White;
IWParagraph p = signature.TextBody.AddParagraph();
System.Drawing.Image sfimage = Image.FromFile(@"E:\Software-Projekte\OnDoc\Unterschriften\1.jpg");
IWPicture pi = p.AppendPicture(sfimage);
pi.Width = 120;
pi.Height = 50;
//Shape signature = bm.BookmarkStart.OwnerParagraph.AppendShape(Syncfusion.DocIO.DLS.AutoShapeType.Rectangle, 120, 50);
////IWParagraph p = bm.BookmarkStart.OwnerParagraph;
////IWPicture u = p.AppendPicture(img);
//IWParagraph sigparagraph = signature.TextBody.AddParagraph();
//signature.WrapFormat.TextWrappingStyle = TextWrappingStyle.Behind;
//signature.LineFormat.DashStyle = LineDashing.Solid;
//signature.LineFormat.Color = Color.White;
//signature.WrapFormat.AllowOverlap = true;
//signature.VerticalPosition = signature.VerticalPosition - 50;
////signature.HorizontalPosition = signature.HorizontalPosition + 200;
//sigparagraph.AppendPicture(img);
//signature.Name = "Unterschrift_" + bookmark;
//// signature.OwnerParagraph.AppendPicture(img);
//mssign = null;
//Shape signature2 = bm.BookmarkStart.OwnerParagraph.AppendShape(AutoShapeType.Rectangle, 50, 50);
//signature2.WrapFormat.AllowOverlap = true;
//int index = bm.BookmarkStart.OwnerParagraph.ChildEntities.IndexOf(bm.BookmarkStart);
//bm.BookmarkStart.OwnerParagraph.ChildEntities.Insert(index, signature2);
//Syncfusion.DocIO.DLS.Bookmark x = document.Bookmarks.FindByName("Unterschrift2");
//IWParagraph p = x.BookmarkStart.Document.CreateParagraph();
//p.AppendShape(AutoShapeType.CircularArrow, 50, 50);
//bookmarkNavigator.InsertParagraph(p);
//IWParagraph paragraph = document.Sections[0].Paragraphs[0];
//if (document.Sections.Count < 1)
//{
// document.AddSection();
//}
//IWParagraph footerparagraph;
//if (document.Sections[0].HeadersFooters.Footer.Paragraphs.Count < 1)
//{
// footerparagraph = document.Sections[0].HeadersFooters.Footer.AddParagraph();
//}
//footerparagraph = document.Sections[0].HeadersFooters.Footer.Paragraphs[0];
//System.Drawing.Image sfimage = Image.FromFile(@"x:\gaga.png");
////sfimage = AutoSizeImage(sfimage, Convert.ToInt32(this.width), Convert.ToInt32(this.height), false);
////sfimage = ScaleImage(sfimage, Convert.ToInt32(this.width), Convert.ToInt32(this.height));
//Shape rectangle = footerparagraph.AppendShape(AutoShapeType.Rectangle, Convert.ToInt32(this.width), Convert.ToInt32(this.height));
//paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
//rectangle.LineFormat.Line = false;
//IWPicture pic = paragraph.AppendPicture(sfimage);
//pic.Width = 160;
//pic.Height = 28;
//rectangle.VerticalPosition = (Convert.ToInt32(this.top) / 150 * 2.83465f);
//rectangle.HorizontalPosition = Convert.ToInt32(this.left);
////rectangle.LineFormat.DashStyle = LineDashing.Dot;
////rectangle.LineFormat.Color = Color.DarkGray;
////IWParagraph rectangleparagraph = rectangle.TextBody.AddParagraph();
////IWPicture picture = rectangleparagraph.AppendPicture(sfimage);
////footerparagraph.AppendShape
document.Save(@"x:\gaga.docx");
document.Close();
System.Diagnostics.Process.Start("winword.exe", "/w " + @"x:\gaga.docx");
return;
//WordDocument document = new WordDocument();
//document.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\empty.docx");
////Add a new section to the document.
//IWSection section = document.AddSection();
////Add a new paragraph to the section.
//IWParagraph paragraph = section.AddParagraph() as WParagraph;
//Shape rectangle = paragraph.AppendShape(AutoShapeType.RoundedRectangle, 150, 100);
//rectangle.VerticalPosition = 72;
//rectangle.HorizontalPosition = 72;
//paragraph = section.AddParagraph() as WParagraph;
//paragraph = rectangle.TextBody.AddParagraph() as WParagraph;
//System.Drawing.Image sfimage = Image.FromFile(@"x:\gaga.png");
//paragraph.AppendPicture(sfimage);
//IWTextRange text = paragraph.AppendText("This text is in rounded rectangle shape");
//text.CharacterFormat.TextColor = Color.Green;
//text.CharacterFormat.Bold = true;
////Apply fill color for shape.
//rectangle.FillFormat.Fill = true;
//rectangle.FillFormat.Color = Color.LightGray;
////Set transparency (opacity) to the shape fill color.
//rectangle.FillFormat.Transparency = 75;
////Apply wrap formats.
//rectangle.WrapFormat.TextWrappingStyle = TextWrappingStyle.Square;
//rectangle.WrapFormat.TextWrappingType = TextWrappingType.Right;
////Set horizontal and vertical origin.
//rectangle.HorizontalOrigin = HorizontalOrigin.Margin;
//rectangle.VerticalOrigin = VerticalOrigin.Page;
////Set line format.
//rectangle.LineFormat.DashStyle = LineDashing.Dot;
//rectangle.LineFormat.Color = Color.DarkGray;
////Set the left internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Left = 30;
////Set the right internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Right = 24;
////Set the bottom internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Bottom = 18;
////Set the top internal margin for the shape.
//rectangle.TextFrame.InternalMargin.Top = 6;
////Saves the Word document to MemoryStream
//document.Save(@"x:\gaga.docx", FormatType.Docx);
////Closes the Word document
//document.Close();
}
private void button3_Click(object sender, EventArgs e)
{
word = new Microsoft.Office.Interop.Word.Application();
docWord = word.Documents.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\Signature.docx");
docWord.Activate();
docWord = word.Documents.Open(@"x:\gaga.docx");
word.Visible = true;
remove_unterschriften();
docWord = null;
word = null;
}
private void button4_Click(object sender, EventArgs e)
{
WordDocument wordDocument = new WordDocument(@"E:\Software-Projekte\OnDoc\Excel_Dateien\SignatureSigned.docx", Syncfusion.DocIO.FormatType.Automatic);
wordDocument.ChartToImageConverter = new ChartToImageConverter();
wordDocument.ChartToImageConverter.ScalingMode = ScalingMode.Normal;
Syncfusion.DocToPDFConverter.DocToPDFConverter converter = new Syncfusion.DocToPDFConverter.DocToPDFConverter();
converter.Settings.EmbedFonts = true;
converter.Settings.UpdateDocumentFields = false;
converter.Settings.EnableAlternateChunks = true;
converter.Settings.AutoDetectComplexScript = true;
converter.Settings.ImageResolution = 1280;
converter.Settings.ImageQuality = 100;
using (PdfDocument pdfDocument = converter.ConvertToPDF(wordDocument))
{
pdfDocument.Save(Path.GetFullPath(@"E:\Software-Projekte\OnDoc\Excel_Dateien\SignatureSigned.pdf"));
this.pdfViewerControl1.Load(@"E:\Software-Projekte\OnDoc\Excel_Dateien\SignatureSigned.pdf");
}
}
}
}