Hi,
1) i want to add and image and text in the signature field with specified size and i want to do that in the existing pdf with signature field ?
2) how to add any type of image [jpg, jpeg , png, etc.] in extsting pdf
static byte[] GenerateSignedPdf(Cert objCert)
{
// Dimensions and positions for the signature field
int signatureFieldWidth = 200;
int signatureFieldHeight = 50;
int signaturePositionLeft = 10;
int signaturePositionTop = 10;
// Load the certificate
X509Certificate2 certificate = new X509Certificate2(objCert.CertArray, objCert.Password);
// Create a SignatureField and assign the digital signature to it
SignatureField pdfSignature = new SignatureField("SignatureField");
pdfSignature.Signature = new Telerik.Windows.Documents.Fixed.Model.DigitalSignatures.Signature(certificate);
// Create a new form to place the signature field
Form pdfForm = new Form();
pdfForm.FormSource = new FormSource();
pdfForm.FormSource.Size = new Telerik.Documents.Primitives.Size(signatureFieldWidth, signatureFieldHeight);
FixedContentEditor editor = new FixedContentEditor(pdfForm.FormSource);
// Draw the text with certificate holder's name and current date
string textToDraw = $"{certificate.GetNameInfo(X509NameType.SimpleName, false)} {DateTime.Now:yyyy.MM.dd HH:mm}";
editor.DrawText(textToDraw, new Telerik.Documents.Primitives.Size(5, 5)); // Adjust position as needed
// Path to the image (ensure this is correct)
string imagePath = "C:/Vaibhav/ProjectVaibhav/PdfProcessing_InsertImageInExistingPdf/image.png"; // Change path as needed
// Ensure the image exists and can be accessed
if (File.Exists(imagePath))
{
using (var imageStream = new FileStream(imagePath, FileMode.Open, FileAccess.Read))
{
var imageSource = new ImageSource(imageStream);
editor.DrawImage(imageSource, new Telerik.Documents.Primitives.Size(100, 50)); // Adjust image size and position as needed
}
}
else
{
throw new FileNotFoundException("Image file not found at: " + imagePath);
}
// Create the SignatureWidget and position it on the PDF page
SignatureWidget signatureWidget = pdfSignature.Widgets.AddWidget();
signatureWidget.Content.NormalContentSource = pdfForm.FormSource;
signatureWidget.Rect = new Rect(signaturePositionLeft, signaturePositionTop, signatureFieldWidth, signatureFieldHeight);
signatureWidget.RecalculateContent();
// Create a RadFixedDocument and add a page
RadFixedDocument document = new RadFixedDocument();
RadFixedPage pdfPage = document.Pages.AddPage();
pdfPage.Annotations.Add(signatureWidget);
// Add content from the form to the page at the specified position
FixedContentEditor pageEditor = new FixedContentEditor(pdfPage);
pageEditor.Position.Translate(signaturePositionLeft, signaturePositionTop);
pageEditor.DrawForm(pdfForm.FormSource);
// Add the signature field to the document's AcroForm
document.AcroForm.FormFields.Add(pdfSignature);
// Use MemoryStream to capture the PDF output and return as a byte array
using (MemoryStream memoryStream = new MemoryStream())
{
var pdfFormatProvider = new PdfFormatProvider();
pdfFormatProvider.Export(document, memoryStream);
return memoryStream.ToArray(); // Return the byte array of the PDF
}
}
Hi,
I have an existing xlsx file that contains graphics (drawing)
I simply open the workbook,
var workbook = CreateWorkbook();
byte[] bytes;
using (var output = new MemoryStream())
{
new XlsxFormatProvider().Export(workbook, output);
bytes = output.ToArray();
}
File.WriteAllBytes("c:\\Logs\\test.xlsx", bytes);
private Workbook CreateWorkbook()
{
Workbook workbook;
IWorkbookFormatProvider formatProvider = new XlsxFormatProvider();
FileStream? stream = null;
try
{
stream = File.Open("AnalyseImpayeTemplate.xlsx", FileMode.Open);
workbook = formatProvider.Import(stream);
}
catch (IOException ex)
{
throw new IOException("The file cannot be opened. It might be locked by another application.", ex);
}
finally
{
stream?.Dispose();
}
return workbook;
}
When I open the result file, with release 2024.3.806, I got an error. It delete drawing parts :
Partie supprimée: /xl/drawings/drawing1.xml partie. (Forme de dessin)
With release 2024.2.426, it works fine.
Any ideas why?
I'm able to export data to an .xlsx file. That file is exported to E:/SaoApps/Sims/wwwroot/exports and the user has full control over that folder. The file successfully is created at that location. But the file doesn't open or offer download to the user and the error message is:
In the attached code snippet, the passed exportsFolder = "E:/SaoApps/Sims/wwwroot/exports/" and passed lanId = "DSS"
"An error occurred trying to start process 'E:/SaoApps/Sims/wwwroot/exports/ContactsSearchResults_DSS.xlsx' with working directory 'E:\\Workspace\\Intranet\\Sims\\Sims'. The process cannot access the file because it is being used by another process."
System.ComponentModel.Win32Exception (32): An error occurred trying to start process 'E:/SaoApps/Sims/wwwroot/exports/ContactsSearchResults_DSS.xlsx' with working directory 'E:\Workspace\Intranet\Sims\Sims'. The process cannot access the file because it is being used by another process.
Hello,
I am trying to upload the stream object received from the 'ToXlsxStream' method of Telerik SpreadSheet processing library to Azure blob container. Unfortunately, it is saving as a blank excel file. I have data in the List object which is getting converted to xlsx stream. Not sure why the excel file is blank. Tried to save the stream to my local file explorer as well. Still, the issue persists.
Below is the code:
try
{
Stream exportStream = exportFormat == SpreadDocumentFormat.Xlsx ? workOrderList.ToXlsxStream(columnsData, (string)options.title.ToString(), cellStyleAction: cellStyle) : workOrderList.ToCsvStream(columnsData);
Task.Factory.StartNew(() => AzureHelper.UploadReportOnCloud(exportStream,fileName, ConfigurationManager.AppSettings[Constant.REPORTATTACHMENTCONTAINER]));
}
catch(Exception ex)
{
}
Please help me to resolve this issue.
Hello,
I have a corrupted XLSX file from CSV dataSource
With other CSV dataSource all is ok
In example in file-attach, I added CSV dataSource with corruption
There are 2 bad lines in generated XLSX file and CSV file have a good format !!!
It's not an issue with codepage or separator !
It's a projet DotNet Core 6 with last version 2023.2.713.20 of API
Do you have encountered this error already ?
Best regards
Cyril REILER
Hi all,
I got some problems when I try to read my Excel file as below:
1. It skipped the null cells, it only read data at the cells having value. For example in my case, after reading cell 2 at row 2, it jumped to cell 14.
2. It showed the error message "The given key '3' was not present in the dictionary." at cell 15
You can see my code, the Excel file I used, and the result in below
My code
@page "/testpage"
@using Telerik.Documents.SpreadsheetStreaming;
<div>
@((MarkupString)(str.ToString()))
</div>
@code {
private StringBuilder str = new StringBuilder();
protected override void OnInitialized()
{
str = ReadData();
}
private StringBuilder ReadData()
{
try
{
string filename = ".\\Template.xlsx";
using (FileStream fs = new FileStream(filename, FileMode.Open))
{
using (IWorkbookImporter workBookImporter = SpreadImporter.CreateWorkbookImporter(SpreadDocumentFormat.Xlsx, fs))
{
foreach (IWorksheetImporter worksheetImporter in workBookImporter.WorksheetImporters)
{
foreach (IRowImporter rowImporter in worksheetImporter.Rows)
{
foreach (ICellImporter cell in rowImporter.Cells)
{
if(cell.Value!= null)
{
str.Append(cell.Value.ToString());
}
else
{
str.Append("NULL");
}
str.Append(",");
}
str.Append("<br/>");
}
}
}
}
return str;
}
catch(Exception ex)
{
str.Append("<br/>");
str.Append(ex.Message);
return str;
}
}
}
My Excel file as a picture below, I also attached my Excel in the question (Template.rar)
The result when I run
Everyone who know how to fix it, please help me.
Thank you