3

这个有点混乱……

我正在使用 Adob​​e 的 PDF 查看器控件来查看 PDF,但我希望用户能够将图像拖到 PDF 上,然后当他们单击保存时,它将图像添加到该位置的 PDF 中。

实现 PDF 查看器非常困难,但我最终决定使用 Adob​​e 的控件,拍照,然后允许用户在 PDF 的图片上绘制图像。当他们单击保存时,一旦我确定了图像的位置,我将使用 PDFSharp 将图像放到 PDF 上,但我目前遇到的问题是我无法获得 PDF 的图片。

以下代码用于获取图片,但它所附加的面板仅显示为带有红色“X”和边框的白色背景......

using (Bitmap bitmap = new Bitmap(adobePDFViewer1.Width, adobePDFViewer1.Height))
                {
                    using (Graphics g = Graphics.FromImage(bitmap))
                    {
                        g.CopyFromScreen(new Point(adobePDFViewer1.Left, adobePDFViewer1.Top), Point.Empty, adobePDFViewer1.Size);
                    }
                    panelOverPdfViewer.BackgroundImage = bitmap;
                }

我认为这不是最好的方法,但我无法解决其他任何问题。任何帮助,将不胜感激!

编辑:

以下是一个非常有用的答案,这是工作代码:

这是我使用的代码:

Bitmap printscreen = new Bitmap(adobePDFViewer1.Width, adobePDFViewer1.Height);
                Graphics graphics = Graphics.FromImage(printscreen as Image);
                int left = this.Left + 396;
                int top = this.Top + 30;
                graphics.CopyFromScreen(left, top, 0, 0, printscreen.Size);
                pictureBoxOverPDFView.Image = printscreen;
4

1 回答 1

4

看看这个这个打印屏幕

并尝试使用 CopyFromScreen 的测试工作

private void PrintScreen()

{  

Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);

Graphics graphics = Graphics.FromImage(printscreen as Image);

graphics.CopyFromScreen(0, 0, 0, 0, printscreen.Size);

printscreen.Save(@"C:\Temp\printscreen.jpg", ImageFormat.Jpeg);

} 
于 2012-05-04T12:08:35.517 回答