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

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

1 Answer 53 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Mi
Top achievements
Rank 1
Mi asked on 03 Jul 2012, 07:38 AM
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);
 
}

1 Answer, 1 is accepted

Sort by
0
Accepted
Iva Toteva
Telerik team
answered on 04 Jul 2012, 01:21 PM
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 >>

Tags
RichTextBox
Asked by
Mi
Top achievements
Rank 1
Answers by
Iva Toteva
Telerik team
Share this question
or