P.Brian.Mackey P.Brian.Mackey - 23 days ago 9
C# Question

Add and display FixedDocument to WPF form

I'm programmatically generating a

FixedDocument
to help me print.
FixedDocument.ActualWidth
is coming out as
0
. I suspect this is because I am not actually displaying the FixedDocument. How can I add and display a
FixedDocument
object?

This is a beginner question. I'm not skilled with WPF. I looked on MSDN/Goog. Sites make the assumption that I've already added the FixedDocument and just need to manipulate it.

I have:

private FixedDocument CreateFixedDocumentWithPages()
{
FixedDocument fixedDocument = CreateFixedDocument();
fixedDocument.DocumentPaginator.PageSize = size;

PageContent content = AddContentFromImage();
fixedDocument.Pages.Add(content);

return fixedDocument;
}


Pseudocode of what I want:
myWpfFormObject.AddChild(fixedDocument)

Answer

for show FixedDocument:

in your Wpf window, add the DocumentViewer Controle, then set the Document property.

for ActualWidth pb:

I think you should call the methods Measure & Arrange for each FixedPage.

See the code below from the exapmle in msdn:

Size sz = new Size(8.5 * 96, 11 * 96);
fixedPage.Measure(sz);
fixedPage.Arrange(new Rect(new Point(), sz));
fixedPage.UpdateLayout();

see also http://stackoverflow.com/a/1695518/1271037