FloatingBlockVerticalPosition.RelativeFrom Problem when exporting to PDF and set to VerticalRelativeFrom.Page

2 posts, 1 answers
  1. Mi
    Mi avatar
    16 posts
    Member since:
    Apr 2011

    Posted 03 Jul 2012 Link to this post

    Hi!

    I'm not sure if it is bug, or I'm doing something wrong.

    I have a RadDocument-object. When I try to add a picture in the back und export it to a PDF the property RelativeFrom of VerticalPosition doesn't work as expected when it is set to VerticalRelativeFrom.Page. 


    
    
    private void Pic2PDF()
    {
        var doc = new Telerik.Windows.Documents.Model.RadDocument();
        var stream = new FileStream("C:\\temp\\test.pdf", FileMode.Create);
        var pdfExp = new Telerik.Windows.Documents.FormatProviders.Pdf.PdfFormatProvider();
        var pic = new FileStream("C:\\temp\\picture.jpg", FileMode.Open);
     
        var image = new Telerik.Windows.Documents.Model.FloatingImageBlock(pic, new Size(150, 150), "jpg");
        image.AllowOverlap = true;
        image.WrappingStyle = Telerik.Windows.Documents.Model.WrappingStyle.BehindText;
        image.HorizontalPosition = new Telerik.Windows.Documents.Model.FloatingBlockHorizontalPosition(Telerik.Windows.Documents.Model.FloatingBlocks.HorizontalRelativeFrom.Page, 250);
        image.VerticalPosition = new Telerik.Windows.Documents.Model.FloatingBlockVerticalPosition(Telerik.Windows.Documents.Model.FloatingBlocks.VerticalRelativeFrom.Page, 250);
        // if I uncomment the next line it works
        //image.VerticalPosition.RelativeFrom = Telerik.Windows.Documents.Model.FloatingBlocks.VerticalRelativeFrom.Paragraph;
     
        doc.InsertInline(image);
     
        pdfExp.Export(doc, stream);
     
    }
  2. Answer
    Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 04 Jul 2012 Link to this post

    Hi Mike,

    The problem is that the default layout mode of RadDocument is Flow. In flow layout mode, there are no pages, that is why this option does not work.

    What you can do in order to make it work is to set the layout mode of the document to Paged before the export:

    var doc = new Telerik.Windows.Documents.Model.RadDocument();

    doc.LayoutMode = DocumentLayoutMode.Paged;

    var stream = new FileStream("C:\\temp\\test.pdf", FileMode.Create);
    var pdfExp = new Telerik.Windows.Documents.FormatProviders.Pdf.PdfFormatProvider();
    var pic = new FileStream("C:\\temp\\picture.jpg", FileMode.Open);
     
    var image = new Telerik.Windows.Documents.Model.FloatingImageBlock(pic, new Size(150, 150), "jpg");
    image.AllowOverlap = true;
    image.WrappingStyle = Telerik.Windows.Documents.Model.WrappingStyle.BehindText;
    image.HorizontalPosition = new Telerik.Windows.Documents.Model.FloatingBlockHorizontalPosition(Telerik.Windows.Documents.Model.FloatingBlocks.HorizontalRelativeFrom.Page, 250);
    image.VerticalPosition = new Telerik.Windows.Documents.Model.FloatingBlockVerticalPosition(Telerik.Windows.Documents.Model.FloatingBlocks.VerticalRelativeFrom.Page, 250);
     
    doc.EnsureDocumentMeasuredAndArranged();
    doc.InsertInline(image);
     
    pdfExp.Export(doc, stream);

    I hope this helps.

    Regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top