Hi,
we have editable PDFs which are stored in a database. We used to be able to pull the PDFs, import them through the Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider to get a RadFixedDocument, iterate through the fields of this document and fill them with data. Afterwards, we exported the PDF through the PdfFormatProvider and wrote them to a file. This gave us the original PDF but filled with the required data.
This does not work anymore, as the resulting exported PDF is visually broken. We have no clue why that happens, maybe you can help us fix this.
I attached a small sample project with our work flow including one of the PDFs we try to fill out and the resulting PDF for you to analyze.
Thanks a lot in advance.
Hello,
I've been using Telerik.Web.Pdf to automate filling in the following EPA form from their website: EPA Form 3540-1- Notice of Arrival of Pesticides and Devices | US EPA
This has worked well until the 2024.4.1112 update. Now using the standard import method:
var provider = new PdfFormatProvider();
using Stream stream = System.IO.File.OpenRead(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Resources\\EPA-3540-1.pdf"));
var document = provider.Import(stream, TimeSpan.FromSeconds(10));
I get a Telerik.Windows.Docments.Fixed.Exceptions.NotSupportedActionException, with message "Action is not supported: Named"
I don't see any PDFImportSettings I can play with to possibly disable (Javascript?) and process as with the .3.806 version. Are there any suggestions for me to try?
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
}
}