How can i add borders to the first page or section?
I find the property borders in Paragraph, but i cant find it in Section, how can i add the border to the full page or section?
Example attached.
Regard
I am trying to programmatically reproduce a header, and nothing I've tried will add a background color or shading. How do you format a table in a header?
HtmlFormatProvider provider = new HtmlFormatProvider();
RadFlowDocument html = provider.Import(sb.ToString());
Section section = html.Sections[0];
section.PageMargins = new Telerik.Windows.Documents.Primitives.Padding(24);
ThemableColor gray = new ThemableColor(new System.Windows.Media.Color {R = 220, G = 220, B = 220});
Header header = section.Headers.Add();
Table table = header.Blocks.AddTable();
TableRow row1 = table.Rows.AddTableRow();
TableCell Title = row1.Cells.AddTableCell();
TableCell Version = row1.Cells.AddTableCell();
Title.PreferredWidth = new TableWidthUnit(384);
Title.Shading.BackgroundColor = gray;
Title.Blocks.AddParagraph().Inlines.AddRun("Executive Summary");
Version.PreferredWidth = new TableWidthUnit(384);
Version.Shading.BackgroundColor = gray;
Version.Blocks.AddParagraph().Inlines.AddRun("Version Name:");
TableRow row2 = table.Rows.AddTableRow();
TableCell Incident = row2.Cells.AddTableCell();
TableCell Period = row2.Cells.AddTableCell();
Incident.Blocks.AddParagraph().Inlines.AddRun("Incident:");
Period.Blocks.AddParagraph().Inlines.AddRun("Period:");
PdfFormatProvider pdf = new PdfFormatProvider();
return pdf.Export(html);
The attached Header.png is an example of what I'm trying to reproduce.
Hi,
I have: Telerik UI for ASP.NET AJAX
I test SplitDocumentPages from PDF example. from https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/ManipulatePages/Program.cs
net.framework: 4.8
test pdf is: https://github.com/telerik/document-processing-sdk/blob/master/PdfProcessing/ManipulatePages/InputFiles/MultipageDocument.pdf
Not working well. see picture split1.pdf, only large rectangle without any data.
Please help.
Thx
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?
Hi
I have a problem with row height when processing docx files and exporting to pdf.
Export does not respect the height of a table row if the height of a given row is lower than the content of cells in that row. However, if the height of the row is greater than the content, then it is ok.
During processing, a given row has its height set as Exact and a specific value in pixels, but after export, the height of a given row in the table adjusts to the content.
Maybe there is a workaround for this problem?
I have the following code that shows the bold formatting from HTML to PDF appears inconsistent.
The last table has all the cells wrapped in <b>
tags, but they are not rendered bold in the PDF. There seems to be some correlation to the length of the text (short text sometimes will be bold). I have also tried <strong>
tags and CSS that applies bold. It does not matter which font is chosen.
Inconclusive observation: It appears that if the bold text line wraps inside a cell, it doesn’t apply bold. Text that does not wrap in the cell appears to apply bold.
Any help appreciated.
using RegServices.Portal.Web.Services.Pdf;
using Telerik.Documents.ImageUtils;
using Telerik.Windows.Documents.Flow.FormatProviders.Html;
using Telerik.Windows.Documents.Flow.Model;
using Xunit.Abstractions;
namespace Portal.Web.Tests.Pdf;
public class PdfBoldRenderTests : OutputTestBase
{
private readonly IHtmlToWordConverter _htmlToWordConverter = new HtmlToWordConverter();
string path = "c:\\\\temp\\\\pdf\\\\";
public PdfBoldRenderTests(ITestOutputHelper output) : base(output)
{
}
[Fact]
public void CanRenderBold()
{
var html = $$"""
<!DOCTYPE html>
<html lang="en">
<head>
<title>Test</title>
<style>
body {
font-family: Arial;
}
.bold {
font-weight: bold;
}
.font-bold {
font-weight: 800;
}
.font-black {
font-weight: 800;
}
</style>
</head>
<body>
<table>
<tr>
<td>
The quick brow fox. Regular text <br>
<b>The quick brow fox. Bold text</b><br>
<span class="bold">The quick brow fox. Bold text via css</span><br>
</td>
<td>
<table>
<tr>
<td>
The quick brow fox. Regular text <br>
<b>The quick brow fox. Bold text</b><br>
<span class="bold">The quick brow fox. Bold text via css</span><br>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="2">
<table>
<tbody>
<tr>
<td class="w-2-24">
<b>Financial year</b>
</td>
<td>
<b>General Services Charge (range)</b><em>(weekly)</em>
<span class="font-black">General Services Charge (range)</span>
</td>
<td class="w-2-24">
<b>Overall % change from previous year </b>
</td>
<td>
<b>
Maintenance Reserve Fund contribution (range)
</b>
<em>(weekly)</em>
</td>
<td class="w-2-24">
<b>Overall % change from previous year</b>
<em>(+ or -)</em>
</td>
</tr>
</table>
</td>
</tr>
</table>
<b>The quick brow fox. Bold text</b><br>
<table>
<tbody>
<tr>
<td class="w-2-24">
<b>Financial year</b>
</td>
<td>
<b>Bold Text</b><em>(weekly)</em>
<span class="font-black">General Services Charge (range)</span>
</td>
<td class="w-2-24">
<b>Bold Text</b>
</td>
<td>
<b>
Bold Text
</b>
<em>(weekly)</em>
</td>
<td class="w-2-24">
<b>Bold Text</b>
<em>(+ or -)</em>
</td>
</tr>
</tbody>
</table>
<b>The quick brow fox. Bold text</b><br>
<table>
<tr>
<td>
<b>I am a bold text</b>
</td>
<td>
<b>I am a bold text
</b><em>(weekly)</em>
</td>
<td>
<b>I am a bold text</b>
</td>
<td>
<b>
I am a bold text test test
</b>
<em>(weekly)</em>
</td>
<td>
<b>I am a bold text test</b>
</td>
</tr>
</table>
</body>
</html>
""";
var htmlDocument = _htmlToWordConverter.ConvertHtmlToWord(html);
var docxProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Docx.DocxFormatProvider();
Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider =
new FontsProvider();
using var memoryStream = new MemoryStream();
docxProvider.Export(htmlDocument, memoryStream);
var documentBytes = memoryStream.ToArray();
File.WriteAllBytes($"{path}Test.docx", documentBytes);
var (pdfBytes, pdfDoc) = PdfConverter.ConvertDocxToPdf(documentBytes);
File.WriteAllBytes($"{path}Test.pdf", pdfBytes);
var provider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
using Stream pdfStream = File.OpenWrite($"{path}Test2.pdf");
provider.Export(pdfDoc, pdfStream);
}
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[] bytes, RadFlowDocument doc) 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);
pdfProvider.ExportToFixedDocument(document);
return (memoryStream.ToArray(), document);
}
}
}
I tried doing the following:
using Stream stream = File.OpenRead(fileName); RadFixedDocument pdfDocument = new PdfFormatProvider().Import(stream); RadFixedDocument pdfNew = new(); pdfNew.Pages.Add(pdfDocument.Pages.First());
I get the following error:
System.ArgumentException: 'The document element is associated with another parent. (Parameter 'item')'
Is there a way to clone a page, so it can be added to another document?
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!