PDF formating when export

9 posts, 1 answers
  1. Georgi
    Georgi avatar
    6 posts
    Member since:
    Nov 2008

    Posted 28 Aug 2015 Link to this post

    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.

  2. Georgi
    Georgi avatar
    6 posts
    Member since:
    Nov 2008

    Posted 31 Aug 2015 in reply to Georgi Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 01 Sep 2015 Link to this post

    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
  5. Georgi
    Georgi avatar
    6 posts
    Member since:
    Nov 2008

    Posted 02 Sep 2015 Link to this post

    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.

  6. Georgi
    Georgi avatar
    6 posts
    Member since:
    Nov 2008

    Posted 04 Sep 2015 Link to this post

    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...
  7. Georgi
    Georgi avatar
    6 posts
    Member since:
    Nov 2008

    Posted 04 Sep 2015 Link to this post

    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?

  8. Answer
    Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 04 Sep 2015 Link to this post

    Hi Georgi,

    At this point 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 a LIB 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
  9. Georgi
    Georgi avatar
    6 posts
    Member since:
    Nov 2008

    Posted 07 Sep 2015 in reply to Tanya Link to this post

    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...
  10. Tanya
    Admin
    Tanya avatar
    405 posts

    Posted 09 Sep 2015 Link to this post

    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
Back to Top
UI for WPF is Visual Studio 2017 Ready