Telerik Forums
Telerik Document Processing Forum
1 answer
13 views

I am trying to create a pdf page using the pdfprocessing library.

The page has a number of tables with mostly text and a few images. I think I am ok with handling these.

I am building up the page in a RadFixedPage added to a RadFixedDocument.

However, in one of the table cells I need to be able to insert a block of rtf formatted text.

This is user entered using a RadRichTextBox and saved to a string field in code-behind using RtfDataProvider

A typical block of rtf may be:

{\rtf1\ansi\ansicpg1252\uc1\deff0\deflang1033{\fonttbl{\f0 Segoe UI;}{\f1 Times New Roman;}{\f2 Verdana;}}{\colortbl\red0\green0\blue0 ;\red0\green176\blue80 ;\red255\green192\blue0 ;\red250\green250\blue250 ;\red0\green0\blue255 ;}{\*\defchp\ltrch\f0\fs18\i0\b0\strike0\cf0\ulc0\ulnone}{\*\defpap\sl276\slmult1\ql\sa180\ltrpar}{\stylesheet{\s0\sqformat\spriority0\ltrch\f0\fs18\i0\b0\strike0\cf0\ulc0\ulnone\sl276\slmult1\ql\ltrpar Normal;}{\*\ts2\tsrowd\spriority59\trbrdrt\brdrnone\trbrdrb\brdrnone\trbrdrl\brdrnone\trbrdrr\brdrnone\trbrdrh\brdrnone\trbrdrv\brdrnone\trgaph0\trpaddl75\trpaddr75\trpaddt0\trpaddb0\clpadft3\clpadt0\clpadfr3\clpadr0\clpadfl3\clpadl0\clpadfb3\clpadb0\tsvertalt\ltrch\f0\fs18\i0\b0\strike0\cf0\ulc0\ulnone\sl276\slmult1\ql\sa180\ltrpar Table Normal;}{\s3\spriority99\ltrch\f0\fs18\i0\b0\strike0\cf0\ulc0\ulnone\sl276\slmult1\ql\sb100\sa100\sbauto1\saauto1\ltrpar Normal (Web);}}\nouicompat\viewkind4\sectd\headery720\footery720\pard\sl276\slmult1\qc\ltrpar{\ltrch\f0\fs18\i\b\strike0\cf1\cb2\highlight2\ulc0\ulnone line }{\ltrch\f0\fs18\i0\b0\strike0\cf0\ulc0\ulnone 1}{\ltrch\f0\fs18\i0\b0\strike0\cf0\ulc0\ulnone\par}\pard\sl276\slmult1\ql\ltrpar{\ltrch\f1\fs18\i\b0\strike0\cf0\cb3\highlight3\ulc0\ulnone sDefaultStyleSettings}{\ltrch\f1\fs18\i0\b0\strike0\cf0\cb3\highlight3\ulc0\ulnone =}{\ltrch\f1\fs18\i0\b0\strike0\cf4\cb3\highlight3\ulc0\ulnone "True"}{\ltrch\f0\fs18\i0\b\strike0\cf0\ulc0\ulnone\par}\pard\sl276\slmult1\ql\ltrpar{\ltrch\f0\fs18\i0\b0\strike0\cf0\ulc0\ulnone linr 3s}{\ltrch\f0\fs18\i0\b\strike0\cf0\ulc0\ulnone lin 2}{\ltrch\f1\fs18\i0\b0\strike0\cf0\cb3\highlight3\ulc0\ulnone DocumentInherit}{\ltrch\f0\fs18\i0\b\strike0\cf0\ulc0\ulnone\par}}

 

For inserting normal text I have been using

            row = table.Rows.AddTableRow();
            cell = row.Cells.AddTableCell();
            cell.Blocks.AddBlock().InsertText(Language.Language.ProductName);

any suggestions how I can insert rtf rather than plain text?

Thanks

Andrew

Yoan
Telerik team
 answered on 26 Feb 2024
0 answers
17 views
Hello! I'm currently attempting to transform an HTML body into a PDF using HtmlFormatProvider, RadFlowDocument, and PdfFormatProvider.

Everything functions good when generating a PDF with standard characters. However, when incorporating characters such as "ćšđž," these specific characters seem to be missing.

Could you kindly provide guidance on resolving this issue?
Sanja Tolo
Top achievements
Rank 1
Iron
Iron
 asked on 09 Feb 2024
1 answer
42 views

My C# project targets net6.0-windows and enables windows forms:

<PropertyGroup>
 <TargetFramework>net6.0-windows</TargetFramework>
 <ImplicitUsings>enable</ImplicitUsings>
<UseWindowsForms>true</UseWindowsForms>
 <Nullable>enable</Nullable>
 </PropertyGroup>

In the code, I want to create PDF documents dynamically and show them by using the PdfViewer component.

Thus, I added the following references:

<PackageReference Include="Telerik.Documents.Core" Version="2023.3.1106" />
<PackageReference Include="Telerik.Documents.Fixed" Version="2023.3.1106" />
<PackageReference Include="Telerik.Documents.Flow" Version="2023.3.1106" />
<PackageReference Include="Telerik.Documents.Flow.FormatProviders.Pdf" Version="2023.3.1106" />
<PackageReference Include="Telerik.Zip" Version="2023.3.1106" />
<PackageReference Include="UI.for.WinForms.AllControls.Net60" Version="2023.3.1114" />

Here is a part of my code:


    internal class GenericPdfCombiner : IPdfCombiner
    {
        public RadFixedDocument Combine(List<string> fileNames)
        {
            using MemoryStream stream = new MemoryStream();
            using (PdfStreamWriter fileWriter = new PdfStreamWriter(stream, leaveStreamOpen: true))
            {
                for (var fi = 0; fi < fileNames.Count; fi++)
                {
                    var file = fileNames[fi];
                    using PdfFileSource fileSource = new PdfFileSource(new MemoryStream(File.ReadAllBytes(file)));
                    for (var p = 0; p < fileSource.Pages.Length; p++)
                    {
                        PdfPageSource sourcePage = fileSource.Pages[p];
                        using PdfPageStreamWriter resultPage = fileWriter.BeginPage(sourcePage.Size);
                        resultPage.WriteContent(sourcePage);
                    }
                }
            }
            PdfFormatProvider provider = new PdfFormatProvider();
            return provider.Import(stream);
        }
    }

but it shows the error Reference to type 'Size' claims it is defined in 'WindowsBase', but it could not be found on the lines like the following:

using PdfPageStreamWriter resultPage = fileWriter.BeginPage(sourcePage.Size);

How can I fix it?

Dess | Tech Support Engineer, Principal
Telerik team
 answered on 03 Jan 2024
1 answer
29 views

I'm trying to convert a word document to PDF and the images and shapes it contains, along with their text, do not make it into the PDF. Are these not yet supported? 

The attached zip contains the original document and the result of the conversion.

The conversion code is pretty straightforward, basically just

DocxFormatProvider docxProvider = new DocxFormatProvider();
var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();
RadFlowDocument document = null;

using (Stream input = File.OpenRead("WordDocWithGraphics.docx"))
{
    document = docxProvider.Import(input);
}

using (Stream output = File.OpenWrite(("WordDocWithGraphics.pdf"))
{
    pdfProvider.Export(document, output);
}

Yoan
Telerik team
 answered on 18 Dec 2023
1 answer
58 views

I am writing an application that that generates a pdf presentation based on a pdf "template" file.  The template file contains one or more images. The application replaces the images in the template file with other images the user has called out. 

How can I name or "tag" the placeholder images in the template file in order to identify what goes where?   

I thought of using the accessibility/alternative text field of each image but I understand that is not currently accessible via the Telerik library.

Are there other fields I could use to place identifiers assocated with the images?

I want to use Adobe acrobat to edit the template file and add the tags if possible.

Thanks. 

Yoan
Telerik team
 answered on 30 Nov 2023
2 answers
376 views

Greetings All,

Is there any way that the text that i am entrering into Block can be formated for Underline and Strikethrough .

 

I was able to achieve other properties like Bold , Italix with statements like 

block testblock =testCell.Blocks.AddBlock();

testblock. TextProperties.Font = FontsRepository.TimesItalic;

 

 

Luk
Top achievements
Rank 1
Iron
 updated answer on 06 Oct 2023
1 answer
35 views

Hi,

I get HTML in my code and I have the image byte in another file. I want to combine it to export my HTML to PDF with images. This is what I do, and it only works with a single image, on the second iteration I got an error in importSettings.LoadImageFromUri (Method = <Internal Error evaluating expression>). What can I do to add multiple images in the importSettings? I don't see an example in the documentation.


foreach (var img in imageList)
{               
  EventHandler<LoadImageFromUriEventArgs> loadImageFromUri = (s, e) =>
  {
    
    byte[] data = img.ContentBytes;
    e.SetImageInfo(data, "jpg");
  };

  importSettings.LoadImageFromUri += loadImageFromUri;                          
}

Thanks

Martin
Telerik team
 answered on 03 Oct 2023
1 answer
106 views

Hi all,

This is a fragment from my code where I use tables in a RadFlowDocument to list some values. This all works fine for me, except one thing: between the text in a cell en the bottom border of that cell is some white space I can't get rid of. I want the bottom border of the cell to have the same distance to the text in the cell as between the text and the top border (border color set to blue for debugging..)

Tried playing with the row Height, cell padding, etc., but that doesn't change anything.

What am I missing?

  

var doc = new RadFlowDocument(); var tableStyle = new Style("TableStyle", StyleType.Table); tableStyle.TableProperties.Borders.LocalValue = new TableBorders(new Border(1, BorderStyle.Single, new ThemableColor(Colors.Blue))); tableStyle.TableProperties.Alignment.LocalValue = Alignment.Left; tableStyle.TableCellProperties.VerticalAlignment.LocalValue = VerticalAlignment.Top; tableStyle.TableCellProperties.Padding.LocalValue = new Padding(0, 0, 0, 0); tableStyle.TableRowProperties.TableCellSpacing.LocalValue = 0; tableStyle.CharacterProperties.FontSize.LocalValue = 12; doc.StyleRepository.Add(tableStyle); var section = new Section(doc) { PageMargins = new Padding(50, 50, 50, 50), PageNumberingSettings = { StartingPageNumber = 1, } }; doc.Sections.Add(section); var paragraph = new Paragraph(doc); section.Blocks.Add(paragraph); Table table = new Table(doc, 0, 2)// 0 rows, 2 columns. { LayoutType = TableLayoutType.FixedWidth, PreferredWidth = new TableWidthUnit(700), StyleId = "TableStyle" };
// add 2 rows with 2 cells TableRow row = table.Rows.AddTableRow(); TableCell cell = row.Cells.AddTableCell(); cell.PreferredWidth = new TableWidthUnit(100); paragraph = cell.Blocks.AddParagraph(); paragraph.Inlines.AddRun($"Cell R1C1"); cell = row.Cells.AddTableCell(); cell.PreferredWidth = new TableWidthUnit(600); paragraph = cell.Blocks.AddParagraph(); paragraph.Inlines.AddRun("Cell R1C2"); cell = row.Cells.AddTableCell(); cell.PreferredWidth = new TableWidthUnit(100); paragraph = cell.Blocks.AddParagraph(); paragraph.Inlines.AddRun($"Cell R2C1"); cell = row.Cells.AddTableCell(); cell.PreferredWidth = new TableWidthUnit(600); paragraph = cell.Blocks.AddParagraph(); paragraph.Inlines.AddRun("Cell R2C2");


Kind regards,

Kees Alderliesten

Vladislav
Telerik team
 answered on 13 Sep 2023
0 answers
109 views
1 answer
115 views

I've searched and searched and I cannot find any information around using Telerik.Documents.Fixed with PDF's that have XFA forms.   Is this possible?   And if so is there any sample code showing how to do it?

Thanks.

 

Yoan
Telerik team
 answered on 21 Jul 2023
Narrow your results
Selected tags
Tags
+? more
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
horváth
Top achievements
Rank 2
Iron
Iron
Steve
Top achievements
Rank 2
Iron
Erkki
Top achievements
Rank 1
Iron
Mark
Top achievements
Rank 2
Iron
Iron
Veteran
Jakub
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?