Telerik Forums
Telerik Document Processing Forum
4 answers
1.3K+ views

Hi,

as a proof of concept, I want to load a Docx in a Kendo Editor and save it back. So far, I'm able to

  1. load a Docx, convert it to HTML
  2. then using Telerik ASP.Net MVC Editor I'm able to modify the HTML
  3. Save it back to a new Docx document

The issues I have is that the new docx don't have the same margins as the original document and it also takes 4 pages instead of 2. You can take a look at the screenshots attached (before/after).

 

Is there a way to configure the styles and the page setup ?

 

here is the code that I use. Basically, I have a Kendo Editor in my view that loads the HTML and a button to save back the data

 

[HttpPost]
public ActionResult Editor(string editor)
{
    // HTML decode the value before using it.
    var notes = System.Web.HttpUtility.HtmlDecode(editor);
      
    var htmlProvider = new HtmlFormatProvider();
    RadFlowDocument document = htmlProvider.Import(notes);
 
    SaveDocx(document);
     
    return View();
}
 
public ActionResult Editor()
{
    RadFlowDocument sourceDoc = GetSourceDocument();
    SaveDocx(sourceDoc);
    var myHtmlContent = GetHtmlFromDocument(sourceDoc);
 
    ViewBag.MyHtmlContent = myHtmlContent;
 
    return View();
}
 
private RadFlowDocument GetSourceDocument()
{
    var docxProvider = new DocxFormatProvider();
    var stream = new MemoryStream(System.IO.File.ReadAllBytes(@"c:\Temp\TelerikMvcApp1\TelerikMvcApp1\Fiche.docx"));
    RadFlowDocument document;
 
    using (Stream input = System.IO.File.OpenRead(@"c:\Temp\TelerikMvcApp1\TelerikMvcApp1\Fiche.docx"))
    {
        document = docxProvider.Import(stream);
    }
 
    return document;
}
 
private string GetHtmlFromDocument(RadFlowDocument document)
{
    var myHtmlContent = "";
    using (MemoryStream ms = new MemoryStream())
    {
        HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
        myHtmlContent = htmlProvider.Export(document);
    }
 
    return myHtmlContent;
}
 
private void SaveDocx(RadFlowDocument document)
{
    using (Stream output = System.IO.File.OpenWrite(String.Format(@"c:\Temp\TelerikMvcApp1\TelerikMvcApp1\Fiche{0}.docx", DateTime.Now.Ticks)))
    {
        DocxFormatProvider docxProvider = new DocxFormatProvider();
        docxProvider.Export(document, output);
    }
}

 

thanks

Pierre Yves
Top achievements
Rank 1
 answered on 19 Jul 2016
1 answer
362 views

Hi,

I am creating an pdf document from an html, which contains a number of images. I notice a difference between the pdf created and when viewing the html in a browser. For example the html contains css to resize the images, however it appears this does not happen during the pdf conversion process, so the images look too big.

Thanks

I use the code below to create the pdf

try {     using (var inputHtml = new MemoryStream(htmlEncoding.GetBytes(sourceString)))     {         var htmlProvider = new HtmlFormatProvider();         var document = htmlProvider.Import(inputHtml);         var editor = new RadFlowDocumentEditor(document);         using (Stream output = new FileStream(targetFolder + targetFilename, FileMode.OpenOrCreate))         {             var pdfProvider = new PdfFormatProvider();             pdfProvider.Export(document, output);         }     } }

Tanya
Telerik team
 answered on 07 Jul 2016
1 answer
259 views
I am currently converting a byte array of a spreadsheet which is stored in a database into a workbook from the XlsxFormatProvider, after doing this I am then converting this workbook into a PDF for export which all works fine. My issue is that during the conversion the formulas used to calculate values is being shown rather then the actual result.
Petya
Telerik team
 answered on 16 Jun 2016
5 answers
533 views

Hi,

please help me.

This is my problem:

I compress some files with this code

Try
            Using st As Stream = File.OpenWrite(FileZippato)
                Using zipArchive As ZipArchive = New ZipArchive(st, ZipArchiveMode.Create, False, Nothing)
                    For Each f As String In FileOrigine
                        Extensions.ZipFile.CreateEntryFromFile(zipArchive, f, Path.GetFileName(f))
                    Next
                End Using
            End Using

        Catch ex As Exception
            Globale.Log.BoxErrore(ex)
        End Try

so everything is right

when I unzip the file with

            Extensions.ZipFile.ExtractToDirectory(FileOrigine, CartellaDestinazione)

catch this exception "folder access denied".

of course access to this folder is totally free
Nikolay Demirev
Telerik team
 answered on 16 Jun 2016
1 answer
259 views

Hello,

I am currently moving from exporting a RadGridView from ExcelML to SpreadProcessing.  Everything exports fine and I am able to set most of the options I need that relate to printing except one option.

In excel, there is an option for "Scale To Fit".  I'd like this to be set to 1 page automatically on export so all columns fit on one page regardless of how many there are.  I know there is a ScaleFactor on the WorksheetPageSetup but would like it to be more dynamic.

Thanks,

Chris

Tanya
Telerik team
 answered on 14 Jun 2016
1 answer
455 views
Excel has the scaling option "Fit All Columns on One Page". Is there an equivalent setting in the Telerik printing options? I haven't been able to find any examples in the documentation or forums. Thanks for any help you can offer.
Tanya
Telerik team
 answered on 06 Jun 2016
6 answers
211 views

Hi,

I have stripped our use down to be a very simple data-dump.

Row 1 = column headers
Rows 2 to N = data

I am using the auto filtering feature  

sheet.Filter.FilterRange = sheet.UsedCellRange;

once all the data has been written

File is being saved

IWorkbookFormatProvider XSLXwriter = new XlsxFormatProvider();

using (FileStream filestream = new FileStream(filename, FileMode.Create))
    XSLXwriter.Export(output, filestream);

Output is a Workbook and filename is a unique string.

I am simulating a user experience of wanting to us the sorting options provided within Excel however this causes a crash and the file to be recovered. Saving and re-opening fixes this problem. Comparing workbook.xml from the before(which crashes) and after(save as copy) it looks like this is missing.

<definedNames>
    <definedName name="_xlnm._FilterDatabase" localSheetId="0" hidden="1">Sheet1!$A$1:$GJ$531</definedName>
  </definedNames>
  <calcPr calcId="0"/>

If you could advise on solving this issue it would be great.

Many Thanks

Nikolay Demirev
Telerik team
 answered on 31 May 2016
1 answer
232 views

Is it possible to format some parts of the text inside a cell? Something like the formatting shown in the attached image.

Tanya
Telerik team
 answered on 13 May 2016
1 answer
440 views

I'm new to creating with PDFs and this control.  I'm trying to create a PDF that could be used to print an employee ID badge.  It looks like the whole card will need to be about 250 x 360 pixels, based on a template someone sent me that can be used to print now.

How does image quality work with this control?  Can images be added with a higher resolution than the pixels used when placing it in the PDF?

Deyan
Telerik team
 answered on 13 May 2016
1 answer
640 views

Hello,

I have a situation where a user can create some text using Kendo UI Editor that later gets inserted into a document. All goes well except if the HTML contains a list (bullet or numbered) where one or more of the list item has some kind of character formatting (bold, italic, font color,...). In the resulting document, the formatted text is placed in a new paragraph, inside the list.

The code I use to insert the HTML text into the document is:

var paragraph = section.Blocks.AddParagraph();
editor.MoveToParagraphStart(paragraph);
HtmlFormatProvider htmlProvider = new HtmlFormatProvider();
RadFlowDocument htmlDocument = htmlProvider.Import(htmlText);
 
var insertOptions = new InsertDocumentOptions
{
    ConflictingStylesResolutionMode = ConflictingStylesResolutionMode.UseTargetStyle
};
editor.InsertDocument(htmlDocument, insertOptions);

The HTML used is:

<p>Lorem ipsum dolor sit amet, <strong>consectetur</strong> adipiscing elit. Aenean viverra augue nec consectetur porta.</p>
<ul>
    <li>Sed aliquet <strong>nibh</strong> vitae ligula vestibulum.</li>
    <li>Iid ullamcorper dolor sollicitudin.</li>
</ul>
<p>Nunc volutpat dui dui, <em>eget laoreet est sollicitudin at</em>. Curabitur mi ipsum, feugiat nec tortor a, tristique elementum purus.</p>
<ol>
    <li>Duis <em>nec</em> dignissim nunc.</li>
    <li>Aenean dui arcu.</li>
    <li>Vulputate eget leo ac.</li>
</ol>
<p>Volutpat volutpat lorem. Vivamus luctus lorem et iaculis porttitor.</p>

The attached images show the text being edited and the result after being exported into a document.

 

Mihail
Telerik team
 answered on 25 Apr 2016
Narrow your results
Selected tags
Tags
+? more
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Top users last month
Simon
Top achievements
Rank 2
Iron
Iron
Bob
Top achievements
Rank 3
Iron
Iron
Veteran
Marco
Top achievements
Rank 4
Iron
Iron
Iron
Grant
Top achievements
Rank 3
Iron
Iron
Iron
Kao Hung
Top achievements
Rank 1
Iron
Want to show your ninja superpower to fellow developers?
Want to show your ninja superpower to fellow developers?