J
Joy123456
Guest
/// <summary>
/// Create fixed document to add header and footer for printing
/// </summary>
/// <param name="toPrint">Orginal object to print</param>
/// <param name="capabilities">Printer capabilities</param>
/// <param name="pageSize">Page Size</param>
/// <param name="fixedDoc">Fixed document object</param>
/// <param name="canvas">Visual object for printing</param>
private void CreateFixedDocument(FrameworkElement toPrint, PrintCapabilities capabilities, Size pageSize, FixedDocument fixedDoc, Canvas canvas)
{
double scaleX = 1;
double scaleY = 1;
double textScale = Math.Round(pageSize.Width / PRINT_HEADERTEXT_SCALEFACTOR, 1);
TextBlock textHeader = new TextBlock();
textHeader.Text = mMimicName;
double length = Math.Ceiling(textHeader.Text.Length / textScale);
if (canvas.Width > capabilities.PageImageableArea.ExtentWidth)
{
scaleX = capabilities.PageImageableArea.ExtentWidth / canvas.Width;
}
if (canvas.Height > capabilities.PageImageableArea.ExtentHeight - PRINT_HEIGHT_SCALEFACTOR * length)
{
scaleY = ((capabilities.PageImageableArea.ExtentHeight - PRINT_HEIGHT_SCALEFACTOR * length) / canvas.Height);
}
canvas.LayoutTransform = new ScaleTransform(scaleX, scaleY);
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
canvas.Measure(sz);
canvas.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
PageContent pageContent = new PageContent();
FixedPage page = new FixedPage();
page.Width = pageSize.Width;
page.Height = pageSize.Height;
page.Margin = new Thickness(3);
canvas.Margin = new Thickness(0, 14 * length, 0, 0);
page.Children.Add(canvas);
textHeader.FontSize = 10;
textHeader.FontWeight = FontWeights.UltraBold;
textHeader.TextWrapping = TextWrapping.Wrap;
textHeader.FontFamily = new FontFamily("Microsoft Sans Serif");
textHeader.Margin = new Thickness(0);
StackPanel stackPanel = new StackPanel();
stackPanel.Width = page.Width - 15;
stackPanel.Orientation = System.Windows.Controls.Orientation.Vertical;
stackPanel.Children.Add(textHeader);
page.Children.Add(stackPanel);
DateTime dt = Pynf_ApplicationFramework.LocalStationUtcDateTime;
TextBlock textFooter = new TextBlock();
textFooter.Text = Pynf_ApplicationFramework.ConvertDateToString(dt);
textFooter.FontSize = 10;
FixedPage.SetTop(textFooter, page.Height - 18);
page.Children.Add(textFooter);
pageContent.Child = page;
fixedDoc.Pages.Add(pageContent);
}
In the above code I was able to view correctly on PDF viewer.
But on real time printer it is shifting up-left.Some components set at a position (0,0) is not visible.
The difference I found between real time printer and saving to PDF viewer is
For real time printer it has a
capabilities.PageImageableArea.OriginWidth = 15.915 and
canvas, capabilities.PageImageableArea.OriginHeight = 11.286
but while saving to PFF it is 0,0
Thanks in advance!..
Continue reading...
/// Create fixed document to add header and footer for printing
/// </summary>
/// <param name="toPrint">Orginal object to print</param>
/// <param name="capabilities">Printer capabilities</param>
/// <param name="pageSize">Page Size</param>
/// <param name="fixedDoc">Fixed document object</param>
/// <param name="canvas">Visual object for printing</param>
private void CreateFixedDocument(FrameworkElement toPrint, PrintCapabilities capabilities, Size pageSize, FixedDocument fixedDoc, Canvas canvas)
{
double scaleX = 1;
double scaleY = 1;
double textScale = Math.Round(pageSize.Width / PRINT_HEADERTEXT_SCALEFACTOR, 1);
TextBlock textHeader = new TextBlock();
textHeader.Text = mMimicName;
double length = Math.Ceiling(textHeader.Text.Length / textScale);
if (canvas.Width > capabilities.PageImageableArea.ExtentWidth)
{
scaleX = capabilities.PageImageableArea.ExtentWidth / canvas.Width;
}
if (canvas.Height > capabilities.PageImageableArea.ExtentHeight - PRINT_HEIGHT_SCALEFACTOR * length)
{
scaleY = ((capabilities.PageImageableArea.ExtentHeight - PRINT_HEIGHT_SCALEFACTOR * length) / canvas.Height);
}
canvas.LayoutTransform = new ScaleTransform(scaleX, scaleY);
Size sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
canvas.Measure(sz);
canvas.Arrange(new Rect(new Point(capabilities.PageImageableArea.OriginWidth, capabilities.PageImageableArea.OriginHeight), sz));
PageContent pageContent = new PageContent();
FixedPage page = new FixedPage();
page.Width = pageSize.Width;
page.Height = pageSize.Height;
page.Margin = new Thickness(3);
canvas.Margin = new Thickness(0, 14 * length, 0, 0);
page.Children.Add(canvas);
textHeader.FontSize = 10;
textHeader.FontWeight = FontWeights.UltraBold;
textHeader.TextWrapping = TextWrapping.Wrap;
textHeader.FontFamily = new FontFamily("Microsoft Sans Serif");
textHeader.Margin = new Thickness(0);
StackPanel stackPanel = new StackPanel();
stackPanel.Width = page.Width - 15;
stackPanel.Orientation = System.Windows.Controls.Orientation.Vertical;
stackPanel.Children.Add(textHeader);
page.Children.Add(stackPanel);
DateTime dt = Pynf_ApplicationFramework.LocalStationUtcDateTime;
TextBlock textFooter = new TextBlock();
textFooter.Text = Pynf_ApplicationFramework.ConvertDateToString(dt);
textFooter.FontSize = 10;
FixedPage.SetTop(textFooter, page.Height - 18);
page.Children.Add(textFooter);
pageContent.Child = page;
fixedDoc.Pages.Add(pageContent);
}
In the above code I was able to view correctly on PDF viewer.
But on real time printer it is shifting up-left.Some components set at a position (0,0) is not visible.
The difference I found between real time printer and saving to PDF viewer is
For real time printer it has a
capabilities.PageImageableArea.OriginWidth = 15.915 and
canvas, capabilities.PageImageableArea.OriginHeight = 11.286
but while saving to PFF it is 0,0
Thanks in advance!..
Continue reading...