如何使用带有C#的ASP.NET在PDF中截取图像?
问题描述:
我想使用带有C#的asp.net在PDF中截取图像。我使用adobe acrobat pro开发了一个PDF。我需要从pdf中获取图像作为屏幕截图左右,并使用c#将此图像转换为二进制(base 64)文件。
我可以在代码部分正在运行的情况下拍摄页面的屏幕截图。但无法在PDF文件中获取图像的屏幕截图
我尝试过:
I want to take screenshot of image in a PDF using asp.net with C#. I have developed a PDF using adobe acrobat pro. I need to get the Image from the pdf as a screen shot or so and convert this image to a binary (base 64) file using c# .
I am able to take the screen shot of the page with the code part is running. But the unable to get the screen shot of a image in a PDF File
What I have tried:
public static void Capture(string CapturedFilePath)
{
Bitmap bitmap = new Bitmap
(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics graphics = Graphics.FromImage(bitmap as System.Drawing.Image);
graphics.CopyFromScreen(25, 25, 25, 25, bitmap.Size);
bitmap.Save(CapturedFilePath, ImageFormat.Bmp);
}
答
考虑所有ASP.NET代码在Web服务器上而不是在客户端上运行完整,你不能这样做。
你需要一些javascript库才能捕获客户端的屏幕截图,我甚至不确定是考虑到安全问题,可能会出现这种情况。
现在,如果您正在谈论将PDF转换为图像,您需要找到一个可以为您执行此操作的库或呈现图像而不是文件。 Google为 pdf to image library [ ^ ]。
Considering all ASP.NET code runs ENTIRELY on the web server and not on the client, you can't do this.
You would need some javascript library to be able to capture screen shot on the client, which I'm not even entirely sure is possible given the security concerns.
Now, if you're talking about converting a PDF to an Image, you need to find a library that either does this for you or renders to an image instead of a file. Google for "pdf to image library[^]".