Telerik Forums
Telerik Document Processing Forum
1 answer
335 views
Is there a way to create a horizontal line in a document using the RadWordsProcessing API? I am looking for something similar to the Microsoft Word horizontal line that can be inserted by typing "---". 
Dimitar
Telerik team
 answered on 25 Oct 2021
1 answer
236 views

Hello,

I am exporting the text and image as shown in the attached program. The resulting output shows the text floating around the image which is left aligned:

What I want to achieve now is the reverse of it so that the image gets right-aligned with text aligning to the left and floating around the image on the right.

How do I do that?

Thanks,

Adnan

Dimitar
Telerik team
 answered on 18 Oct 2021
0 answers
225 views

Hello,

i'm trying to convert some docx to PDF. The resulting document looks quite similar to the original, however i have 2 main issues:

  • Bullet lists are not present on the exported document
  • Bold text is never present in the exported document
  • The exported pdf file doesn't seem to be a valid PDF/A-3U one checking with some online validator

 

i've attached a very simple example.

Here is the code i'm using to generate the pdf:


public byte[] Convert()
{
    //to support fonts
    Telerik.Windows.Documents.Extensibility.FontsProviderBase fontsProvider = new FontsProvider();
    Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.FontsProvider = fontsProvider;

    //to support PNG's
    Telerik.Windows.Documents.Extensibility.JpegImageConverterBase jpegImageConverter = new Telerik.Documents.ImageUtils.JpegImageConverter();
    Telerik.Windows.Documents.Extensibility.FixedExtensibilityManager.JpegImageConverter = jpegImageConverter;

    var importProvider = new DocxFormatProvider();
    byte[] templateData = GetTemplateData(); 
    var template = importProvider.Import(templateData);

    var pdfProvider = new PdfFormatProvider();
    PdfExportSettings settings = new();
    settings.ComplianceLevel = PdfComplianceLevel.PdfA3U;
    pdfProvider.ExportSettings = settings;
    var pdfBytes = pdfProvider.Export(template);
    return pdfBytes;
}

//... end class

public class FontsProvider : Telerik.Windows.Documents.Extensibility.FontsProviderBase
    {
        public override byte[] GetFontData(FontProperties fontProperties)
        {
            string fontFileName = fontProperties.FontFamilyName + ".ttf";
            string fontFolder = Environment.GetFolderPath(Environment.SpecialFolder.Fonts);
            string targetPath = Path.Combine(fontFolder, fontFileName);

            DirectoryInfo directory = new DirectoryInfo(fontFolder);
            FileInfo[] fontFiles = directory.GetFiles("*.ttf");
            if (fontFiles.Any(s => s.Name.Equals(fontFileName, StringComparison.InvariantCultureIgnoreCase)))
            {
                using (FileStream fileStream = File.OpenRead(targetPath))
                {
                    using (MemoryStream memoryStream = new MemoryStream())
                    {
                        fileStream.CopyTo(memoryStream);
                        return memoryStream.ToArray();
                    }
                }
            }

            return null;
        }
    }

 

am i missing something?

Thanks in advance for your help!

Carmine
Top achievements
Rank 1
 asked on 12 Oct 2021
0 answers
239 views

I try to import a pdf file from a external source. This contains a Typ3 font but I cannot import it.

My telerik version is 2021.2 so it should work. 

PdfViewer: Add support for Type 3 fonts (telerik.com) is completet in R1 2021.

I try to Import the file like this:

                var provider = new PdfFormatProvider();
                var document = provider.Import(File.ReadAllBytes(dokument.Hyperlink));

And I get this Exception: Cannot create TrueType font type from FontFile3 with Type1C subtype!

 

   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Fonts.FontFile3Stream.CreateOpenTypeFontSource(FontType fontType)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Fonts.FontFile3Stream.ToFontSource(FontType fontType)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Fonts.TrueTypeFontObject.TryCreateSimpleFontFromFontFile(SimpleFont& font)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Fonts.SimpleFontObject.TryCreateFontFromFontFile(FontBase& font)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Model.Elements.Fonts.FontObject.ToFont(PostScriptReader reader, IRadFixedDocumentImportContext context)
   at Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Import.RadFixedDocumentImportContext.GetFont(PostScriptReader reader, FontObject font)

 

 

How can I import them correctly?

Marco
Top achievements
Rank 1
Iron
Iron
Iron
 asked on 06 Oct 2021
2 answers
347 views

Hi

Recently I upgraded our c# project making use of the  Telerik.Documents.Spreadsheet.FormatProviders.OpenXml component from 2021.1.322 to  2021.2.50 (actually to the latest 2021.3.909 but in this case that doesn't matter.

I want to make use of the CONCAT function which is supported in this version.

After upgrading the unittests stopped working on the fact that the worksheet functions (after setting some values in the worksheet) are not completely executed/updated. After rolling back the version to 2021.1.322 it worked again (but the concat function is not supported).

Regards,

Bart Huls

 

Nikolay Demirev
Telerik team
 answered on 06 Oct 2021
9 answers
1.7K+ views
Hi

According to this thread it is possible to convert a DOCX file to a PDF. The code there no longer seems to work however.

The code I'm trying to run is:

RadDocument document = null;
IDocumentFormatProvider providerDocx = (IDocumentFormatProvider) new DocxFormatProvider();
using (FileStream stream = File.Open(@"C:\Test.docx", FileMode.Open))
{
    document = providerDocx.Import(stream);
}
 
PdfFormatProvider providerPdf = new PdfFormatProvider();
using (Stream output = File.Open(@"C:\Test.pdf", FileMode.Create))
{
    providerPdf.Export(document, output);
}


The error occurs on the last line: cannot convert from 'Telerik.Windows.Documents.Model.RadDocument' to 'Telerik.Windows.Documents.Fixed.Model.RadFixedDocument'

Is it still possible to convert from docx to PDF?
Tomáš
Top achievements
Rank 1
Iron
Iron
 answered on 30 Sep 2021
1 answer
425 views

Hello!

Have an issue w/ merging specific PDFs.  One thing that we noticed is we get the error when the following version of the Telerik.Windows.Documents.Fixed package:      <PackageReference Include="Telerik.Windows.Documents.Fixed" Version="2020.2.504" />

but it works correctly with the following package from 2018:

    <PackageReference Include="Telerik.Windows.Documents.Fixed">
      <Version>2018.1.220.40</Version>

Trying to figure out what the differences are between those package versions and if there is a work around for the 2020 version so we don't have to use the 2018 package.

The Code is failing on the provider.Import:

                    using (var pdfInputStream = GetPdfDocumentStream(client, uri))
                    {
                        RadFixedDocument document = provider.Import(pdfInputStream);
                        mergedPdf.Merge(document);
                    }

Thanks!

Martin
Telerik team
 answered on 29 Sep 2021
1 answer
3.6K+ views

 

I have problem with converting HTML to PDF with c# coding. Namely, I go through next steps:

1) creating HtmlFormatProvider

2) registering event LoadStyleSheetFromUri

3) importing Stream with HTML content. Content contains reference to bootstrap.css, Bootstrap v4.3.1 (https://getbootstrap.com/)

4) creating PdfFormatProvider

5) exporting to pdf.

Complete code is following:

       public async static Task<InputSignDocument> CreateDemoDocument(string wwwPath, string fileName, string extension, string recipientName, string recipientEmail, Func<Task<Stream>> getPdfStream)
        {
            var result = new InputSignDocument()
            { 
                FileName = fileName,
                FileExtension = extension,
            };

            Stream inpuContent = await getPdfStream(); // here is reading html into stream
            var htmlProvider = new HtmlFormatProvider();

            HtmlImportSettings importSettings = new HtmlImportSettings();

            importSettings.LoadStyleSheetFromUri += (s, e) =>
            {
                  string styles = File.ReadAllText($"{wwwPath}\\{e.Uri}");

                e.SetStyleSheetContent(styles);
            };
            importSettings.DefaultStyleSheet = "body {white-space: normal;}";
            htmlProvider.ImportSettings = importSettings;

            RadFlowDocument doc;
           using (StreamReader reader = new StreamReader(inpuContent))
            {
                string htmlText = reader.ReadToEnd();
                doc = htmlProvider.Import(htmlText);
            }

            var pdfProvider = new Telerik.Windows.Documents.Flow.FormatProviders.Pdf.PdfFormatProvider();

            PdfExportSettings exportSettings = new PdfExportSettings()
            {

            };
            pdfProvider.ExportSettings = exportSettings;

            result.FileContent = new MemoryStream();
            pdfProvider.Export(doc, result.FileContent);

            return result;
        }

 

PDF is created however no bootstrap classes are apllied.

In debug session I look in variable (string styles) in event, css file was read properly.

HTML contains two references:

<link rel="stylesheet" href="/lib/bootstrap/dist/css/bootstrap.css" />
<link rel="stylesheet" href="/css/site.css" />
From event I see that both files are exported.

In HTML, namely, in razor view are used bootstrap classes: container, col-lg-6, col-md-6, col-sm-6, row.

rhey are applied this way:

<div class="container">
    <div class="row">
        <div class="col-lg-6 col-md-6 col-sm-6">
            <div class="row">
                <div class="col-lg-4 col-md-4 col-sm-4">
                    <label>Werknemer</label>
                    <div>
                        /fnm1/
                    </div>
                </div>

                <label></label>
                <div class="col-lg-4 col-md-4 col-sm-4">
                    <label>Handtekening</label>
                    <div>
                        /sn1/
                        <hr />
                    </div>
                </div>

                <div class="col-lg-4 col-md-4 col-sm-4 docusign-basetab">
                    <label>Aangetekend op</label>
                    <div>
                        /ds1/
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

It seems that this part css is not applied in PDF File.

What I am missing?

When I run the view from controller it shows me this:

 

And in pdf it looks like this:

                  
Dimitar
Telerik team
 answered on 29 Sep 2021
5 answers
2.3K+ views
Hi,

I am trying to convert a HTML body to a PDF using HtmlFormatProvider and PdfFormatProvider. 

It works well when I try to create a pdf with "normal" characters, but when I use characters like "åäö" the characters is either missing or replaced with other character. 

I have seen a similiar issue that recommended to load in the fonts, but that did not solve the issue for me. 

I have added the code in a zip as an attchment to this issue. 

 

Thanks in advance.

Dimitar
Telerik team
 answered on 24 Sep 2021
1 answer
128 views

Is it possible to create AND password protect certain sections of a docx document using Blazor WordsProcessing?

 

MM

Dimitar
Telerik team
 answered on 23 Sep 2021
Narrow your results
Selected tags
Tags
+? more
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Anislav
Top achievements
Rank 6
Silver
Bronze
Bronze
Jianxian
Top achievements
Rank 1
Iron
Marco
Top achievements
Rank 3
Iron
Iron
Iron
Jim
Top achievements
Rank 2
Iron
Iron
Nurik
Top achievements
Rank 2
Iron
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?