PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Tue Dec 07, 2021 6:16 pm

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 

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

        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
            RenderDocument(gfx, gfx.PageSize);

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

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


            PageContent pageContent = new PageContent
                Child = fixedPage,

            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:
<Window x:Class="WPF_Projekt.MainWindow"
        Title="MainWindow" Height="1080" Width="1920">
        <DocumentViewer Panel.ZIndex="0" Grid.Row="1" Grid.Column="0" x:Name="Viewer"/>

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?

File comment: This is how it should look like
wpf_offset_correct.PNG [ 4.76 KiB | Viewed 20315 times ]
File comment: Here you can see the offset.
wpf_offset.PNG [ 4.13 KiB | Viewed 20315 times ]
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 18 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