WPF FixedDocument Constrain to printable area.

  • Thread starter Thread starter Bryan Valencia
  • Start date Start date
B

Bryan Valencia

Guest
I am creating a label for printing in CODE, not using XAML.

System.Drawing.SizeF pageSize = new System.Drawing.SizeF(12f / 16f, 2f + 3f / 8f);
Size pixelSize = new Size(96 * pageSize.Width, 96 * pageSize.Height);

FixedDocument doc = new FixedDocument();

doc.Pages.Add(new PageContent());
doc.Pages[0].Child = new FixedPage() { Width = pixelSize.Width, Height = pixelSize.Height, Margin=new Thickness(20) };
doc.Pages[0].Child.Children.Add(new StackPanel() { Orientation = Orientation.Vertical });

doc.DocumentPaginator.PageSize = pixelSize;


StackPanel panel = (StackPanel)doc.Pages[0].Child.Children[0];
double PageWidth = pixelSize.Width;

panel.Children.Add(textblock("Normal Text", "Calibri", 7, PageWidth));
panel.Children.Add(textblock("Bold Text", "Calibri", 7, PageWidth, FontWeights.UltraBold, FontStyles.Normal));



There are SO MANY problems here, but whenever I search for answers, it sends me back to "PrintDocument", not "FixedDocument".

The label (without my totally arbitrary margin set) has an origin OUTSIDE the printer's printable area. I would think that the origin could be easily set to originate at the printable region.

When I set the margin in this way. it SUBTRACTS from my printable area. NO. I have calculated the exact size I want, and I DO NOT want the label size to vary from that.

The text and label seem MUCH TOO SMALL. In a textblock, when you say FontSize=x, what units is that? It's a double, but ???

Also, I am using 96 as a multiplier, but my printer is at 300DPI. (I think). how do I get the label size to be exactly right? I found the 96 in a WPF tutorial, but it doesn't seem right.


NONE of the Microsoft pages give units for anything. It's just "Size" or "Width", or "Thickness".

This is EXTREMELY FRUSTRATING. and to top it all off, everytime I think I am getting close to an anwer, it seems to go back to PrintDocument (which has no way of setting line heights).

so questions.

1. how do I set the document to start at the printable region?

2. how do I ensure that my text is 7 POINTS, not pixels or ANY OTHER UNIT OF MEASURE?

3. NO XAML. I am building this in code.











I'd rather live with false hope than with false despair.

Continue reading...
 
Back
Top