This is a migrated thread and some comments may be shown as answers.

PDF formating when export

8 Answers 110 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Georgi
Top achievements
Rank 1
Georgi asked on 28 Aug 2015, 07:38 AM

Hi, I have a question about preparing a RadDocument for export to PDF. I'm creating a RadDocument object and setting its properties programmatically and when it is exported to a pdf file it doesn't have outer margins and text that is set to be aligned to center is not centered.
Exporting to Word document file is OK and when a RadDocument is created by importing the docx file and then exported to pdf the formating is consistent with the word file as expected. What propery might be not set correctly thus causing this behaviour?

Thanks.

8 Answers, 1 is accepted

Sort by
0
Georgi
Top achievements
Rank 1
answered on 31 Aug 2015, 08:17 AM

If I have to simplify the question - what might be the difference when I'm ​setting manualy a RadDocument object and when ​the one is created by DocxFormatProvider.Import method? The difference is shown when both objects are exported to pdf - the manualy created RadDocument doesn't have margins and its page is wider.

As I don't get any answers, please let me know if my question isn't clear.

0
Tanya
Telerik team
answered on 01 Sep 2015, 03:18 PM
Hi Georgi,

I tested the described scenario and could confirm that there is an issue with the PdfFormatProvider. The problem is related with the export of document with LayoutMode set to Flow (this is the default layout mode of RadDocument). I logged the issue in our backlog and you could subscribe to the related public item in order to receive notifications about status changes on it.

To work around this behavior you could set the LayoutMode property of the RadDocument to Paged:
document.LayoutMode = DocumentLayoutMode.Paged;

Hope this helps.

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Georgi
Top achievements
Rank 1
answered on 02 Sep 2015, 06:54 AM

Hi Tanya,
I also tried setting LayoutMode of the RadDocument to Paged but the ​behaviour of the export provider didn't change.

Here is my code:
byte[] buffer = null;
string extension = fileName.Substring(fileName.LastIndexOf(".") + 1);
IDocumentFormatProvider formatProviderByExtension = DocumentFormatProvidersManager.GetProviderByExtension(extension);
radDocument.LayoutMode = DocumentLayoutMode.Paged;             
buffer = formatProviderByExtension.Export(radDocument);​
using (FileStream stream = File.Create(fileName)) {
   stream.Write(buffer, 0, buffer.Length);
   stream.Flush();
}

"fileName" ​is a parameter and when it is with docx extension that code creates well formated word document.

0
Georgi
Top achievements
Rank 1
answered on 04 Sep 2015, 06:17 AM
The workaround which I'm using for now is before exporting the created RadDocument to pdf, export it to xml and then import it back from the xml. Then the created pdf is formatted as expected...
0
Georgi
Top achievements
Rank 1
answered on 04 Sep 2015, 06:28 AM

Additionaly, after exporting a RadDocument to pdf and opening the file in Adobe Reader, on closing the file Reder asks to save the changes. That happens with every pdf file created through Telerik's tools (using directly the export provider, using the example of Telerik Editor, etc.). Might be that the Adobe Reader makes some changes (fixes) in the document's formatting..

Are you aware of that behaviour and can you advise how to avoid it?

0
Accepted
Tanya
Telerik team
answered on 04 Sep 2015, 03:11 PM
Hi Georgi,

At this I am not able to tell what is the reason for this behavior and will need some more detailed information in order to check what is causing it and give you a suitable solution. Could you share how the document is created and which is the version of the controls you are using? The snippet below demonstrates the approach I am using to achieve the desired visualization:
RadDocument radDocument = new RadDocument();
radDocument.LayoutMode = DocumentLayoutMode.Paged;

RadDocumentEditor editor = new RadDocumentEditor(radDocument);
editor.Insert(content);
editor.ChangeParagraphTextAlignment(RadTextAlignment.Center);        
editor.ChangeSectionActualPageMargin(new Padding(100));
              
byte[] buffer = null;
string extension = fileName.Substring(fileName.LastIndexOf(".") + 1);
IDocumentFormatProvider formatProviderByExtension = DocumentFormatProvidersManager.GetProviderByExtension(extension);
buffer = formatProviderByExtension.Export(radDocument);
  
using (FileStream stream = File.Create(fileName))
{
    stream.Write(buffer, 0, buffer.Length);
    stream.Flush();
}

The issue with Adobe Reader was present in earlier versions and has been fixed with after the Q3 2014 release. The first official release it was included in is Q1 2015. 

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Georgi
Top achievements
Rank 1
answered on 07 Sep 2015, 07:36 AM

Hi, now with your snipped the export works as expected. The difference was that I was using direct export from RadDocument without setting an editor, or using RadRichTextbox to assign its Document to the created RadDocument and then call Export(RadRichTextbox.Document). Just using the following code did the trick:

RadDocumentEditor editor = new RadDocumentEditor(radDocument);

byte[] buffer = formatProviderByExtension.Export(​editor.Document);​

The version of the libraries which I'm using is 2014.3.1021.40, so probably the fix for the issue with Adobe Reader wasn't included yet...
0
Tanya
Telerik team
answered on 09 Sep 2015, 04:31 PM
Hi Georgi,

It is strongly recommended to use the RadDocumentEditor class to modify a RadDocument. The editor provides a better API and internally performs updates, which are important for the visualization of the document.

You are right, the fix is included later - in the LIB with version 2014.3.1222.

Regards,
Tanya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Georgi
Top achievements
Rank 1
Answers by
Georgi
Top achievements
Rank 1
Tanya
Telerik team
Share this question
or