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

Print to XPS/PDF

14 Answers 387 Views
ScheduleView
This is a migrated thread and some comments may be shown as answers.
Benoît
Top achievements
Rank 1
Benoît asked on 05 Jan 2016, 11:06 AM

Hello !

First of all, let me wish you a happy new year !

Let's get straight to the point, I can't print my ScheduleView (SV). On my screen, I can see about 50% (or less) of the entire SV. The goal for me is to print the entire SV on as many pages needed without quality loss.

I used this project to start : http://www.telerik.com/forums/print-bb34c69c1e37#1454069 but I can't adapt it to my needs. The result I obtain with that method is only the visible part of my SV (and it doesn't even fit the whole page).

I also tried the method below but the xps I get is blank. There's only the textblock "Toto".

 

LayoutRoot.Children.Remove(MainSV); // LayoutRoot is the main grid of our view
 
StackPanel sp = new StackPanel();
sp.Children.Add(new TextBlock { Text = "Toto" });
sp.Children.Add(MainSV);
 
FixedPage fp = new FixedPage();
fp.Children.Add(sp);
 
string path = @"C:\test\pla_" + Guid.NewGuid() + ".xps";
XPSPrinter.CreateXps(path, new List<FixedPage> { fp });

I can provide more snippet, just ask me what you need to see.

Thanks for your help.

 

Regards.

Ben


 

14 Answers, 1 is accepted

Sort by
0
Nasko
Telerik team
answered on 07 Jan 2016, 04:18 PM
Hello BenoƮt,

What we can suggest you is to check the Export Support article from our help documentation on the following link:
http://docs.telerik.com/devtools/wpf/common-export-support.html

Using the Export through RadDocument approach will allow to achieve the desired (export RadScheduleView into a PDF file). Please, check the attached sample that demonstrates that and let us know if it worked for you.

Hope this helps.

Regards,
Nasko
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
Benoît
Top achievements
Rank 1
answered on 12 Jan 2016, 10:46 AM

Hello Nasko,

I tried to use your solution, but I don't have access to the "Telerik.Windows.Documents.Model" namespace. I searched through the whole Telerik folder and I couldn't find this dll. I even managed to update the Telerik UI for WPF solution to the last version but nothing changed. Is it hidden somewhere ?

 

Thanks for your help.

Regards.
Ben

0
Nasko
Telerik team
answered on 12 Jan 2016, 12:36 PM
Hi Ben,

The Telerik.Windows.Documents.Model namespace is part of the Telerik.Windows.Documents binary - please, check if you have added it.

Meanwhile, I am sending you again the project with trial binaries included, so you could be able to check it.

We hope this help help you.

Regards,
Nasko
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
Benoît
Top achievements
Rank 1
answered on 12 Jan 2016, 01:09 PM

Thanks Nasko, that namespace was in the Telerik.Windows.Documents dll. I just didn't knew it (but I'm sure if I searched a little bit more in documentation, I'd have find it).

However, your solution doesn't fit my needs. It's working fine, but I still can't get my entire SV in a document. I only have the part of the SV that is visible on screen (around 50% of the entire SV in my case).

Do you have a solution?

 

Thanks for your help.
Regards.

Ben

0
Nasko
Telerik team
answered on 12 Jan 2016, 01:39 PM
Hello Ben,

The proposed approach depends on the SectionDefaultPageSize set for the RadDocument and the panel where the control is placed in- the ScheduleView should be displayed in that entire size that is set nevertheless of the fact how much of the control is currently visible.

Please, check the attached video that demonstrates how that approach works on our side - RadScheduleView gets displayed as expected. Are we missing something?

Could you please send us a video with the observed on your side behavior?

We are looking forward to hearing from you.

Regards,
Nasko
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
Benoît
Top achievements
Rank 1
answered on 12 Jan 2016, 02:14 PM

I can't watch your video. To me it's 45 seconds of a screenshot displaying a part of your code. I used VLC Media Player and Groove Video to watch it but it's the same result.

Still, I can't make a video for you due to data confidentiality issues. But I can take screenshots and a code snippet. The files attached here will show you what I have (ss_ori) and what I get after the print process (ss_out, this file is actually a screenshot of the pdf obtained). Here is my code (a lot is taken from yours) :

01.private void Print()
02.{
03.    string path = @"C:\test\pla_" + Guid.NewGuid() + ".pdf";
04.    RadDocument document = this.CreateDocument();
05.    document.LayoutMode = DocumentLayoutMode.Flow;
06.    document.Measure(RadDocument.MAX_DOCUMENT_SIZE);
07.    document.Arrange(new RectangleF(PointF.Empty, document.DesiredSize));
08.    document.SectionDefaultPageSize = new Size(1500, 2300);
09.    PdfFormatProvider provider = new PdfFormatProvider();
10. 
11.    using (Stream output = System.IO.File.Create(path))
12.    {
13.        provider.Export(document, output);
14.    }
15.}
16. 
17.private RadDocument CreateDocument()
18.{
19.    Telerik.Windows.Documents.Model.Section section = new Telerik.Windows.Documents.Model.Section();
20.    Telerik.Windows.Documents.Model.Paragraph paragraph = new Telerik.Windows.Documents.Model.Paragraph();
21.    BitmapImage bi = new BitmapImage();
22. 
23.    Telerik.Windows.Documents.Model.ImageInline image = null;
24. 
25.    using (MemoryStream ms = new MemoryStream())
26.    {
27.        ExportExtensions.ExportToImage(this.MainSchedule, ms, new PngBitmapEncoder());
28.        bi.BeginInit();
29.        bi.StreamSource = ms;
30. 
31.        bi.EndInit();
32.        image = new Telerik.Windows.Documents.Model.ImageInline(new WriteableBitmap(bi));
33.    }
34. 
35.    paragraph.Inlines.Add(image);
36.    section.Blocks.Add(paragraph);
37. 
38.    RadDocument document = new RadDocument();
39.    document.Sections.Add(section);
40. 
41.    return document;
42.}

Thanks for your help.

Regards.

Ben

0
Benoît
Top achievements
Rank 1
answered on 12 Jan 2016, 02:40 PM

With my designer co-worker, we managed to get a workaround. It seems that it's the main grid that causes problem. When we put the SV in a StackPanel only (and no grid around), the print process works just fine. But we can't break the whole page layout just for printing...

So we tried to create another UserControl, pass the SV in parameter and when the Loaded event is fired, we launch the print process and it works, but it's really dirty...

Do you have another solution ?

 

Thanks for your help.

Regards.

Ben

0
Benoît
Top achievements
Rank 1
answered on 14 Jan 2016, 12:30 PM

Sorry to insist, but are there any other solution ?

[quote]With my designer co-worker, we managed to get a workaround. It seems that it's the main grid that causes problem. When we put the SV in a StackPanel only (and no grid around), the print process works just fine. But we can't break the whole page layout just for printing...
So we tried to create another UserControl, pass the SV in parameter and when the Loaded event is fired, we launch the print process and it works, but it's really dirty...[/quote]

 

Thanks for your help.

Regards.

Ben

0
Nasko
Telerik team
answered on 14 Jan 2016, 03:31 PM
Hello Ben,

Could you please provide us a code - snippet of the exact layout (the xaml declaration) of the control inside the Grid. Most probably the Grid has some set sizes that causes the ScheduleView not being printed as expected.

We are looking forward to hearing from you.

Regards,
Nasko
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
Benoît
Top achievements
Rank 1
answered on 14 Jan 2016, 04:29 PM

Hello Nasko,

Given the fact that our XAML is pretty huge, I erased some useless stuff for you.

<Grid x:Name="LayoutRoot" Margin="0,20,0,0" >
    <Grid.RowDefinitions>
        <RowDefinition Height="150" />
        <RowDefinition Height="*" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="256" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <!-- region ScheduleView -->
  <telerik:RadScheduleView x:Name="MainSchedule" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="2"
 CategoriesSource="{Binding PlanningHelper.Categories}" telerik:StyleManager.Theme="Windows8"
 NavigationHeaderVisibility="Collapsed"
 AppointmentsSource="{Binding PlanningHelper.Appointments}"
 ResourceTypesSource="{Binding PlanningHelper.ResourceTypes}"
 CurrentDate="{Binding ElementName=TimeBar, Path=SelectionStart}"
 MouseOverHighlightStyle="{StaticResource MouseOverHighlightStyle}"
 SpecialSlotsSource="{Binding PlanningHelper.SpecialSlots}"
 EditAppointmentDialogStyle="{x:Null}"
 TimeRulerItemTemplateSelector="{StaticResource CustomTimeRulerItemTemplateSelector}"
 ShowDialog="MainSchedule_OnShowDialog" MouseDoubleClick="Export"/>
</Grid>

Hope this helps.

Thanks.
Regards.

Ben

0
Nasko
Telerik team
answered on 15 Jan 2016, 09:36 AM
Hello Ben,

Thank you for the provided code snippet. As already stated in my previous response the observed behavior is caused by the Grid panel and more specifically by the row inside which the ScheduleView is placed. That row has a height set to "*". When a row has such set height the size of the controls becomes proportional to the one of the grid and because of that when you print it it gets printed only the visible part because this is the current size of ScheduleView (proportional to the grid). If you set the height of the row to "Auto" it should be exported as expected because when the value is auto the row is given as much as height as the ScheduleView requires - thus it is exported as expected.

Please, check the sample that demonstrates that - notice how the ScheduleView gets printed when the height of the row is set to Auto.

We hope the provided information will be helpful for you.

Regards,
Nasko
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
Benoît
Top achievements
Rank 1
answered on 15 Jan 2016, 12:37 PM

Hello Nasko,

Thanks for this, it's working for me now. I didn't get the info of your previous post about the panel... I thought of something else.

However, with the Auto on my gridrow, I lost my scroll, and it's really important for users... I can only get it back when I switch to "*" again.

Have you an idea to fix that ?

Thanks.

Regards
Ben

0
Benoît
Top achievements
Rank 1
answered on 15 Jan 2016, 01:47 PM

I managed to fix the scroll problem. In fact, I leave my XAML unchanged, meaning that I leave the "*" in the grid row, but when I launch the print process I do this :

 

LayoutRoot.RowDefinitions[1].Height = GridLength.Auto;
LayoutRoot.UpdateLayout();
 
// print process here
 
this.LayoutRoot.RowDefinitions[1].Height = new GridLength(1, GridUnitType.Star);

And it's working as I wanted. The user sees nothing, it's fully transparent for him.

Thanks Nasko for your help !

Regards
Ben

0
Nasko
Telerik team
answered on 15 Jan 2016, 02:20 PM
Hi Ben,

I am really glad that you managed to find an approach that suits your requirements and now everything works as expected.

If you have any additional questions or concerns regarding Telerik controls, please do not hesitate to contact us.

Regards,
Nasko
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
ScheduleView
Asked by
Benoît
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Benoît
Top achievements
Rank 1
Share this question
or