update 20250129

This commit is contained in:
Stefan Hutter
2025-01-29 21:11:56 +01:00
parent 3f765247ee
commit 6558c21a9d
193 changed files with 390461 additions and 223 deletions

View File

@@ -1,4 +1,5 @@
using System;
using Microsoft.Office.Interop.Word;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
@@ -7,9 +8,17 @@ using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
using System.Drawing.Text;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Syncfusion.DocIO;
using Syncfusion.DocIO.DLS;
using Shape = Syncfusion.DocIO.DLS.Shape;
using System.IO;
using BarcodeLib;
using System.Xml.Linq;
using Microsoft.Office.Core;
namespace ZZ_BarcpdeFromFont
@@ -21,13 +30,60 @@ namespace ZZ_BarcpdeFromFont
InitializeComponent();
}
public string barcode_font;
public string barcode_fontsize;
public string zusatz_font;
public string zusatz_size;
public string width;
public string height;
public string top;
public string left;
public string imagewith;
public string imageheight;
public string inhalt;
public string zusatz;
public string rotation;
private void button1_Click(object sender, EventArgs e)
{
string inp = Bar25I(this.textBox1.Text);
Font f = new Font("Bar 25i c", 46);
//Font f = new Font("Bar 25i c", 46);
BarcodeLib.clsBarI25 barbarcode = new BarcodeLib.clsBarI25();
BarcodeLib.Barcode Barcode = new BarcodeLib.Barcode();
barcode_font = textBox7.Text;
barcode_fontsize = textBox12.Text;
zusatz_font = textBox8.Text;
zusatz_size = textBox13.Text;
width = textBox4.Text;
height = textBox5.Text;
top = textBox2.Text;
left = textBox3.Text;
imagewith = textBox10.Text;
imageheight = textBox11.Text;
inhalt = textBox1.Text;
zusatz = textBox9.Text;
rotation = textBox6.Text;
// pictureBox1.Image = barbarcode.GetBarI25(Color.Black, Color.White, inp, "Bar 25i c HR", 36, 350, 50, " U", "Futur Book", 8,0);
System.Drawing.Image barcodeimage;
barcodeimage = barbarcode.GetBarI25(Color.Black, Color.White, inhalt, barcode_font, Convert.ToInt32(barcode_fontsize), Convert.ToInt32(imagewith), Convert.ToInt32(imageheight), zusatz, zusatz_font, Convert.ToInt32(zusatz_size), Convert.ToInt32(rotation));
//barcodeimage = ScaleImage(barcodeimage, Convert.ToInt32(this.imageheight));
// barcodeimage = ScaleImage(barcodeimage, 200, 33);
//barcodeimage = Barcode.Get_LinerBarcode(Barcoded.Symbology.I2of5, inhalt,inhalt + " "+zusatz,"Below", zusatz_font, Convert.ToInt32(zusatz_size),Convert.ToInt32(rotation));
//barcodeimage = Barcode.Get_LinerBarcode(Barcoded.Symbology.I2of5, inhalt, inhalt + " " + zusatz, "Below", zusatz_font, Convert.ToInt32(zusatz_size), Convert.ToInt32(rotation));
barcodeimage = Barcode.Get_LinerBarcode(Barcoded.Symbology.I2of5C ,inhalt, inhalt + " " + zusatz, "Below", zusatz_font, Convert.ToInt32(zusatz_size), Convert.ToInt32(rotation));
// barcodeimage = AutoSizeImage(barcodeimage, Convert.ToInt32(width), Convert.ToInt32(height),false);
barcodeimage = ScaleImage(barcodeimage, 50);
pictureBox1.Image = barcodeimage;
pictureBox1.Image.Save(@"x:\gaga.png");
pictureBox1.Image = barbarcode.GetBarI25(Color.Black, Color.White, inp, "Bar 25i c HR", 36, 350, 50, " U", "Futur Book", 8,270);
//pictureBox1.Image= DrawText(inp, f, Color.Black, 140,textBox1.Text+ " U");
//pictureBox1.Image = DrawText1(Color.Black, Color.White, "Bar 25i c HR", 36, inp, 350, 50, " U",0);
@@ -123,7 +179,7 @@ namespace ZZ_BarcpdeFromFont
//}
public Image DrawText(String text, Font font, Color textColor, int maxWidth, String path)
public Image DrawText(String text, System.Drawing.Font font, Color textColor, int maxWidth, String path)
{
//first, create a dummy bitmap just to get a graphics object
Image img = new Bitmap(1, 1);
@@ -142,7 +198,7 @@ namespace ZZ_BarcpdeFromFont
int multi = 4;
//create a new image of the right size
img = new Bitmap((int)textSize.Width*multi, (int)textSize.Height);
img = new Bitmap((int)textSize.Width * multi, (int)textSize.Height);
drawing = Graphics.FromImage(img);
//Adjust for high quality
@@ -158,9 +214,9 @@ namespace ZZ_BarcpdeFromFont
//create a brush for the text
Brush textBrush = new SolidBrush(textColor);
Font ftext = new Font("Arial", 15,FontStyle.Bold);
drawing.DrawString(text, font, textBrush, new RectangleF(0, 0, textSize.Width*multi, textSize.Height), sf);
drawing.DrawString(path, ftext, textBrush, new RectangleF(50, 50, textSize.Width*multi , textSize.Height ), sf);
System.Drawing.Font ftext = new System.Drawing.Font("Arial", 15, FontStyle.Bold);
drawing.DrawString(text, font, textBrush, new RectangleF(0, 0, textSize.Width * multi, textSize.Height), sf);
drawing.DrawString(path, ftext, textBrush, new RectangleF(50, 50, textSize.Width * multi, textSize.Height), sf);
drawing.Save();
@@ -176,20 +232,20 @@ namespace ZZ_BarcpdeFromFont
{
Bitmap img = new Bitmap(width, height);
Graphics Gimg = Graphics.FromImage(img);
Font imgFont = new Font(fontName, fontSize);
System.Drawing.Font imgFont = new System.Drawing.Font(fontName, fontSize);
PointF imgPoint = new PointF(5, 5);
SolidBrush bForeColor = new SolidBrush(foreColor);
SolidBrush bBackColor = new SolidBrush(backColor);
Gimg.FillRectangle(bBackColor, 0, 0, width, height);
Gimg.DrawString(txt, imgFont, bForeColor, imgPoint);
Font fzFont = new Font("Arial", 9);
System.Drawing.Font fzFont = new System.Drawing.Font("Arial", 9);
SizeF textSize = Gimg.MeasureString(zusatz, fzFont, 50);
PointF imgPointZusatz= new PointF(width-textSize.Width-15, 30);
PointF imgPointZusatz = new PointF(width - textSize.Width - 15, 30);
Gimg.DrawString(zusatz, fzFont, bForeColor, imgPointZusatz);
return RotateImage(img, rotation,true,true,Color.White);
return RotateImage(img, rotation, true, true, Color.White);
//img.Save(imagePath, ImageFormat.Jpeg);
}
@@ -279,7 +335,7 @@ namespace ZZ_BarcpdeFromFont
gfx.InterpolationMode = InterpolationMode.HighQualityBicubic;
//now draw our new image onto the graphics object
gfx.DrawImage(img, new Point(0, 0));
gfx.DrawImage(img, new System.Drawing.Point(0, 0));
//dispose of our Graphics object
gfx.Dispose();
@@ -291,6 +347,213 @@ namespace ZZ_BarcpdeFromFont
{
}
}
public System.Drawing.Image AutoSizeImage(System.Drawing.Image oBitmap, int maxWidth, int maxHeight, bool bStretch = false)
{
// Größenverhältnis der max. Dimension
float maxRatio = (float)(maxWidth / (double)maxHeight);
// Bildgröße und aktuelles Größenverhältnis
int imgWidth = oBitmap.Width;
int imgHeight = oBitmap.Height;
float imgRatio = (float)(imgWidth / (double)imgHeight);
// Bild anpassen?
if (imgWidth > maxWidth | imgHeight > maxHeight | bStretch)
{
if (imgRatio <= maxRatio)
{
// Größenverhältnis des Bildes ist kleiner als die
// maximale Größe, in der das Bild angezeigt werden kann.
// In diesem Fall muss die Bildbreite angepasst werden.
imgWidth = (int)Math.Round(imgWidth / (imgHeight / (double)maxHeight));
imgHeight = maxHeight;
}
else
{
// Größenverhältnis des Bildes ist größer als die
// maximale Größe, in der das Bild angezeigt werden kann.
// In diesem Fall muss die Bildhöhe angepasst werden.
imgHeight = (int)Math.Round(imgHeight / (imgWidth / (double)maxWidth));
imgWidth = maxWidth;
}
// Bitmap-Objekt in der neuen Größe erstellen
var oImage = new Bitmap(imgWidth, imgHeight);
// Bild interpolieren, damit die Qualität erhalten bleibt
using (Graphics g = Graphics.FromImage(oImage))
{
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
g.DrawImage(oBitmap, new System.Drawing.Rectangle(0, 0, imgWidth, imgHeight));
}
// neues Bitmap zurückgeben
return oImage;
}
else
{
// unverändertes Originalbild zurückgeben
return oBitmap;
}
}
public static System.Drawing.Image ScaleImage(System.Drawing.Image image, int maxWidth, int maxHeight)
{
var ratioX = (double)maxWidth / image.Width;
var ratioY = (double)maxHeight / image.Height;
var ratio = Math.Min(ratioX, ratioY);
var newWidth = (int)(image.Width * ratio);
var newHeight = (int)(image.Height * ratio);
var newImage = new Bitmap(newWidth, newHeight);
using (var graphics = Graphics.FromImage(newImage))
graphics.DrawImage(image, 0, 0, newWidth, newHeight);
return newImage;
}
public static Image ScaleImage(Image image, int height)
{
double ratio = (double)height / image.Height;
int newWidth = (int)(image.Width * ratio);
int newHeight = (int)(image.Height * ratio);
Bitmap newImage = new Bitmap(newWidth, newHeight);
using (Graphics g = Graphics.FromImage(newImage))
{
g.DrawImage(image, 0, 0, newWidth, newHeight);
}
image.Dispose();
return newImage;
}
private void button3_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Word.Application word = new Microsoft.Office.Interop.Word.Application();
word.Documents.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\empty.docx");
FindAndReplaceImages(word.ActiveDocument, @"x:\gaga.png");
word.Visible = true;
}
private void FindAndReplaceImages(Document wordDoc, string imagePath)
{
var sec = wordDoc.Application.Selection.Sections[1];
foreach (Section wordSection in wordDoc.Sections)
{
var footer = sec.Footers[WdHeaderFooterIndex.wdHeaderFooterPrimary];
//var footerImage = footer.Shapes.AddShape(1, 0, 0, 594, 280);
var footerImage = footer.Shapes.AddShape(1, Convert.ToInt32(this.left), Convert.ToInt32(this.top), Convert.ToInt32(this.width), Convert.ToInt32(this.height));
footerImage.Fill.UserPicture(imagePath);
footerImage.WrapFormat.Type = WdWrapType.wdWrapThrough;
footerImage.WrapFormat.AllowOverlap = -1;
footerImage.WrapFormat.Side = WdWrapSideType.wdWrapBoth;
footerImage.RelativeHorizontalPosition = WdRelativeHorizontalPosition.wdRelativeHorizontalPositionPage;
footerImage.RelativeVerticalPosition = WdRelativeVerticalPosition.wdRelativeVerticalPositionPage;
footerImage.Top = (float)Convert.ToInt32(this.top);
}
}
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)
{
WordDocument document = new WordDocument();
document.Open(@"E:\Software-Projekte\OnDoc\Excel_Dateien\empty.docx");
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();
}
}
}