ghostscript print to usercontrol in c#

View: New views
3 Messages — Rating Filter:   Alert me  

ghostscript print to usercontrol in c#

by peng tao-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi Experts,
 
I am Tao from China, currently our project is trying to print pdf to usercontrol in c# (like preview in our own panel).
My test project works all right when print pdfs to local files(jpg, bmp...) but fails when printing to usercontrol.
 
In a word: How can we print a pdf to usercontrol directly? (Better to load pdf in memory as a C# object, like Bitmap...)
 
Below lines show how I construct Command Parameters to pass to the GhostScript DLL:
// Construct Command Parameters to pass to the GhostScript DLL
List<string> commandList = new List<string>();
commandList.Add("convert"); //First parameter is ignored
commandList.Add("-dSAFER");
commandList.Add("-dBATCH");
commandList.Add("-dNOPAUSE");
commandList.Add("-dCOLORSCREEN");
commandList.Add("-dDOINTERPOLATE");
commandList.Add("-dTextAlphaBits=4");
commandList.Add("-dGraphicsAlphaBits=4");
commandList.Add("-dUseCIEColor");
commandList.Add("-sDEVICE=display");
 
//GetDC() was imported from User32.dll
//deviceHandle is from PictureBox1.Handle
IntPtr hdc = GCUtility.GetDC(deviceHandle);
commandList.Add("-dDisplayHandle=" + hdc.ToString());
int planes = GCUtility.GetDeviceCaps(hdc, (int)DeviceCap.PLANES);
int bitspixel = GCUtility.GetDeviceCaps(hdc, (int)DeviceCap.BITSPIXEL);
int depth = planes * bitspixel;
int resolution = GCUtility.GetDeviceCaps(hdc, (int)DeviceCap.LOGPIXELSY);
int format = (int)DISPLAY_FORMAT_COLOR.DISPLAY_COLORS_RGB | (int)DISPLAY_FORMAT_ALPHA.DISPLAY_ALPHA_LAST
| (int)DISPLAY_FORMAT_DEPTH.DISPLAY_DEPTH_8
| (int)DISPLAY_FORMAT_ENDIAN.DISPLAY_LITTLEENDIAN
| (int)DISPLAY_FORMAT_FIRSTROW.DISPLAY_BOTTOMFIRST;
commandList.Add("-dDisplayformat=" + format.ToString());
commandList.Add("-dDisplayResolution=" + resolution.ToString());
commandList.Add(inputFileName);
 
 
Ran the application but Nothing happened.(no exception)
 
Thank Mark who give me a lot of help and figured out a workaround: 1) convert pdf to jpg 2) load jpg. But sometimes we have to load pdfs with many pages which might be timecomsuming.

 Hope you can help me :)

 Thanks,
 
Tao Peng
 
 

_______________________________________________
gs-devel mailing list
gs-devel@...
http://www.ghostscript.com/mailman/listinfo/gs-devel

Re: ghostscript print to usercontrol in c#

by Ken Sharp :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

At 11:59 03/09/2009 +0800, peng tao wrote:

>In a word: How can we print a pdf to usercontrol directly? (Better to load
>pdf in memory as a C# object, like Bitmap...)

You can't print to a c# object 'directly', Ghostscript renders PostScirpt
or PDf into a raw bitmap, the Ghostscript device is the component which
converts the bitmap into 'something else'. This can be a file format, or it
can drive a printer directly using the data.

I believe in your case you will need to create your own device which is
handed the bitmap data from the rendering engine, and you will need to
refactor it as required to fit your own C# object.

A starting point in understanding how to do this might be the 'jpeg' family
of devices. There are 3 of these, and they are all defined in the file
gdevjpeg.c



             Ken
_______________________________________________
gs-devel mailing list
gs-devel@...
http://www.ghostscript.com/mailman/listinfo/gs-devel

Re: ghostscript print to usercontrol in c#

by peng tao-4 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Ken,
 
I really appreciate your reply and valuable suggestion. :)
 
As you said, I will have a try this 'my own device'.
 
Thanks,
 
Tao

2009/9/3 Ken Sharp <ken.sharp@...>
At 11:59 03/09/2009 +0800, peng tao wrote:

In a word: How can we print a pdf to usercontrol directly? (Better to load pdf in memory as a C# object, like Bitmap...)

You can't print to a c# object 'directly', Ghostscript renders PostScirpt or PDf into a raw bitmap, the Ghostscript device is the component which converts the bitmap into 'something else'. This can be a file format, or it can drive a printer directly using the data.

I believe in your case you will need to create your own device which is handed the bitmap data from the rendering engine, and you will need to refactor it as required to fit your own C# object.

A starting point in understanding how to do this might be the 'jpeg' family of devices. There are 3 of these, and they are all defined in the file gdevjpeg.c



           Ken



--
PENG Tao / 彭韬


_______________________________________________
gs-devel mailing list
gs-devel@...
http://www.ghostscript.com/mailman/listinfo/gs-devel