Print High Resolution Image in C# - c#

I am printing image 2349 x 3600 pixels. I have resized image but printing is blurred not clean. Please looke at code -
using System.Drawing.Drawing2D;
public Bitmap resizeimage(Bitmap bitmap)
{
Bitmap result = new Bitmap(850, 1101);
using (Graphics grap = Graphics.FromImage(result))
{
grap.CompositingQuality = CompositingQuality.HighQuality;
grap.InterpolationMode = InterpolationMode.Bicubic;
grap.SmoothingMode = SmoothingMode.HighQuality;
grap.CompositingQuality = CompositingQuality.HighQuality;
grap.DrawImage(bitmap, 0, 0, 850, 1101);
}
return result;
}
I tried everything from changing bitmap size, quality of graphics but still image blurred.
I used microsoft office 2007 and resized image and printed it , it was so clear.
How I can get exact printing quality as I got in microsoft office 2007.
Please help.
Here is code before drawing -
PrintPreviewDialog printpreview = new PrintPreviewDialog();
PrintDocument printdocument = new PrintDocument();
printdocument.PrinterSettings.PrinterName = "EPSON L100 Series";
int horizantal_dpi = printdocument.PrinterSettings.DefaultPageSettings.PrinterResolution.X;
int vertical_dpi = printdocument.PrinterSettings.DefaultPageSettings.PrinterResolution.Y;
decimal final_width_dpi = (((int)printdocument.DefaultPageSettings.PrintableArea.Width * horizantal_dpi) / 100);
decimal final_height_dpi = (((int)printdocument.DefaultPageSettings.PrintableArea.Height * vertical_dpi ) / 100);
printimagaprint = new Bitmap((int)final_width_dpi, (int)final_height_dpi);
//set resoultion
printimagaprint.SetResolution(horizantal_dpi, vertical_dpi);
Graphics g = System.Drawing.Graphics.FromImage(printimagaprint);
g.DrawImage(bitmap, 0, 0, printimagaprint.Width, printimagaprint.Height);
printdocument.PrintPage +=new PrintPageEventHandler(printdocument_PrintPage);
//printdocument.Print();
printdocument.DocumentName = textBox1.Text;
printpreview.Document = printdocument;
printpreview.ShowDialog();

Try matching the printer resolution before printing.
printDialog.PrinterSettings.PrinterName = GetTargetPrinter();
int horizontal_dpi = printDialog.PrinterSettings.DefaultPageSettings.PrinterResolution.X;
int vertical_dpi = printDialog.PrinterSettings.DefaultPageSettings.PrinterResolution.Y;
Decimal final_width_dpi = (((int)printDialog.PrinterSettings.DefaultPageSettings.PrintableArea.Width * horizontal_dpi) / 100);
Decimal final_height_dpi = (((int)printDialog.PrinterSettings.DefaultPageSettings.PrintableArea.Height * vertical_dpi) / 100);
printImage = new Bitmap((int)final_width_dpi, (int)final_height_dpi);
// Set Resolution
printImage.SetResolution(horizontal_dpi, vertical_dpi);
Graphics g = System.Drawing.Graphics.FromImage(printImage);
And please try to provide more descriptive code. I am just making assumption for now.

Related

Blurry and large image barcode being generated using a plugin in Windows Form

Going through the steps mentioned here
and using IDAutomationCode39, I am getting the barcode image, however they are very blurr and only scans bigger size images. My barcode id will be upto 30 characters long, which is causing a very wide barcode image. Where could the problem lie? Is it the IDAutomationCode39 or my setting in my button click event below?
private void button1_Click(object sender, EventArgs e)
{
string abbre = GenerateProdCodeFromProductName();
txt2.Text = abbre;
string barcode = txt1.Text;
Bitmap bitm = new Bitmap(barcode.Length * 45, 160);
bitm.SetResolution(240, 240);
using (Graphics graphic = Graphics.FromImage(bitm))
{
Font newfont = new Font("IDAutomationHC39M", 6);
PointF point = new PointF(5f, 5f);
SolidBrush black = new SolidBrush(Color.Black);
SolidBrush white = new SolidBrush(Color.White);
graphic.FillRectangle(white, 0, 0, bitm.Width, bitm.Height);
graphic.DrawString("*" + barcode + "*", newfont, black, point);
}
using (MemoryStream Mmst = new MemoryStream())
{
bitm.Save("ms", ImageFormat.Jpeg);
pictureBox1.Image = bitm;
pictureBox1.Width = bitm.Width;
pictureBox1.Height = bitm.Height;
}
}
Thank you.
I don't see any PlugIn reference in your code, you are just using a Code39 ASCII font to print a Barcode on a Bitmap.
The problem I see is that the size of the resulting Bitmap is unscaled.
What I mean is, you let the size of the Barcode determine the size of the final graphic image.
It is usually the opposite. You have some defined dimensions for a Bitmap, because of layout constraints: you have to print the barcode to a label, for example.
If the generated Barcode is wider than its container, you have to normalize it (scale it to fit).
Here is what I propose. The size of the Bitmap if fixed (300, 150). When the Barcode is generated, its size is scaled to fit the Bitmap size.
The quality of the image is preserved, using an Bicubic Interpolation in case of down scaling. The resulting graphics is also Anti-Aliased.
(Anti-Alias has a good visual render. May not be the best choice for printing. It also depends on the printer.)
The generated Bitmap is then passed to a PictureBox for visualization and saved to disk as a PNG image (this format because of its loss-less compression).
Here is the result:
string Barcode = "*8457QK3P9*";
using (Bitmap bitmap = new Bitmap(300, 150))
{
bitmap.SetResolution(240, 240);
using (Graphics graphics = Graphics.FromImage(bitmap))
{
Font font = new Font("IDAutomationSHC39M", 10, FontStyle.Regular, GraphicsUnit.Point);
graphics.Clear(Color.White);
StringFormat stringformat = new StringFormat(StringFormatFlags.NoWrap);
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
graphics.TextContrast = 10;
PointF TextPosition = new PointF(10F, 10F);
SizeF TextSize = graphics.MeasureString(Barcode, font, TextPosition, stringformat);
if (TextSize.Width > bitmap.Width)
{
float ScaleFactor = (bitmap.Width - (TextPosition.X / 2)) / TextSize.Width;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.ScaleTransform(ScaleFactor, ScaleFactor);
}
graphics.DrawString(Barcode, font, new SolidBrush(Color.Black), TextPosition, StringFormat.GenericTypographic);
bitmap.Save(#"[SomePath]\[SomeName].png", ImageFormat.Png);
this.pictureBox1.Image = (Bitmap)bitmap.Clone();
font.Dispose();
}
}

Confirmation, Printing Graphic location C#

I have created the code below to help me print the admin form as a "report" like document showing the date and graph needed for documentation.
try
{
Graphics g = this.CreateGraphics();
AdminPage = new Bitmap(Size.Width, Size.Height, g);
Graphics Printed = Graphics.FromImage(AdminPage);
Printed.CopyFromScreen(519, 340, 0,0,this.Size);//519,340 this.Location.Y,this.Location.X
printPreviewAdminDialogue.ShowDialog();
}
catch(Exception )
{
MessageBox.Show("Please check printer connection!");
}
I have used the coordinate data of the screen as:
Printed.CopyFromScreen(519, 340, 0,0,this.Size);
Will this still work on any size screen or will this result in some formatting problems on other devices rather than just my laptop?
So far it looks fine Print Preview of what i want with the current code
This method takes a Control (SourceControl) reference and returns a Bitmap resulting from a screen capture of the Control's Window.
Parameters:
SourceControl: The control to be printed. It can be a TopLevel Window (a Form) or a Child Control.
Dpi: The DPI resolution of the resulting Bitmap.
ScaleToDpi: if set to true, the size of the Bitmap will be scaled to match the Dpi parameter, defining a scale factor relative to current screen resolution. E.g.: If parameter Dpi = 300 and the current screen resolution is 96 Dpi, the resulting Bitmap size will be scaled with a factor of 3.125
ClientAreaOnly: If true, captures the SourceControl client area, otherwise the full window bounds.
InterpolationMode: Defines the resulting quality of a scaled bitmap. For enlargements, Bicubic or HighQualityBicubic gives better results. Bicubic may render a shaper image. The usefulness of this parameter depends on how the image is used. The perceived visual quality may not be the same when the image is printed on paper. When printing, sharper images give a better result.
The results can be tested using a PrintPreviewControl to see the difference between a scaled and a non-scaled Bitmap.
Print the a Form including its borders with a resolution of 300 DPI but not scaled to the new resolution (modifies the resulting Bitmap resolution only):
Bitmap FullSize300Dpi = PrintControlFromScreen(this, false, 300, false, InterpolationMode.Default);
Print the a Form ClientArea with a resolution of 300 DPI and scale its dimensions to the new resolution using a HighQualityBicubic Interpolation:
Bitmap ClientArea300DpiScaled = PrintControlFromScreen(this, true, 300, true, InterpolationMode.HighQualityBicubic);
The same, but it prints the client area of a button1 control with a resolution of 96 DPI with a Bilinear Interpolation:
Bitmap Child96DpiUnscaled = PrintControlFromScreen(this.button1, true, 96, false, InterpolationMode.Bilinear);
public Bitmap PrintControlFromScreen(Control SourceControl, bool ClientAreaOnly, float Dpi, bool ScaleToDpi, InterpolationMode Interpolation)
{
using (Graphics graphics = SourceControl.CreateGraphics())
{
SizeF ScaleFactor = new SizeF((Dpi / graphics.DpiX), (Dpi / graphics.DpiY));
SizeF BitmapSize;
if (ScaleToDpi)
{
BitmapSize = ClientAreaOnly ? new SizeF((SourceControl.ClientRectangle.Size.Width * ScaleFactor.Width),
(SourceControl.ClientRectangle.Size.Height * ScaleFactor.Height))
: new SizeF((SourceControl.Bounds.Size.Width * ScaleFactor.Width),
(SourceControl.Bounds.Size.Height * ScaleFactor.Height));
}
else
{
BitmapSize = ClientAreaOnly ? SourceControl.ClientRectangle.Size : SourceControl.Bounds.Size;
}
using (Bitmap bitmap = new Bitmap((int)BitmapSize.Width, (int)BitmapSize.Height))
{
bitmap.SetResolution(ScaleFactor.Width * graphics.DpiX, ScaleFactor.Height * graphics.DpiY);
using (Graphics ImageGraph = Graphics.FromImage(bitmap))
{
ImageGraph.CompositingQuality = CompositingQuality.HighQuality;
ImageGraph.CompositingMode = CompositingMode.SourceCopy;
ImageGraph.SmoothingMode = SmoothingMode.HighQuality;
ImageGraph.PixelOffsetMode = PixelOffsetMode.HighQuality;
ImageGraph.InterpolationMode = Interpolation;
if (ClientAreaOnly)
{
ImageGraph.CopyFromScreen(SourceControl.PointToScreen(SourceControl.ClientRectangle.Location),
new Point(0, 0), SourceControl.ClientRectangle.Size);
}
else
{
if (SourceControl.TopLevelControl == SourceControl)
{
ImageGraph.CopyFromScreen(SourceControl.Bounds.Location,
new Point(0, 0), SourceControl.Bounds.Size);
}
else
{
ImageGraph.CopyFromScreen(SourceControl.PointToScreen(SourceControl.ClientRectangle.Location),
new Point(0, 0), SourceControl.Size);
}
}
if (ScaleToDpi) ImageGraph.ScaleTransform(ScaleFactor.Width, ScaleFactor.Height);
ImageGraph.DrawImage(bitmap, new Point(0, 0));
return (Bitmap)bitmap.Clone();
};
};
};
}
UPDATE1 (Example of Print Preview):
This is one possible way to show a PrintPreview of the Bitmap. It should of course be adapted to an actual Printer. This is for general use.
A Bitmap is created in a Button event handler and a PrintPreview Dialog is shown to seee the result.
This creates a ScreenShot of a PictureBox control in the current Form
(this), takes the ClientArea only, sets the resuluton to 300Dpi, does
not scale the image (keeps the screen original size), using a Bicubic
Interpolation for rendering.
Bitmap screenCapture = PrintControlFromScreen(this.pictureBox1, true, 300, false, InterpolationMode.Bicubic);
This is the Button click handler from where you can call the PrintControlFromScreen() method:
private void button1_Click(object sender, EventArgs e)
{
Bitmap screenCapture = PrintControlFromScreen(this.pictureBox1, true, 300, false, InterpolationMode.Bicubic);
PrintDocument PrintDoc = new PrintDocument();
PrintDoc.DocumentName = "ScreenShot";
PrintDoc.DefaultPageSettings.PrinterResolution = new PrinterResolution() { X = 300, Y = 300 };
PrintDoc.DefaultPageSettings.Landscape = PrintDoc.DefaultPageSettings.PaperSize.Width < screenCapture.Width;
PrintDoc.OriginAtMargins = true;
PrintDoc.PrintPage += (s, ppe) =>
{
Rectangle BitmapSize = new Rectangle(new Point(0, 0),
new Size(screenCapture.Width, screenCapture.Height));
Graphics _imagegraph = Graphics.FromImage(screenCapture);
_imagegraph.CompositingMode = CompositingMode.SourceCopy;
_imagegraph.CompositingQuality = CompositingQuality.HighQuality;
_imagegraph.SmoothingMode = SmoothingMode.HighQuality;
_imagegraph.PixelOffsetMode = PixelOffsetMode.HighQuality;
_imagegraph.InterpolationMode = InterpolationMode.HighQualityBicubic;
ImageAttributes ImageAttr = new ImageAttributes();
ImageAttr.ClearThreshold(ColorAdjustType.Bitmap);
ppe.Graphics.DrawImage(screenCapture, BitmapSize, 0F, 0F,
BitmapSize.Width, BitmapSize.Height, GraphicsUnit.Pixel, ImageAttr);
};
PrintPreviewDialog pPreviewDiag = new PrintPreviewDialog();
pPreviewDiag.Document = PrintDoc;
pPreviewDiag.AutoScaleDimensions = new SizeF(Screen.PrimaryScreen.BitsPerPixel * 1.5F,
Screen.PrimaryScreen.BitsPerPixel * 1.5F);
pPreviewDiag.AutoScaleMode = AutoScaleMode.Dpi;
pPreviewDiag.StartPosition = FormStartPosition.CenterScreen;
pPreviewDiag.ShowDialog();
}

Print Text with DrawString() next to an existing bitmap

Greetings fellow users,
A virgin post on my end since its the first time i am abusing stack overflow with a question! I have been trying to get a bitmap print along with a String to print. Basically the view i want to achieve is the Image and the text to the right of the image as we see the printout. Below is the code I am using
Bitmap qrCodeImage = qrCode.GetGraphic(20);
senderQR = qrCodeImage;
PrintDocument pd = new PrintDocument();
Margins margins = new Margins(10, 10, 10, 10);
pd.DefaultPageSettings.Margins = margins;
pd.PrintPage += PrintPage;
pd.Print();
Here is the PrintPage method
private void PrintPage(object sender, PrintPageEventArgs e)
{
System.Drawing.Image img = senderQR;
Bitmap batchCode = new Bitmap(80, 700);
Rectangle m = e.MarginBounds;
RectangleF batch1 = new RectangleF(80, 700, 650, 1000);
m.Width = img.Width / 5;
m.Height = img.Height / 5;
Graphics g = Graphics.FromImage(batchCode);
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.DrawString(batch, new Font("Arial", 40), Brushes.Black, batch1);
g.Flush();
e.Graphics.DrawImage(img, m);
}
What am i doing wrong? what seems to be the issue? I have been struggling a whole lot to achieve this but no luck!
Additional Notes:
I want the text on the right to Wrap under itself and not under or on top of the existing bitmap within a size of 3,5 x 2 (inches) (label printing).
This is the printout i get with the existing code;
https://prnt.sc/h1ecb0
https://prnt.sc/h1edex
The image you're drawing on (batchCode) is 80 pixels wide and 700 high. When you write your text over it, you set the top-left point of your writing to 80,700 - exactly to the bottom-right corner of your picture. Basically, you write your text outside of the picture.
Update
I've created a small example to make it reproducible, below is a form class for a basic WinForms application:
public partial class Form1 : Form
{
private PictureBox pictureBox2;
public Form1()
{
InitializeComponent();
pictureBox2 = new PictureBox();
pictureBox2.Size = ClientSize;
pictureBox2.SizeMode = PictureBoxSizeMode.AutoSize;
this.Click += Form1_Click;
pictureBox2.Click += Form1_Click;
Controls.Add(pictureBox2);
}
private void Form1_Click(object sender, EventArgs e)
{
var batch = "hello there!";
Bitmap batchCode = new Bitmap(1000, 1000);
var batch1 = new RectangleF(150, 150, 850, 850);
using (Graphics g = Graphics.FromImage(batchCode))
{
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.AntiAlias;
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
g.PixelOffsetMode = System.Drawing.Drawing2D.PixelOffsetMode.HighQuality;
g.DrawString(batch, new Font("Arial", 40), Brushes.Black, batch1);
}
pictureBox2.Image = batchCode;
}
}

Adding text to an Image programmatically appears blurry

I'm trying to add some text to an Image programmatically and later I save it. But the end result is somewhat not convincing.
The text on the image appears quite blurry.
The snippet I use to render is as follows :
static void ModifyImage()
{
Image origImage;
if (File.Exists(path))
{
using (Stream s = new FileStream(path, FileMode.Open, FileAccess.Read))
{
origImage = Image.FromStream(s);
}
using (Image newImage = new Bitmap(path))
{
// Get the image's original width and height
int originalWidth = origImage.Width;
int originalHeight = origImage.Height;
// To preserve the aspect ratio
float ratio = Math.Min((float)originalWidth, (float)originalHeight);
Graphics graphics = Graphics.FromImage(newImage);
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit;
string strSoftwareVersion = "Version " + StrVersion;
var oVersionFont = new Font("Arial", 15f, FontStyle.Bold);
SizeF strSize = graphics.MeasureString(strSoftwareVersion, oVersionFont);
float mX = (float)((originalWidth * 0.85) - 5.0);
float mY = (float)((originalHeight * 0.85) - 5.0);
float mWidth = (float) (strSize.Width + 5.0);
float mHeight = (float)(strSize.Height + 10.0);
/*
* Alternate I tried.
*/
//GraphicsPath blackfont = new GraphicsPath();
//SolidBrush brsh = new SolidBrush(Color.White);
//blackfont.AddString("TEST APP", oVersionFont.FontFamily, (int)FontStyle.Bold, 15, new Point((int)(originalWidth * 0.85), (int)(originalHeight * 0.85)), StringFormat.GenericDefault);
//graphics.FillPath(brsh, blackfont);
/*
*Software Version String
*/
graphics.DrawString("Version " + StrVersion, new Font("Arial", 15f, FontStyle.Bold), Brushes.White, (int)(originalWidth * 0.85), (int)(originalHeight * 0.85));
/*
* Save processed image
*/
newImage.Save(newPath, ImageFormat.Jpeg);
}
origImage.Dispose();
}
}
As you can see from the image, the blurriness of the text and surrounding areas are quite prominent. I'm quite sure this is due to the Aliasing or TextRendering issue with the alpha levels, but just not able to point the exact issue.
The text looks fine to me.
To make it crispier you can turn off all antialiasing.
The 'surrounding areas' obviously show some jpeg artifacts.
Good text and jpeg don't go together well.
Either turn up jpeg quality settings up from the default (of around 75%) or go for png!
Note that 90-95% quality, while greatly improving text quality also greatly enlarges size and going for png may well save you space in addition to being lossless..
I had a similar issue with the text being quite badly aliased when drawn onto the image. This is my solution which produces a reasonable text quality.
"text" is a System.Windows.Media.FormattedText instance.
BitmapFrame originalImageSource = BitmapFrame.Create(new Uri(file.FullName), BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
var visual = new DrawingVisual();
using(DrawingContext drawingContext = visual.RenderOpen()) {
drawingContext.DrawImage(originalImageSource, new Rect(0, 0, originalImageSource.PixelWidth, originalImageSource.PixelHeight));
drawingContext.DrawText(text, topRight);
}
var renderTargetBitmap = new RenderTargetBitmap(originalImageSource.PixelWidth,
originalImageSource.PixelHeight,
originalImageSource.DpiX, originalImageSource.DpiY,
PixelFormats.Pbgra32);
renderTargetBitmap.Render(visual);
BitmapFrame bitmapFrame = BitmapFrame.Create(renderTargetBitmap);
BitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(bitmapFrame);
encoder.Save(stream);

How to calculate FixedPage dimensions

This snippet is part of some code used to generate an XPS document. XPS document generation is no joke. I wish to avoid pasting any of that XPS code here if at all possible. Instead, this code focuses on the WPF portion of the problem.
The problem I am asking for you to help with is here. I have hard coded the dimensions to work for a test image:
double magicNumber_X = 3.5;//trial and error...3 too small 4 too big
fixedPage.Arrange(new Rect(new Point(magicNumber_X, 0), size));
Instead, how can I fix this code to calculate the coordinates?
Full Method:
private PageContent AddContentFromImage()
{
var pageContent = new PageContent();
var fixedPage = new FixedPage();
var bitmapImage = new BitmapImage(new Uri(hardCodedImageSampleFilePath, UriKind.RelativeOrAbsolute));
var image = new Image();
image.Source = bitmapImage;
fixedPage.Children.Add(image);
((IAddChild)pageContent).AddChild(fixedPage);
double pageWidth = 96 * 8.5;//XPS documents are 96 units per inch
double pageHeight = 96 * 11;
fixedPage.Width = pageWidth;
fixedPage.Height = pageHeight;
var size = new Size(8.5 * 96, 11 * 96);
fixedPage.Measure(size);
double magicNumber_X = 3.5;//trial and error...3 too small 4 too big
double magicNumber_Y = 0;
fixedPage.Arrange(new Rect(new Point(magicNumber_X, magicNumber_Y), size));
fixedPage.UpdateLayout();
return pageContent;
}
I'm a little surprised FixedPage.Measure(size) does not correct the issue by itself. I tried passing no params, e.g. fixedPage.Arrange(new Rect(), size)) still no go.
FWIW, this calculation worked fine when I was using PrintDocument.
private void pd_PrintPage(object sender, PrintPageEventArgs e)
{
Graphics g = e.Graphics;
RectangleF marginBounds = e.MarginBounds;
RectangleF printableArea = e.PageSettings.PrintableArea;
int availableWidth = (int)Math.Floor(printDocument.OriginAtMargins ? marginBounds.Width : (e.PageSettings.Landscape ? printableArea.Height : printableArea.Width));
int availableHeight = (int)Math.Floor(printDocument.OriginAtMargins ? marginBounds.Height : (e.PageSettings.Landscape ? printableArea.Width : printableArea.Height));
Rectangle rectangle = new Rectangle(0,0, availableWidth -1, availableHeight - 1);
g.DrawImage(_image, rectangle);
I hooked into FixedPage.Loaded event because FixedPage.ActualHeight is required in order to perform the calculation and will not be set until the control has loaded. This also means that with this mechanism FixedPage has to be displayed to correctly perform an automated print.
void fixedPage_Loaded(object sender, RoutedEventArgs e)
{
var fixedDocument = sender as FixedPage;
CalculateSize(fixedDocument);
}
private void CalculateSize(FixedPage fixedPage)
{
PrintQueue printQueue = LocalPrintServer.GetDefaultPrintQueue();
PrintCapabilities capabilities = printQueue.GetPrintCapabilities();
//get scale of the print wrt to screen of WPF visual
double scale = Math.Min(capabilities.PageImageableArea.ExtentWidth / fixedPage.ActualWidth, capabilities.PageImageableArea.ExtentHeight / fixedPage.ActualHeight);
//Transform the Visual to scale
fixedPage.LayoutTransform = new ScaleTransform(scale, scale);
//get the size of the printer page
var sz = new Size(capabilities.PageImageableArea.ExtentWidth, capabilities.PageImageableArea.ExtentHeight);
//update the layout of the visual to the printer page size.
fixedPage.Measure(sz);
double x = capabilities.PageImageableArea.OriginWidth;
double y = capabilities.PageImageableArea.OriginHeight;
fixedPage.Arrange(new Rect(new Point(x, y), sz));
fixedPage.UpdateLayout();
}

Categories