Tôi nhận được từ một nơi nào đó trên web - không thể nhớ chính xác vị trí nào nhưng nó hoạt động cho tôi!
Tôi vừa biến nó thành một chức năng tuyệt vời.
Nó sử dụng các API GhostScript (GSdll32.dll)
Ví dụ về các tham số imageFormat là "jpeg", "tiff32nc", vv
#region GhostScript API functions
[DllImport("gsdll32.dll", EntryPoint = "gsapi_new_instance")]
private static extern int CreateAPIInstance(out IntPtr pinstance,
IntPtr caller_handle);
[DllImport("gsdll32.dll", EntryPoint = "gsapi_init_with_args")]
private static extern int InitAPI(IntPtr instance, int argc, IntPtr argv);
[DllImport("gsdll32.dll", EntryPoint = "gsapi_exit")]
private static extern int ExitAPI(IntPtr instance);
[DllImport("gsdll32.dll", EntryPoint = "gsapi_delete_instance")]
private static extern void DeleteAPIInstance(IntPtr instance);
#endregion
public bool CreateImage(string inputPath, string outputPath, string imageFormat, int firstPage, int lastPage, int width, int height)
{
bool result = false;
try
{
string[] args = GetArgs(inputPath, outputPath, imageFormat, firstPage, lastPage, width, height);
var argStrHandles = new GCHandle[args.Length];
var argPtrs = new IntPtr[args.Length];
// Create a handle for each of the arguments after
// they've been converted to an ANSI null terminated
// string. Then store the pointers for each of the handles
for (int i = 0; i < args.Length; i++)
{
argStrHandles[i] = GCHandle.Alloc(StringToAnsi(args[i]), GCHandleType.Pinned);
argPtrs[i] = argStrHandles[i].AddrOfPinnedObject();
}
// Get a new handle for the array of argument pointers
var argPtrsHandle = GCHandle.Alloc(argPtrs, GCHandleType.Pinned);
// Get a pointer to an instance of the GhostScript API
// and run the API with the current arguments
IntPtr gsInstancePtr;
CreateAPIInstance(out gsInstancePtr, IntPtr.Zero);
InitAPI(gsInstancePtr, args.Length, argPtrsHandle.AddrOfPinnedObject());
// Cleanup arguments in memory
for (int i = 0; i < argStrHandles.Length; i++)
argStrHandles[i].Free();
argPtrsHandle.Free();
// Clear API
ExitAPI(gsInstancePtr);
DeleteAPIInstance(gsInstancePtr);
result = true;
}
catch(Exception e)
{
throw e;
}
return result;
}
Bạn đã thử gì trong PDFSharp? Có một ví dụ ở đây: http://www.pdfsharp.net/wiki/ExportImages-sample.ashx?AspxAutoDetectCookieSupport=1 – keyboardP
Hiển thị cho chúng tôi những gì bạn đã thử. Chúng tôi sẽ giúp bạn với nó. – Amy
Cảm ơn bạn đã tìm hiểu! Tôi đã không thử bất cứ điều gì ngoại trừ ví dụ bạn liên kết mà trích xuất các hình ảnh trong PDF thay vì rendering PDF và xuất nó vào một hình ảnh. Đó là lý do tôi yêu cầu: Tôi không thấy một cách để làm điều đó trong iTextSharp hoặc PDFSharp. Tôi đã Googled rất nhiều và đưa ra tay trắng. – Jason