Hello,
Thanks for contacting us.
Now the issue has been resolved and it is under testing. Once the hotfix is available, I will let you know.
Sincerely,
Jane
E-iceblue support team
private void btnAddimage_Click(object sender, RoutedEventArgs e)
{
var path = @"1.pdf";
var outputPath = Path.Combine("split_Addimage", Path.GetDirectoryName(path));
using (var Doc = new PdfDocument(path))
{
string pattern = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(path) + "_{0}.pdf");
Doc.Split(pattern, 1);
}
path = @"2.pdf";
using (var Doc = new PdfDocument(path))
{
string pattern = Path.Combine(outputPath, Path.GetFileNameWithoutExtension(path) + "_{0}.pdf");
Doc.Split(pattern, 1);
}
foreach (var doc in Directory.GetFiles(outputPath)) //used to get all the splitted docuemtns
{
using (var pdfDocument = new PdfDocument(File.ReadAllBytes(doc)))
{
var imagePath = "sig\\BuyerInitials.png";
var fileNameWOExt = Path.Combine(Path.GetDirectoryName(doc),Path.GetFileNameWithoutExtension(doc)) ;
ExportImage(pdfDocument, fileNameWOExt + ".pdf");
PdfImage pdfImageInit = PdfImage.FromFile(imagePath);
System.Drawing.RectangleF location = new System.Drawing.Rectangle(497, 753, 27, 18);
AddSignatureToPdf(pdfDocument, location, pdfImageInit);
pdfDocument.SaveToFile(fileNameWOExt + "_first.pdf");
ExportImage(pdfDocument, fileNameWOExt + "_first.pdf");
var imagePath2 = "sig\\BuyerSignature.png";
PdfImage pdfImageInit2 = PdfImage.FromFile(imagePath2);
System.Drawing.RectangleF location2 = new System.Drawing.Rectangle(397, 753, 27, 18);
AddSignatureToPdf(pdfDocument, location2, pdfImageInit2);
pdfDocument.SaveToFile(fileNameWOExt + "_second.pdf");
ExportImage(pdfDocument, fileNameWOExt + "_second.pdf");
}
}
}
private void AddSignatureToPdf(PdfDocument pdfDocument, System.Drawing.RectangleF rect, PdfImage pdfImage)
{
PdfPageBase page0 = pdfDocument.Pages[0];
if (pdfImage.Width > 0 && pdfImage.Height > 0)
{
float imageAspectRatio = (float)pdfImage.Width / (float)pdfImage.Height;
float newWidth = imageAspectRatio * rect.Height;
if (newWidth <= rect.Width)
{
float delta = rect.Width - newWidth;
rect.X += delta / 2f;
rect.Width = newWidth;
}
else
{
imageAspectRatio = (float)pdfImage.Height / (float)pdfImage.Width;
float newHeight = imageAspectRatio * rect.Width;
float delta = rect.Height - newHeight;
rect.Y += delta;
rect.Height = newHeight;
}
}
page0.Canvas.DrawImage(pdfImage, rect);
}
private void ExportImage(PdfDocument pdfDocument, string finalPdfPath)
{
Application.Current.Dispatcher.Invoke(() =>
{
using (var doc = new PdfDocument(finalPdfPath))
SaveImage(doc.SaveAsImage(0, 192D, 192D), finalPdfPath + "_grf.jpg" /*+ ".png"*/);
});
}