Print to XPS/PDF

15 posts, 0 answers
  1. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 05 Jan Link to this post

    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


     
  2. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 07 Jan Link to this post

    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
  3. UI for WPF is Visual Studio 2017 Ready
  4. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 12 Jan in reply to Nasko Link to this post

    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

  5. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 12 Jan Link to this post

    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
  6. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 12 Jan in reply to Nasko Link to this post

    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

  7. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 12 Jan Link to this post

    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
  8. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 12 Jan in reply to Nasko Link to this post

    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

  9. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 12 Jan Link to this post

    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

  10. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 14 Jan Link to this post

    Sorry to insist, but are there any other solution ?

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

     

    Thanks for your help.

    Regards.

    Ben

  11. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 14 Jan Link to this post

    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
  12. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 14 Jan in reply to Nasko Link to this post

    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

  13. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 15 Jan Link to this post

    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
  14. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 15 Jan in reply to Nasko Link to this post

    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

  15. Benoît
    Benoît avatar
    9 posts
    Member since:
    Jan 2016

    Posted 15 Jan Link to this post

    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

  16. Nasko
    Admin
    Nasko avatar
    587 posts

    Posted 15 Jan Link to this post

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