PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Wed Jul 24, 2019 7:04 am

All times are UTC


Forum rules


Please read this before posting on this forum: Forum Rules



Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Apr 05, 2019 6:20 am 
Offline

Joined: Fri Apr 05, 2019 6:04 am
Posts: 1
Code for the mainwindow:
Code:
public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            Render();
        }

        void Render()
        {
            double A4Width = XUnit.FromCentimeter(21).Point;
            double A4Height = XUnit.FromCentimeter(29.7).Point;

            FixedDocument fixedDocument = new FixedDocument();
            var size = new Size(A4Height, A4Width);
            fixedDocument.DocumentPaginator.PageSize = size;

            DrawingVisual dv = new DrawingVisual();
            DrawingContext dc = dv.RenderOpen();
            XGraphics gfx = XGraphics.FromDrawingContext(dc, new XSize(size.Width, size.Height), XGraphicsUnit.Point);
            // FIXME: Seems everything is off by factor 1.333 if I do not pop here (or scale by 1.0/1.33), which is exactly what is in the DefaultViewMatrix of the gfx
            //dc.Pop();
            RenderDocument(gfx, gfx.PageSize);
            dc.Close();

            // Create page content
            UIElement visual = new DrawingVisualPresenter(dv);

            FixedPage fixedPage = new FixedPage
            {
                Background = new SolidColorBrush(System.Windows.Media.Color.FromRgb(0xFE, 0xFE, 0xFE))
            };


            fixedPage.Children.Add(visual);

            PageContent pageContent = new PageContent
            {
                Child = fixedPage,
            };

            fixedDocument.Pages.Add(pageContent);
            Viewer.Document = fixedDocument;
        }

        void RenderDocument(XGraphics gfx, XSize size)
        {
            //Rectangle for presentation
            var container = gfx.BeginContainer();

            //Would solve the problem, but why is there a 1.33 factor???
            //gfx.ScaleTransform(1.0 / 1.33, 1 / 1.33);
            XRect rect = new XRect(new XPoint(), gfx.PageSize);
            rect.Inflate(-50, -50);
            gfx.DrawRectangle(XPens.Blue, rect);
        }
    }


Xaml window code:
Code:
<Window x:Class="WPF_Projekt.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF_Projekt"
        mc:Ignorable="d"
        Title="MainWindow" Height="1080" Width="1920">
    <Grid>
        <DocumentViewer Panel.ZIndex="0" Grid.Row="1" Grid.Column="0" x:Name="Viewer"/>
    </Grid>
</Window>


Ass mentioned in the commented code. There is a 1.333 factor offset on everthing, when I am not doing dc.pop(). Why is that the case?


Attachments:
File comment: This is how it should look like
wpf_offset_correct.PNG
wpf_offset_correct.PNG [ 4.76 KiB | Viewed 262 times ]
File comment: Here you can see the offset.
wpf_offset.PNG
wpf_offset.PNG [ 4.13 KiB | Viewed 262 times ]
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Privacy Policy, Data Protection Declaration, Impressum
Powered by phpBB® Forum Software © phpBB Group