开发者

Printing in WPF

I've created some windows in wpf that I need to print to one xps document. Each window opens, loads the relevant data and then immediately closes. Currently I use the below code to create the xps:

    Using doc = New XpsDocument(TempLoc, FileAccess.Write)
        Dim writer = XpsDocument.CreateXpsDocumentWriter(doc)
        Dim collator = writer.CreateVisualsCollator()

        Dim Window1 As Window1 = New Window1()
        Window1.ShowDialog()
        Dim Window2 As Window2 = New Window2()
        Window2.ShowDialog()
        Dim WindowX As WindowX = New WindowX()
        WindowX.ShowDialog()

        collator.BeginBatchWrite()
        collator.Write(Window1)
        collator.Write(Window2)
        collator.Write(WindowX)

        collator.EndBatchWrite()
    End Using

    Dim doc2 = New XpsDocument(TempLoc, FileAccess.Read)

    Dim seq = doc2.GetFixedDocumentSequence()

    Dim window = New Window()
    window.Content开发者_Python百科 = New DocumentViewer() With {.Document = seq}
    window.ShowDialog()

    doc2.Close()

However the trouble with this approach is that the area printed varies between machines - I assume this is due to the local screen size being used etc.

Is it possible to make the program print the full window independent of the computer its on by modifying this code? Alternativly is there a better way to approach this problem?

Thanks for any help


I print with FixedDocuments by either appending or adding placed UIElements. I posted the full source code to my helper class here. You may find that breaking it down by UIElements gives you much better control over your exact printed output, though yes, it requires you to separate printing code instead of just emitting your window.

I've used this helper class to create some very nicely formated multi-page reports that always come out the same on every computer.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜