Hi,
I am using the PDFSharp library to create PDF file from WinForm .net application.
I try to caputre the form with the following code:
Code:
private static void createPdf()
{
PdfDocument document = new PdfDocument();
PdfPage page = initPage(document);
XGraphics gfx = XGraphics.FromPdfPage(page);
XImage image = initImage();
gfx.DrawImage(image, 0, 0, page.Width, page.Height);
string fileName = "z.pdf";
document.Save(fileName);
Process.Start(fileName);
}
private static PdfPage initPage(PdfDocument document)
{
PdfPage page = document.AddPage();
page.Width = XUnit.FromMillimeter(m_Form.Width);
page.Height = XUnit.FromMillimeter(m_Form.Height);
return page;
}
private static XImage initImage()
{
BitmapImage screenCaptureInBitmapImage = getScreenCaptureInBitmapImage();
XImage image = XImage.FromBitmapSource(screenCaptureInBitmapImage);
return image;
}
private static BitmapImage getScreenCaptureInBitmapImage()
{
Bitmap screenCapture = copyFormScreenToClipboard();
BitmapImage screenCaptureInBitmapImage = new BitmapImage();
screenCapture.SetResolution(96.0F*2, 96.0F*2);
using (MemoryStream memStream2 = new MemoryStream())
{
screenCapture.Save(memStream2, System.Drawing.Imaging.ImageFormat.Bmp);
memStream2.Position = 0;
screenCaptureInBitmapImage.BeginInit();
screenCaptureInBitmapImage.CacheOption = BitmapCacheOption.OnLoad;
screenCaptureInBitmapImage.UriSource = null;
screenCaptureInBitmapImage.StreamSource = memStream2;
screenCaptureInBitmapImage.EndInit();
}
return screenCaptureInBitmapImage;
}
The issue is that the image captured in the function of getScreenCaptureInBitmapImage is blurred.
i tried to change the DPI value in the function of
screenCapture.SetResolution(96.0F*2, 96.0F*2);
but it didnt help me .
Does someone has any advise? Thanks - Tuvia