I am having trouble getting some HTML converted to PDF to render Unicode checkboxes.
\u2612 ☒ and \u2610 ☐
They appear ok in the word conversion, but are missing in PDF
Here is the same code
using Telerik.Documents.ImageUtils;
using Telerik.Windows.Documents.Flow.FormatProviders.Html;
using Telerik.Windows.Documents.Flow.Model;
namespace Web.Tests.Pdf;
public class PdfRenderTests
{
private readonly IHtmlToWordConverter _htmlToWordConverter = new HtmlToWordConverter();
string path = "c:\\\\temp\\\\pdf\\\\";
[Fact]
public void CanRenderCheckbox()
{
var html = "<span class=\"checkbox\">\u2612 Yes \u2610 No</span>";
var htmlDocument = _htmlToWordConverter.ConvertHtmlToWord(html);
var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
using var memoryStream = new MemoryStream();
docxProvider.Export(htmlDocument, memoryStream);
var documentBytes = memoryStream.ToArray();
File.WriteAllBytes($"{path}Test.docx", documentBytes);
var pdfBytes = PdfConverter.ConvertDocxToPdf(documentBytes);
File.WriteAllBytes($"{{path}}Test.pdf", pdfBytes);
}
}
public interface IHtmlToWordConverter
{
RadFlowDocument ConvertHtmlToWord(string html);
}
public class HtmlToWordConverter : IHtmlToWordConverter
{
public RadFlowDocument ConvertHtmlToWord(string html)
{
var htmlFormatProvider = new HtmlFormatProvider();
return htmlFormatProvider.Import(html);
}
}
public static class PdfConverter
{
static PdfConverter()
{
var defaultImagePropertiesResolver = new ImagePropertiesResolver();
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.ImagePropertiesResolver =
defaultImagePropertiesResolver;
}
public static byte[] ConvertDocxToPdf(byte[] docxBytes)
{
var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
var document = docxProvider.Import(docxBytes);
using var memoryStream = new MemoryStream();
pdfProvider.Export(document, memoryStream);
return memoryStream.ToArray();
}
}
PDF Output:
Word Output
Greetings,
I am using Telerik 2024.3.802 PdfProcessing library.
We have used the Telerik library to convert a HTML document to Word DOCX format.
This process completes successfully.
Then using Telerik PdfProcessing, executing a Word to PDF process.
The method throws an exception shown below.
The code is fairly trivial:
public static byte[] ConverDocxToPdf(byte[] docxBytes)
{
var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
var document = docxProvider.Import(docxBytes);
using var memoryStream = new MemoryStream();
pdfProvider.Export(document, memoryStream);
return memoryStream.ToArray();
}
If we open the Telerik produced docx file, in word, and resave it (no changes)
Then the Word to PDF process works. So it may imply there is an error in the HTML to word conversion which is creating a invalid docx file.
Is there anyway to "validate" a docx file with the Telerik tooling?
EDIT: When using this OpenXML validator: https://learn.microsoft.com/en-us/office/open-xml/word/how-to-validate-a-word-processing-document?tabs=cs-0%2Ccs against the Telerik created word docx file, I get a list of 51 errors. So Telerik Html to Docx perhaps is not creating a valid docx for various nodes.
Here are the list of errors
Error 1
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:footerReference'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.SectionProperties
Error 2
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 3
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 4
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 5
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 6
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 7
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 8
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 9
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 10
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 11
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 12
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 13
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 14
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 15
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 16
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 17
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 18
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 19
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 20
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 21
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 22
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 23
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 24
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 25
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 26
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 27
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 28
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 29
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 30
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 31
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 32
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 33
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 34
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 35
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 36
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 37
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 38
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tr'. List of possible elements expected: <http://schemas.openxmlformats.org/wordprocessingml/2006/main:tblGrid>.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.Table
Error 39
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
Error 40
Description: The element has unexpected child element 'http://schemas.openxmlformats.org/wordprocessingml/2006/main:tcBorders'.
ErrorType: Schema
Node: DocumentFormat.OpenXml.Wordprocessing.TableCellProperties
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!
Hi folks,
we have a requirement for a PDF that we must draw a table with different columns counts and sizes. Our approach is to generate a defined number of cells in a row (18) and merge them appropriately as we need them. Find a test below.
void AddSecondTable(RadFixedPage page)
{
var blackBorder = new Border(1, new RgbColor(0, 0, 0));
var editor = new FixedContentEditor(page);
editor.Position.Translate(Unit.CmToDip(2), Unit.CmToDip(2));
var table = new Table
{
LayoutType = TableLayoutType.AutoFit,
DefaultCellProperties =
{
Padding = new Thickness(5, 5, 5, 5),
Borders = new TableCellBorders(blackBorder, blackBorder, blackBorder, blackBorder)
}
};
for (var rowIndex = 0; rowIndex < 10; rowIndex++)
{
var row = table.Rows.AddTableRow();
for (var cellIndex = 0; cellIndex < 18; cellIndex++)
{
var cell = row.Cells.AddTableCell();
cell.PreferredWidth = Unit.CmToDip(1);
var b = cell.Blocks.AddBlock();
b.InsertText(new FontFamily("Helvetica"), FontStyles.Normal, FontWeights.Normal, $"Cell: {cellIndex}");
}
var firstCell = row.Cells[0];
firstCell.ColumnSpan = 4;
}
editor.DrawTable(table, Unit.CmToDip(18));
}
We expect that the first cell be placed over the first four columns, but nothing happens at all. What do we miss here?
Further, we would expect that the next cell starts with cellIndex 4, as the first four (0-3) are “merged”.
I am generating a RadFlowDocument, and at the end protecting the entire document with a custom password like below..
editor.Protect("TestPassword");
Hi there,
I am trying to generate a list on the position of a named bookmark in an template.
The list is generated and looks fine, but is a positioned at the very end of the document.
The code looks very similar to my code for generating a table on the position of a bookmark, but for a list it does not work.
Does anyone kwows what is going wrong? Is a section always generated at the very end of the document?
Thank for your help!
My code:
var bookmark = bookmarks.FirstOrDefault(b => b.Bookmark.Name == "PaymentMilestones");
if (bookmark is not null)Hi I am looking for code to add a table to a template with a bookmark:
The first step in my code is to go to the named bookmark, then I generate the table, but the table is not attached to location of the bookmark, but shows at the very end of the document.
var bookmark = bookmarks.FirstOrDefault(b => b.Bookmark.Name == "PricingTable");
Hi,
We've been using the DocFormatProvider and DocxFormatProvider to convert from DOC to DOCX. Most documents convert okay. However, we've noticed some really old documents (late 90's) contain an image (or object) type called PBrush. I'm guessing it's from the old PaintBrush program. Is there any option to keep these when converting?
Thanks
Daniel
Here's a trivial example that demonstrates this and the file as well, confused because it works on your "InteractiveForms.pdf" file. The file can be found on the Canadian government site, see link below.
PdfFormatProvider provider = new PdfFormatProvider();
RadFixedDocument document = provider.Import(File.OpenRead("t661-fill-20e.pdf"));