Lo obtuve de algún lugar en la web, no recuerdo exactamente dónde pero me funciona.
Acabo de hacer una buena función.
Utiliza las API Ghostscript (gsdll32.dll)
Ejemplos del parámetro ImageFormat son "jpeg", "tiff32nc", etc.
#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;
}
¿Qué pruebas en PDFSharp? Hay un ejemplo aquí: http://www.pdfsharp.net/wiki/ExportImages-sample.ashx?AspxAutoDetectCookieSupport=1 – keyboardP
Muéstrenos lo que ha intentado. Te ayudaremos con eso. – Amy
¡Gracias por los votos a favor! No he intentado nada excepto el ejemplo que vinculó, que extrae las imágenes en el PDF en lugar de representar el PDF y enviarlo a una imagen. Esa es la razón por la que estoy preguntando: no veo una manera de hacerlo en iTextSharp o PDFSharp. Busqué en Google y vine con las manos vacías. – Jason