Create a pdf in landscape/horizontal view

5 posts, 1 answers
  1. Phil
    Phil avatar
    2 posts
    Member since:
    Oct 2014

    Posted 04 Feb 2015 Link to this post

    Hello all, i was wondering if anybody could help me figure out how to take the current week view in the scheduler and create a pdf that's in a landscape/horizontal view of it?

    Thanks all,

    Phil
  2. Answer
    Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 06 Feb 2015 Link to this post

    Hi Phil,

    Thank you for writing.

    You can achieve this task by creating an image out of the current week view and then with the help of our RadPdfProcessing framework export the image to a pdf document. Please see my example below:
    private void createPdfButton_Click(object sender, EventArgs e)
    {
        this.radScheduler1.ActiveViewType = SchedulerViewType.Week;
        SchedulerWeekView weekView = this.radScheduler1.GetWeekView();
        weekView.StartDate = DateTime.Now;
     
        Application.DoEvents();
        Bitmap bitmap = new Bitmap(this.radScheduler1.Width, this.radScheduler1.Height);
        weekView.Scheduler.DrawToBitmap(bitmap, new Rectangle(0, 0, weekView.Scheduler.Width, weekView.Scheduler.Height));
        bitmap.Save(@"..\..\current-week.png", ImageFormat.Png);
     
        Telerik.Windows.Documents.Fixed.Model.RadFixedDocument document = new Telerik.Windows.Documents.Fixed.Model.RadFixedDocument();
        Telerik.Windows.Documents.Fixed.Model.RadFixedPage page = new Telerik.Windows.Documents.Fixed.Model.RadFixedPage();
        document.Pages.Add(page);
     
        Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource imageSource;
        using (FileStream source = File.Open(@"..\..\current-week.png", FileMode.Open))
        {
            imageSource = new Telerik.Windows.Documents.Fixed.Model.Resources.ImageSource(source);
        }
        Telerik.Windows.Documents.Fixed.Model.Objects.Image imageWithSource = page.Content.AddImage(imageSource);
        System.Windows.Size pageSize = new System.Windows.Size(imageSource.Width, imageSource.Height);
        page.Size = pageSize;
     
        Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider provider = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.PdfFormatProvider();
        Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExportSettings settings = new Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.PdfExportSettings();
        settings.ImageQuality = Telerik.Windows.Documents.Fixed.FormatProviders.Pdf.Export.ImageQuality.High;
        provider.ExportSettings = settings;
        using (FileStream output = new FileStream(@"..\..\current-week.pdf", FileMode.Create))
        {
            provider.Export(document, output);
        }
    }

    I am sending you attached the exported file using the code above.

    I hope this information is useful. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Phil
    Phil avatar
    2 posts
    Member since:
    Oct 2014

    Posted 06 Feb 2015 in reply to Hristo Merdjanov Link to this post

    Thanks Hristo, that worked out great!

    Phill
  5. Art
    Art avatar
    54 posts
    Member since:
    Dec 2010

    Posted 17 Feb 2015 in reply to Hristo Merdjanov Link to this post

    Can you do that same thing with a SchedulerWeeklyCalendarView? And also, how do I edit the ruler, or add notes, or change the heading. In VB.Net please.
  6. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 19 Feb 2015 Link to this post

    Hi Art,

    Thank you for writing.

    If I understand you correctly you are asking if the suggested approach is valid for any of the other views. If that is the case, the answer is yes. You can find additional information for the specifics of each individual view in the articles in this section of our documentation. If that is not the case please clarify what you mean by SchedulerWeeklyCalendarView since we do not have a view nor a class with that name.

    As to your second question, the best place to perform this type of operation is in the Formatting events.
    Regarding the header cells I can recommend subscribing to the CellFormatting event, you can examine a sample implementation here. Considering the RulerPrimitive, the appropriate event is RulerTextFormatting, an example is discussed here.

    I hope this information is useful. Should you have further questions please do no hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
Back to Top
UI for WinForms is Visual Studio 2017 Ready