Telerik Forums
Telerik Document Processing Forum
1 answer
255 views
I want to learn more about Word processing and how to create tables in the Word document.
Unfortunately I only ever see c# code.
Can someone show me an example for VB.NET ?
A simple table with cell contents..
Yoan
Telerik team
 answered on 13 Jul 2023
1 answer
423 views


Hi all, 

I got some problems when I try to read my Excel file as below:

1. It skipped the null cells, it only read data at the cells having value. For example in my case, after reading cell 2 at row 2, it jumped to cell 14. 

2. It showed the error message "The given key '3' was not present in the dictionary." at cell 15

You can see my code, the Excel file I used, and the result in below

My code

@page "/testpage"
@using Telerik.Documents.SpreadsheetStreaming;
<div>
    @((MarkupString)(str.ToString()))
</div>


@code {
    private StringBuilder str = new StringBuilder();
    protected override void OnInitialized()
    {
        str = ReadData();
    }
    private StringBuilder ReadData()
    {

        try
        {
            string filename = ".\\Template.xlsx";
            using (FileStream fs = new FileStream(filename, FileMode.Open))
            {
                using (IWorkbookImporter workBookImporter = SpreadImporter.CreateWorkbookImporter(SpreadDocumentFormat.Xlsx, fs))
                {
                    foreach (IWorksheetImporter worksheetImporter in workBookImporter.WorksheetImporters)
                    {
                        foreach (IRowImporter rowImporter in worksheetImporter.Rows)
                        {
                            foreach (ICellImporter cell in rowImporter.Cells)
                            {
                                if(cell.Value!= null)
                                {
                                    str.Append(cell.Value.ToString());

                                }
                                else
                                {
                                    str.Append("NULL");
                                }
                                str.Append(",");
                            }
                            str.Append("<br/>");
                        }

                    }
                }
            }
            return str;
        }
        catch(Exception ex)
        {
            str.Append("<br/>");
            str.Append(ex.Message);
            return str;
        }

    }
}
 My Excel file as a picture below, I also attached my Excel in the question (Template.rar)

  The result when I run 

  Everyone who know how to fix it, please help me.

Thank you

Yoan
Telerik team
 answered on 04 Jul 2023
1 answer
214 views

Hi all,

 

I would like to replace a temporary page content (a placeholder text) with an image in a Pdf. In order to do this, I use the telerik solution here.

My problem is that it doesn't work always : it often bugs because the placeholder text seems to be splitted in multiple text fragment.

Here is an example :

In my document : the placeholder text

The text fragments found in pdf :

And sometimes it works well:

Is there any solution to help me with this please?

 

Thank you,
Regards,
Adrian

Martin
Telerik team
 answered on 28 Jun 2023
0 answers
300 views

I have a method like so that takes HTML and returns a PDF: 

private static Stream ConvertToPdf(string htmlFileContent)
{
	var htmlProvider = new HtmlFormatProvider();

	var htmlDocument = htmlProvider.Import(htmlFileContent);

	var pdfProvider = new PdfFormatProvider();

	var pdfMemoryStream = new MemoryStream();

	pdfProvider.Export(htmlDocument, pdfMemoryStream);

	pdfMemoryStream.Position = 0;

	return pdfMemoryStream;
}

This method works perfectly on my local Windows dev box, but when I run it in a Fargate container in AWS ECS, I get the following exception if the HTML contains an image:

System.NotSupportedException: Not supported image format.
   at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.DoOnUnknownData(Byte[] unknownData, ImageQuality imageQuality, Action`1 doOnEncodedData)
   at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.InitializeImageInfoFromUnknownData(Byte[] unknownData, ImageQuality imageQuality)
   at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.EnsureImageInfo()
   at Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource.get_Width()
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Objects.ImageXObject.CopyPropertiesFrom(IPdfExportContext context, ImageSource imageSource)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExportContext.GetResource(ImageSource resource)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfContentExportContext.GetResource(ImageSource imageSource)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ImageWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, Image element)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.MarkableContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ClippingWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, Clipping clipping)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentRootWriter.WriteOverride(PdfWriter writer, IPdfContentExportContext context, IContentRootElement element)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriter`1.Write(PdfWriter writer, IPdfContentExportContext context, Object element)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ContentElementWriters.ContentElementWriterBase.WriteElement(PdfWriter writer, IPdfContentExportContext context, Object element)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.ContentStream.BuildContentData(IPdfExportContext context, IResourceHolder resourceHolder, IContentRootElement contentRootElement)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.Page.CopyPropertiesFrom(IPdfExportContext context, RadFixedPage fixedPage)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyRadFixedPageProperties(RadFixedPage source, Page destination, IRadFixedDocumentExportContext context)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPagePropertiesFrom(IRadFixedDocumentExportContext context)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.DocumentStructure.DocumentCatalog.CopyPropertiesFrom(IRadFixedDocumentExportContext context)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExporter.Export(IRadFixedDocumentExportContext context, Stream output)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(RadFixedDocument document, Stream output)
   at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Export(T document, Stream output)
   at Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider.ExportOverride(RadFlowDocument document, Stream output)
   at Telerik.Windows.Documents.Common.FormatProviders.FormatProviderBase`1.Export(T document, Stream output)
All of those Telerik.Windows.Documents.* namespaces make me skeptical. I am referencing the .NET Standard NuGet packages from the Telerik feed, so they should work on Linux, right?
Dev
Top achievements
Rank 1
 asked on 15 Jun 2023
1 answer
138 views
 I want to create new file , is possible import header and footer from exist docx file ?
Aleks
Telerik team
 answered on 15 Jun 2023
1 answer
308 views

When creating a PDF is there a way to nest a table within another table without having to be specific of the tables Y position?  I actually have 3 tables that can look like this:

Table1 - Row1

Table2 - Row1

Table3 - Row1
Table3 - Row2

Table1 - Row2

The number of rows per table is determined by the data, so I don't necessarily know where I am on the page.  Do I have to increase some kind of counter for each line, cause that would be miserable?  I wish there were more extensive examples for creation of Pdf's.  I have seen the Developer Focused examples none of them even come close to what I am trying to accomplish.  

Yoan
Telerik team
 answered on 15 Jun 2023
1 answer
123 views

Hi.

I'd like to be able to put certain strings in a Word document, and then programmatically have everything between those strings removed.  The following works, when STARTREPLACE and ENDREPLACE are on the same line.

RadFlowDocument document = provider.Import(inputFileStream);

RadFlowDocumentEditor editor = new RadFlowDocumentEditor(document);

editor.ReplaceText(new Regex("(?<=STARTREPLACE)(.*)(?=ENDREPLACE)", RegexOptions.Singleline), string.Empty);

However when STARTREPLACE and ENDREPLACE are not on the same line, nothing happens.

Anyone have any idea how I can make this work over multiple lines - or if there's another approach which would be better?

Thanks in advance!

Dean

Yoan
Telerik team
 answered on 13 Jun 2023
1 answer
249 views

I'm creating a spreadsheet Workbook, then exporting it to PDF. Each cell I write has a custom style where the FontSize is being set to 9 (and I'm also setting up fills and font effects, like bold).

When I get through writing the data to the Worksheet(s) in the Workbook, I then call AutoFitWidth on the Columns that have data.

Finally, I use the PdfFormatProvider to write the entire Workbook to a PDF file.

My problem is that text items in the cells are being clipped, even when there is room to fit them after calling AutoFitWidth.

For example:

It seems to be worse on strings with all caps. Sometimes it's just half a letter, other times it's multiple letters (the ATMOSPHERICCORR is supposed to be ATMOSPHERICCORROSION).

Here's another export in a different format:

As you can see, there's two problems based on calculating the required width. First is that AutoFitWidth is not giving enough space (mostly in the second example), but as you can see in the first example, even when there is enough horizontal space, it's still clipping off the text area within the cell.

Is the estimation assuming no caps, or is the font size/font family throwing it off (9pt)? Or am I missing something where I can force it to make more space?

Dimitar
Telerik team
 answered on 29 May 2023
1 answer
90 views

Hi - I'm trying to open accessible Word document (with stuff like tags, alternative text on images, etc.), but when I'm saving in to PDF all of that is gone. Looking at this: https://docs.telerik.com/devtools/document-processing/libraries/radpdfprocessing/howto/comply-with-pdfa-standard I've tried to set `ComplianceLevel` but nothing has changed, pdf is inaccessbile. Should I set something additional? Is this supported?

Version I'm using is: 2023.1.104, platform is .NET 7

I've attached the code that I'm running and the template that I'm working on.

Dimitar
Telerik team
 answered on 26 May 2023
0 answers
202 views

Hi there,

 

I need to create a pdf with various different tabs. So, I work with RadPdfProcessing.

In order to create a next page when there is no more place on the current page, I set a method that measures the available size on the page (without margin) and the size of the object to draw, before drawing it. If there is enough space, I draw it on current page, if not, I create a new page and draw it on.
But when I run my code, some tables are drawn in the margin of my page, as you can see on attached pictures.
I don't understant why. And when debugging, measures are working fine...
Could someone explain me what I'm missing or doing wrong please?

Here is my code :

Code about measuring object and page creation

        public static readonly Size _pageSize = new(Unit.MmToDip(210), Unit.MmToDip(297));
        public static readonly Thickness _margins = new(Unit.MmToDip(15));

        public static DocumentContainer CreateNewPage(RadFixedDocument document)
        {
            var page = document.Pages.AddPage();
            var editor = new DocumentContainer(page, _pageSize, new Padding(_margins.Top, _margins.Right, _margins.Bottom, _margins.Left));
            //if not first page, position the editor between margins 
            if(document.Pages.Count != 1) 
                editor.Position.Translate(_margins.Left, _margins.Top);
            return editor;
        }

        public static DocumentContainer CheckRemainingSpaceAndCreateNewPageIfNeeded(IBlockElement elementToDraw, DocumentContainer editor, RadFixedDocument document)
        {
            var remainingHeight = editor.PageHeight - _margins.Bottom  - editor.Position.Matrix.OffsetY;
            var neededSize = elementToDraw.Measure(new Size(editor.PageInternWidth, editor.PageInternHeight));

            if(remainingHeight < neededSize.Height)
            {
                return CreateNewPage(document);
            }

            return editor;
        }

 

Code about table creation

        public static Table CreateTable(BorderStyle borderStyle = BorderStyle.None)
        {
            return new Table
            {
                Borders = new TableBorders(new Border(borderStyle)),
                LayoutType = TableLayoutType.FixedWidth,
            };
        }

And the code about table drawing


        private Table DrawOneStyleTable(...)
        {
            var oneCellPadding = new Thickness(Unit.MmToDip(5));
            var anotherCellPadding = new Thickness(Unit.MmToDip(5), Unit.MmToDip(2), Unit.MmToDip(5), Unit.MmToDip(2));

            //Add table
            Table table = Helper.CreateTable();
            table.DefaultCellProperties.Padding = new Thickness(5);

            table.Borders = new TableBorders(new Border(2, BorderStyle.Single, mycolor));

            //Add rows

            _editor = Helper.CheckRemainingSpaceAndCreateNewPageIfNeeded(table, _editor, _document);
            _editor.DrawTable(table, _editor.PageInternWidth);
            return table;
        }

        private Table DrawSecondStyleTable(...)
        {
            //Add table and row
            Table table = Helper.CreateTable();
            //Add content

            _editor = Helper.CheckRemainingSpaceAndCreateNewPageIfNeeded(table, _editor, _document);
            _editor.DrawTable(table, _editor.PageInternWidth);
            return table;
        }

 

Please do not hesitate to ask me more information if needed.

 

Thank you in advance for your help,
Regards,
Adrian

Adrian
Top achievements
Rank 1
Iron
 asked on 25 May 2023
Narrow your results
Selected tags
Tags
+? more
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Rob
Top achievements
Rank 3
Iron
Iron
Iron
Atul
Top achievements
Rank 1
Iron
Iron
Alexander
Top achievements
Rank 1
Veteran
Iron
Serkan
Top achievements
Rank 1
Iron
Shawn
Top achievements
Rank 1
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?