Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating document in Postscript format with C#

Is there an API available to write directly to postscript format with C#? I am currently using pdfnet to write a document to pdf and then use adobe to export that to postscript. However, quality is being lost during the conversion and I need to go directly to postscript and skip creating the pdf.

The document contains an image with some text overlayed on top of it.

like image 951
doclove Avatar asked Sep 19 '25 15:09

doclove


1 Answers

You know how to use files in C#, right? A very simple way to do it would be to just have your program create a new ofstream or whatever C# calls it, naming it whatever.ps, and just appending strings to the file. Its really quite easy to learn, although I'd recommend actually getting a print copy of the Postscript Language Reference manual if you are going to do it that way. Even though you can get an electronic version for free, it really isn't as useful as a print copy unless you have more than one monitor.

For instance, to draw a 1" square centered at the middle of a portrait-oriented piece of letter-size paper in C++, I'd do something like:

myFile << "%!PS-Adobe-2.0 \n" //header block
       << "%%Creator: INSERT YOUR NAME HERE \n"
       << "%%Title: FILENAME.ps \n"
       << "%%Pages: 1 \n"
       << "%%PageOrder: Ascend \n"
       << "%%BoundingBox: 0 0 612 792 \n"
       << "%%DocumentPaperSizes: Letter \n"
       << "%%EndComments \n"

myFile << "<< /PageSize [612 792] >> setpagedevice \n" //page setup
       << "396 306 translate \n" //set (0,0) to center of page

myFile << "-36 -36 72 72 rectfill \n" //the rectangle at last!

You would need to translate that into whatever language you are using, though. Also, to be more readable, you might put the header block into its own function. In fact, you don't even need the newlines at the end of each string, except in the header block.

like image 137
AJMansfield Avatar answered Sep 21 '25 06:09

AJMansfield