During export operation of a document that contains signature fields the following error occurs:
System.InvalidOperationException: 'The signature was not properly initialized for external signing. The signing delegate is missing.'Setting the ComplianceLevel to PdfA3B and the TaggingStrategy to UseExisting when exporting a PDF document leads to the following Error reported by VeraPdf:
Specification: ISO 19005-3:2012, Clause: 6.2.11.5, Test number: 1 For every font embedded in a conforming file and used for rendering, the glyph width information in the font dictionary and in the embedded font program shall be consistent. Glyph width 274.4140625 in the embedded font program is not consistent with the Widths entry of the font dictionary (value 272)
Resaving a document with Acrobat throws an error due to invalid Info dictionary in document trailer.
You need to explicitly set the correct MIME type when embedding the file into the PDF. This is especially important for standards like PDF/A-3 and Factur-X, which require strict metadata and MIME type declarations for embedded files.
The default value /application/octet-stream is too generic and not compliant for XML attachments.
Corrupted document when exporting "Courier New" subset.
Workaround - fully embed the font:
var pdfFormatProvider = new PdfFormatProvider();
pdfFormatProvider.ExportSettings.FontEmbeddingType = FontEmbeddingType.Full;
The TextProperties.FontSize property specifies the font size for text fragments. The property is of type double. The measurement unit used for font size in RadPdfProcessing is Device Independent Pixels (DIPs). You can convert it to points or other units using the Unit class.
However, when using the TextProperties with widgets the font conversion is not correct. Let's consider the case that we build a PDF document with a TextBoxField occupying a specific rectangle. According to the set text value, we should calculate the appropriate font size so the whole content can fit in the widget's rectangle.
/// <summary>
/// Creates a TextBoxField with calculated font size for the given rectangle
/// </summary>
private static TextBoxField CreateTextBoxWithCalculatedFont(string name, string text, Rect rect, double fontSize, FontBase font)
{
TextBoxField field = new TextBoxField(name);
field.TextProperties.FontSize = Unit.DipToPoint(fontSize);
field.TextProperties.Font = font;
field.Value = text;
var widget = field.Widgets.AddWidget();
widget.Rect = rect;
widget.Border.Width = 0;
widget.TextProperties.FontSize = Unit.DipToPoint(fontSize);
widget.TextProperties.Font = font;
return field;
}
/// <summary>
/// Calculates the optimal font size for text to fit within a specific rectangle
/// </summary>
public static double CalculateFontSizeForRectangle(string text, Rect rect, FontBase font)
{
double fontSize = 0;
Size measuredSize = new Size(0, 0);
Size availableSize = rect.Size;
while (measuredSize.Width<availableSize.Width && measuredSize.Height< availableSize.Height)
{
fontSize++;
Block block = new Block();
block.TextProperties.FontSize = fontSize;
block.TextProperties.Font = font;
block.InsertText(text);
measuredSize = block.Measure();
}
return fontSize-1;
} // Example: Wide textbox with calculated font size
string wideText = "This is a wide textbox that demonstrates horizontal fitting of text content.";
Rect wideRect = new Rect(200, 500, 400, 30);
double wideFontSize = CalculateFontSizeForRectangle(wideText, wideRect, font);
TextBoxField wideTextBoxField = CreateTextBoxWithCalculatedFont("WideTextBox", wideText, wideRect, wideFontSize, font);
document.AcroForm.FormFields.Add(wideTextBoxField);
var wideWidget = wideTextBoxField.Widgets.First();
page.Annotations.Add(wideWidget);
wideWidget.RecalculateContent();
When exporting a PDF page to an image with the SkiaImageFormatProvider the following error occurs:
System.IndexOutOfRangeException: 'Index was outside the bounds of the array.'