firstly loading the document i have use
// Load the PDF document
var provider = new PdfFormatProvider();
var loadedDocument = provider.Import(inDocByte,null);
and after some functinality to export the document i have used below
Telerik.Documents.ImageUtils.ImagePropertiesResolver defaultImagePropertiesResolver = new Telerik.Documents.ImageUtils.ImagePropertiesResolver();
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver = defaultImagePropertiesResolver;
provider.Export(document, memoryStream, null);
outDocPdf = memoryStream.ToArray();
what was the problem can you tell me the solution for that exception
Unable to cast object of type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfLiteralString' to type 'Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Types.PdfName'. |
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
}
}
How can i add borders to the first page or section?
I find the property borders in Paragraph, but i cant find it in Section, how can i add the border to the full page or section?
Example attached.
Regard
I am trying to programmatically reproduce a header, and nothing I've tried will add a background color or shading. How do you format a table in a header?
HtmlFormatProvider provider = new HtmlFormatProvider();
RadFlowDocument html = provider.Import(sb.ToString());
Section section = html.Sections[0];
section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(24);
ThemableColor gray = new ThemableColor(new System.Windows.Media.Color {R = 220, G = 220, B = 220});
Header header = section.Headers.Add();
Table table = header.Blocks.AddTable();
TableRow row1 = table.Rows.AddTableRow();
TableCell Title = row1.Cells.AddTableCell();
TableCell Version = row1.Cells.AddTableCell();
Title.PreferredWidth = new TableWidthUnit(384);
Title.Shading.BackgroundColor = gray;
Title.Blocks.AddParagraph().Inlines.AddRun("Executive Summary");
Version.PreferredWidth = new TableWidthUnit(384);
Version.Shading.BackgroundColor = gray;
Version.Blocks.AddParagraph().Inlines.AddRun("Version Name:");
TableRow row2 = table.Rows.AddTableRow();
TableCell Incident = row2.Cells.AddTableCell();
TableCell Period = row2.Cells.AddTableCell();
Incident.Blocks.AddParagraph().Inlines.AddRun("Incident:");
Period.Blocks.AddParagraph().Inlines.AddRun("Period:");
PdfFormatProvider pdf = new PdfFormatProvider();
return pdf.Export(html);
The attached Header.png is an example of what I'm trying to reproduce.
Hi,
I have: Telerik UI for ASP.NET AJAX
I test SplitDocumentPages from PDF example. from https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/ManipulatePages/Program.cs
net.framework: 4.8
test pdf is: https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/ManipulatePages/InputFiles/MultipageDocument.pdf
Not working well. see picture split1.pdf, only large rectangle without any data.
Please help.
Thx
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?