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
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.
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
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.
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?
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
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...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