PDFsharp & MigraDoc Foundation

PDFsharp - A .NET library for processing PDF & MigraDoc Foundation - Creating documents on the fly
It is currently Fri Jan 22, 2021 1:54 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: Sat Sep 23, 2017 11:14 am 

Joined: Tue Apr 26, 2016 8:24 pm
Posts: 20

I'm trying to write a XPS document in a background thread and I cannot use PageContent or FixedPage since the require STA thread. Reason is that it take quite a lot to load and it blocks the UI.
This works great, but the page size is not correct or if i have a landscape page it is still the default?! size in document viewer.
Question is. In what I must put the DrawingVisual in order to be able to change the page size/orientation without using PageContent or FixedPage?
            // XPS package definition
            var packetName = "undefined";
            var stream = new MemoryStream();
            var uri = new Uri($"pack://{packetName}.xps", UriKind.Absolute);
            var package = Package.Open(stream, FileMode.Create, FileAccess.ReadWrite);
            PackageStore.AddPackage(uri, package);
            // Creating the XPS document
            var xpsDocument = new XpsDocument(package, CompressionOption.NotCompressed, new Uri($"pack://{packetName}.xps", UriKind.Absolute).AbsoluteUri);
            // XPS document writer
            var docWriter = XpsDocument.CreateXpsDocumentWriter(xpsDocument);

            var pageCount = renderer.FormattedDocument.PageCount;
            for (int pageNumber = 1; pageNumber <= pageCount; pageNumber++) {
                DrawingVisual drawingVisual = new DrawingVisual();
                DrawingContext drawingContext = drawingVisual.RenderOpen();

                XGraphics graphics = XGraphics.FromDrawingContext(drawingContext,
                    new XSize(renderer.FormattedDocument.GetPageInfo(pageNumber).Width.Point, renderer.FormattedDocument.GetPageInfo(pageNumber).Height.Point),

                renderer.RenderPage(graphics, pageNumber, PageRenderOptions.All);


                var container = new ContainerVisual();


            foreach (var item in list) {

            DocumentViewer = xpsDoc.GetFixedDocumentSequence();

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