We need to print a GridView and are implementing the code found in "GridView | Print and Print Preview" example in the WPF Desktop Examples 2024 Q4 app but are encountering two issues also present in the Telerik-provided example.
1) Changes made in Print Preview are not carried over when the Print button is pressed. For example, if you change to Landscape/Legal in Print Preview, this will revert back to Portrait/Letter when Print is clicked.
2) Clicking Print on the Print Preview window shoves the Print Preview window to the background and if Cancel is clicked on the Print window, the user has to Alt-Tab through windows to find the Print Preview window to close it.
We need to set a spreadsheet font to Courier New in a WPF app using telerik.ui.for.wpf.60.xaml\2024.2.514. As a first step, we do:
using System.Windows;
using Telerik.Documents.Common.Model;
namespace WpfApp4;
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
var fontFamily = new ThemableFontFamily("Courier New");
}
}
Which is fine until we add a required cross-platform project referencing telerik.documents.core\2024.2.426
Then we get:
The type 'ThemableFontFamily' exists in both 'Telerik.Documents.Core, Version=2024.2.426.20, Culture=neutral, PublicKeyToken=5803cfa389c90ce7' and 'Telerik.Windows.Documents.Core, Version=2024.2.426.60, Culture=neutral, PublicKeyToken=5803cfa389c90ce7'
Ambiguous reference.
Candidates are:
Telerik.Documents.Common.Model.ThemableColor
Telerik.Documents.Common.Model.ThemableColor
What is the proper fix for this to reference the version in the WPF app project?
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 see Sreadsheet processing has row removal feature but it seems you need to know the range of rows you want to remove.
How would you recommend acheiving something like a trim functionality? Excel spreadsheets in my experience are notorious for having potenatially pages and pages of empty rows after all the actual content. In fact I am working with one like that now.How can I get rid of those empty rows?
Thank you!