I have a table that has a variable number of columns (from 2 to 6)
I set preferredWidth based on number of columns as follows:
table1.PreferredWidth = new TableWidthUnit(TableWidthUnitType.Percent, 100);
I am inserting images into each table cell, but I want specify the size of the image based on the cell width
How do I get the cell width?
var inImage = table1.Rows[x].Cells[y].Blocks.AddParagraph().Inlines.AddImageInline();
var cellWidth =??
inImage.Image.Size = new System.Windows.Size(cellWidth, cellWidth);
Hi All,
For the PDF Processing , I have to attache a single table row and there will be two cells.(some thing which is simillar to the attachment).
1.First cell constitutes of Question.
2.Second Sells constitues of a table.
It his scenario possible?
Regards,
JP
Hello!
Faced an incomprehensible problem.
When trying to open a workbook, an exception is thrown:
ArgumentOutOfRangeException: Index and count must refer to a location within the string. (Parameter 'count')
At the same time, everything works fine on the working computer during development, there is no exception.
The problem pops up when placing a project on a hosting.
The library from Syncfusion in a similar environment opens the file normally on the hosting.
Library version 2020.3.1019
.net5 Server-side project
private void LoadFile()
{
try
{
string path = Path.Combine(Path.GetPathRoot(Environment.SystemDirectory), "Templates", $"temp.xlsx");
using FileStream stream = new FileStream(path, FileMode.Open, FileAccess.Read);
XlsxFormatProvider formatProvider = new XlsxFormatProvider();
// Getting exception there while hosted
using Workbook workbook = formatProvider.Import(stream);
}
catch (Exception error)
{
NotificationReference.Show(new NotificationModel()
{
Text = $"{error.GetType().Name}: {error.Message}",
ThemeColor = "primary"
});
}
}
Attached a project to demonstrate some issues we're seeing that need resolving in order to use the component.
1. When using a font like Tahoma on a form field, the value no longer displays or contains garbled text.
2. Input file is 24KB, output is 2MB!
3. Rotated field lose their rotation after being flattened.
4. Simulate merging with other files, 100 times the file is now 150MB! It's as though it's not re-using the fonts, but keeps adding the same ones.
5. when merging, but not flattening, the form fields are all lost on pages after page 1.
using
System;
using
System.Collections.Generic;
using
System.IO;
using
System.Linq;
using
Telerik.Windows.Documents.Fixed.FormatProviders.Pdf;
using
Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Streaming;
using
Telerik.Windows.Documents.Fixed.Model;
using
Telerik.Windows.Documents.Fixed.Model.Annotations;
using
Telerik.Windows.Documents.Fixed.Model.Editing;
using
Telerik.Windows.Documents.Fixed.Model.InteractiveForms;
using
Telerik.Windows.Documents.Fixed.Model.Resources;
namespace
FlattenFormFieldsDemo
{
class
Program
{
static
void
Main(
string
[] args)
{
PdfFormatProvider provider =
new
PdfFormatProvider();
RadFixedDocument document = provider.Import(File.ReadAllBytes(
"InteractiveForms.pdf"
));
foreach
(RadFixedPage page
in
document.Pages)
{
foreach
(Annotation annotation
in
page.Annotations)
{
if
(annotation.Type == AnnotationType.Widget)
{
Widget widget = (Widget) annotation;
if
(widget.Field
is
TextBoxField field)
{
field.Value =
"John Doe"
;
}
}
}
}
FlattenFormFields(document);
string
resultFile =
"Flattened.pdf"
;
if
(File.Exists(resultFile))
{
File.Delete(resultFile);
}
File.WriteAllBytes(resultFile, provider.Export(document));
MergeMultipleFiles(resultFile);
}
public
static
void
MergeMultipleFiles(
string
filename)
{
using
(PdfStreamWriter fileWriter =
new
PdfStreamWriter(File.OpenWrite(
"MergedFlattened.pdf"
)))
{
// Iterate through the files you would like to merge
for
(
int
i = 0; i< 100; i++)
{
// Open each of the files
using
(PdfFileSource fileToMerge =
new
PdfFileSource(File.OpenRead(filename)))
{
// Iterate through the pages of the current document
foreach
(PdfPageSource pageToMerge
in
fileToMerge.Pages)
{
// Append the current page to the fileWriter, which holds the stream of the result file
fileWriter.WritePage(pageToMerge);
}
}
}
}
}
public
static
void
FlattenFormFields(RadFixedDocument document)
{
foreach
(RadFixedPage page
in
document.Pages)
{
List<Widget> widgetsToRemove =
new
List<Widget>();
FixedContentEditor pageEditor =
new
FixedContentEditor(page);
foreach
(Annotation annotation
in
page.Annotations)
{
if
(annotation.Type == AnnotationType.Widget)
{
Widget widget = (Widget)annotation;
FlattenWidgetAppearance(pageEditor, widget);
widgetsToRemove.Add(widget);
}
}
foreach
(Widget widget
in
widgetsToRemove)
{
page.Annotations.Remove(widget);
}
}
foreach
(FormField field
in
document.AcroForm.FormFields.ToArray())
{
document.AcroForm.FormFields.Remove(field);
}
}
private
static
void
FlattenWidgetAppearance(FixedContentEditor pageEditor, Widget widget)
{
FormSource widgetAppearance = GetWidgetNormalAppearance(widget);
if
(widgetAppearance ==
null
)
return
;
pageEditor.Position.Translate(widget.Rect.Left, widget.Rect.Top);
pageEditor.DrawForm(widgetAppearance, widget.Rect.Width, widget.Rect.Height);
}
private
static
FormSource GetWidgetNormalAppearance(Widget widget)
{
FormSource widgetAppearance;
switch
(widget.WidgetContentType)
{
case
WidgetContentType.PushButtonContent:
widgetAppearance = ((PushButtonWidget)widget).Content.NormalContentSource;
break
;
case
WidgetContentType.SignatureContent:
widgetAppearance = ((SignatureWidget)widget).Content.NormalContentSource;
break
;
case
WidgetContentType.VariableContent:
widgetAppearance = ((VariableContentWidget)widget).Content.NormalContentSource;
break
;
case
WidgetContentType.TwoStatesContent:
TwoStatesButtonWidget twoStatesWidget = (TwoStatesButtonWidget)widget;
widgetAppearance = GetTwoStatesWidgetNormalAppearance(twoStatesWidget);
break
;
default
:
throw
new
NotSupportedException(
string
.Format(
"Not supported widget content type {0}"
, widget.WidgetContentType));
}
return
widgetAppearance;
}
private
static
FormSource GetTwoStatesWidgetNormalAppearance(TwoStatesButtonWidget twoStatesWidget)
{
FormField field = twoStatesWidget.Field;
bool
isOnState;
switch
(field.FieldType)
{
case
FormFieldType.CheckBox:
CheckBoxField checkBox = (CheckBoxField) field;
isOnState = checkBox.IsChecked;
break
;
case
FormFieldType.RadioButton:
RadioButtonField radio = (RadioButtonField) field;
RadioButtonWidget radioWidget = (RadioButtonWidget) twoStatesWidget;
if
(radio.ShouldUpdateRadiosInUnison)
{
isOnState = radio.Value !=
null
&& radio.Value.Value.Equals(radioWidget.Option.Value);
}
else
{
isOnState = radio.Value == radioWidget.Option;
}
break
;
default
:
throw
new
NotSupportedException(
string
.Format(
"Not supported field type {0} for TwoStateButtonWidget"
, field.FieldType));
}
FormSource widgetAppearance = (isOnState ? twoStatesWidget.OnStateContent : twoStatesWidget.OffStateContent).NormalContentSource;
return
widgetAppearance;
}
}
}
Good day all.
I am developing an application using C# WinForms and Telerik 2020.1.218.40 that needs to take pre-filled PDF forms and display the page images as static documents. I have been able to read the PDFs and split the documents into individual pages, which when viewed using Microsoft Edge's PDF rendering, displays the forms with data, but when loaded into a RadPdfViewer, only displays the form image without any of the completed data.
Any help in displaying the form data is appreciated.
private static readonly string uploadPath = "H:\\TEMP\\DMSUpload\\";
string splitNameTemplate = Path.Combine(uploadPath, "SplitPage-{0}.pdf");
using (FileStream fs = new FileStream(uploadPath + "TEMP.PDF", FileMode.OpenOrCreate))
{
RadFixedDocument document = new PdfFormatProvider().Import(fs);
using (FileStream writeStream = new FileStream(uploadPath + "FOO.PDF", FileMode.OpenOrCreate))
{
PdfFormatProvider provider = new PdfFormatProvider();
provider.Export(document, writeStream);
using (PdfFileSource fileSource = new PdfFileSource(writeStream))
{
for (int i = 0; i < fileSource.Pages.Length; i++)
{
using (PdfStreamWriter fileWriter = new PdfStreamWriter(File.OpenWrite(string.Format(splitNameTemplate, i + 1))))
{
PdfPageSource pageSource = fileSource.Pages[i];
fileWriter.WritePage(pageSource);
}
}
}
}
}
pdfViewer.LoadDocument(uploadPath + "SplitPage-1.pdf");
In your example, located at https://github.com/telerik/xaml-sdk/blob/master/PdfProcessing/CreateDocumentWithImages/MainViewModel.cs , you go through how to encode a dual tone image. I have tried to apply this same logic to an 32 bit ARGB image, one directly from RadChartView.ExportToImage, but the image comes out in gray scale and not even in the correct dimensions. I am not sure what I am missing, I've even changed the color space from DeviceGray to DeviceRGB with no luck and set bits per component to 8. I am calculating stride and data correct array size correctly...
Thanks.
Hi
In the documentation for CsvFormatProvider (https://docs.telerik.com/devtools/document-processing/libraries/radspreadprocessing/formats-and-conversion/csv/settings) it is decribed that you can use Settings.Encoding to set the encoding when exporting.
How does it work when importing a file? Does CsvFormatProvider automatically detect the encoding of the provided file? Or do I need to ensure that files that I import always have a certain encoding?
Thanks!
In the process of evaluating the PDF functionality provided by Telerik so we can switch components (hopefully).
Is there a way to add a watermark to an existing PDF using another PDF as that watermark?
Thanks.
Hi,
I am looking at the WordsProcessing to use in a project to convert HTML to PDF, however I have two issues. One the CSS from the linked files are not being applied so the first and easy question is must this be inline styles \ css in the cshtml file
The second is how do I get the output to show as landscape. My code below shows you how I am currently doing it and it is pushing out the HTML table and data but no styles from bootstrap (mentioned above) but its also very squashed so I need it to be in a landscape format.
public
byte
[] ConvertDocumentToPDF(
byte
[] fileData,
string
extension, ImageQuality exportQuality)
{
byte
[] convertedData =
null
;
RadFlowDocument document;
IFormatProvider<RadFlowDocument> provider =
this
.providers
.FirstOrDefault(p => p.SupportedExtensions
.Any(e =>
string
.Compare(extension, e, StringComparison.InvariantCultureIgnoreCase) == 0));
if
(provider ==
null
)
{
Log.Error($
"No provider found that supports the extension: {extension}"
);
return
null
;
}
try
{
using
(Stream stream =
new
MemoryStream(fileData))
{
try
{
document = provider.Import(stream);
}
catch
(Exception ex)
{
Log.Error(ex.ToString());
return
null
;
}
}
var quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.Medium;
switch
(exportQuality)
{
case
ImageQuality.High:
quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.High;
break
;
case
ImageQuality.Medium:
quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.Medium;
break
;
case
ImageQuality.Low:
quality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.Low;
break
;
}
PdfFormatProvider formatProvider =
new
PdfFormatProvider();
formatProvider.ExportSettings.ImageQuality = quality;
using
(var stream =
new
MemoryStream())
{
formatProvider.Export(document, stream);
convertedData = stream.ToArray();
}
}
catch
(Exception ex)
{
Log.Error(ex.ToString());
}
return
convertedData;
}
Any and all help gratefully received.
Thanks
Hi all,
My company has historically used an ActiveX control to produce certain documents, created as PDFs, for printing or sending via email. With the move to a new development environment we lost support for ActiveX and need to switch to the Telerik document controls.
We wrote a program using the following Telerik objects:
Telerik.Windows.Documents.Fixed.Model.RadFixedDocument.
Telerik.Windows.Documents.Fixed.Model.RadFixedPage.
Telerik.Windows.Documents.Fixed.Model.Editing.FixedContentEditor.
This works fine for most of the document creation, but we have a need to add language specific to each of our customers to the document. This language comes from each customer in an RTF file. The old control had a method to add the RTF file to the document flow, and it used the RTF metadata to add the properly formatted text to the document. Can you tell me if the Telerik document model has the ability to do this? And what objects/methods would be best to use? If it doesn't support RTF specifically, but has this ability for other formats, I can convert the RTF file to PDF, DOCX, etc. Thanks.