Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Postscript editing with Ghostscript

New Here ,
Apr 15, 2011 Apr 15, 2011

Hi,

I am a student that is currently working with a project where we are supposed to read something from a postscript file and place it in a new postscript file.

I want to edit a postscript file with the help of ghostscript to make an output with certain values I have picked out of the original postscript file.

Right now I have a file that does this, but I want to get the fonts that are embedded in a hexadecimal string and decode it so I get the ASCII symbol from it.

The original file have objects that look something like this

/g5 <1C60D8A8C9B64EDFFB83C6241DB110BEE5AB2FAD9D94B39ED5E81E7411B

66E9361DDE78FC667AB91EF9824>

And what I want to do is to pick them out and check them against some dictionary in the postscript code (systemdict???) and pick out its value.

Does anyone have something like this or an example to do this?

Right now my code to pick out the file starts something like this:

(%stdout) (w) file def

where I get the file and now I want to search for let's say the string "<1C60D8" and copy everything that is between this and the symbol ">"

After that I want to check what the hexadecimal code hides underneath it, which in this case is a "E" in Arial.

If anyone have any info on how to do this I would be very happy.

Best regards.

TOPICS
Programming
4.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 15, 2011 Apr 15, 2011

I'm having a little trouble following what exactly you want to accomplish and why.

Not to be critical, but in this case, it seems like you are going to a lot of trouble to access information in an odd way.

Maybe a more thorough explaination of both your starting point (why you need to search using a hexadecimal string, and where it comes from) and ending point (what you do with a resulting ascii character in the font), would set me straight on your project. I apologize if you have exactly outlined an assignment that you were given.

However:

With PostScript code the objects you referred to can be converted to strings and scanned for matching values, parsed into substrings, etc. whether you store them in a separate file or not. Using PostScript font encoding/handling procedures you can calculate/process/retrieve character parameters using ascii, or hexadecimal, or octal values as your starting point. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 18, 2011 Apr 18, 2011

Hi!

I want to extract the text so I can have it in a new file without the hexadecimal strings and in pure ASCII format. So <hexadecimal> becomes a "P" for example.

After that I can make a software that picks out the "P" from the new postscript file and puts it on my homepage, and the final result is a homepage with everyones test results from the last exam for example.

Right now I am using ghostscript and the following command line which I found on the internet somewhere to extract the information in the file.

gswin32c.exe -q -dNODISPLAY -dNOPAUSE -sFONTPATH=C:\WINDOWS\Fonts -dBATCH extract.ps input.ps > output.ps

where extract.ps is the file in which I need to do some encoding to retrieve the hexadecimal string and encode it and lastly output it so it becomes an "normal" font, and also write in some coordinates of where they should lie.

If you have any knowlegde of how I should start that would be awesome. Right now I am thinking that this probably wont work and I'll have to do another approach like the other students, but since I found out that PostScript is a programming language I thought I could make it.

Right now I am  thinking I probably need to do something like this in the beginning.

(%Stdout)(w)

test{

     <hexadecimal string>

     dup ????

     writestring

     check against systemdict?

     gcheck??

     <end of hexadecimal string>

    } bind def

show test???

I am currently trying to read some literature that I found on the internet but it is very difficult!

If you know how to solve the problem, with an example, please let me know

Best regards!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 18, 2011 Apr 18, 2011

I would prefer to do what you want to do with a more general purpose language, such as "C", for instance, probably like the other students.

However, that doesn't mean it can't be done with PostScript and I think I can probably help you with your project, and broaden our understanding of PostScript and what it is capable of.

Can you post (or email) a complete input file for me to look at?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2011 Apr 19, 2011

Hello Mr.Horton,

I have sent an email to the email adress on your profile page, with an attached file and also what I want to accomplish.

Best regards.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 19, 2011 Apr 19, 2011

Joe,

My schedule is really tight right now, so don't expect a reply until Friday or Saturday. I will respond sooner if I get a break before then.

Looking forward to helping,

Marvin Horton

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 19, 2011 Apr 19, 2011

Wow that is awesome to hear! I really appreciate all help I can get, it

would be a great accomplishment to learn some postscript and just not be

like the other drones and do it the conventional way

2011/4/19 Mr. Horton <forums@adobe.com>

Joe,

>

My schedule is really tight right now, so don't expect a reply until

Friday or Saturday. I will respond sooner if I get a break before then.

>

Looking forward to helping,

Marvin Horton

>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 19, 2011 Apr 19, 2011
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 20, 2011 Apr 20, 2011

Hi,

Thanks, although I already got those books, but it has been a pain in the neck to try and read them, they've helped me understand a little bit more about postscript but I honestly don't think I have it in me to read everything from the books

But I have skimmed through the most important parts so I understand the code somewhat now, but it is just all about writing it myself where the problems occurs

Best regards!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 21, 2011 Apr 21, 2011

Joe,

The first problem is that the moment you define a variable, like /g30 <1C60D8...> def, it can no longer be accessed directly as a string of hexadecimal characters due to the enclosing < and >.

The following method should get you past that hurdle and on to the part where you take hexadecimal pairs and convert them to valid font characters.

%!PS-Adobe-3.0
%%Title: hex2ascii.ps
%%Creator: Marvin R. Horton
%%CreationDate: 4/21/2011
%%For: Joe
%%Purpose: Solving the problem of hexadecimal encoding to binary in PostScript.
%%Context: PostScript interpreter must allow user writable file system.
%%EndComments

%%BeginProlog
/tmpstr 256 string def
/poststr 256 string def
%%EndProlog

%%BeginSetup

/g30 <1C60D8A8C9B64EDFF4BBA9405C68CB1D32394A0B35B38FF15650A7F4CA
980D304B0E82F2EE31DE1B207C9690A7D1CE7998A46A2671A721A2721266CDB3
CB7162FB8735F8901B59D497FC48B1C8BA82BBC82DEF38A7FA67F275089B99C0
47F77478B3299CF33148E1E790C5C7235CAB593CF69659FDEE7364A65AC06E62
96> def

%%--g30 is a string of binary data once it is defined.

%%--open a file where you can output strings
(tempout) (w) file /fd exch def

%%--write string out as hexadecimal characters to a file
fd g30 writehexstring

%%--append an end-of-line character
fd (\n) writestring

%%--close the file
fd closefile


%%--open the same file to read in each line as though it was normal text
(tempout) (r) file /fd exch def

%%--read hex string in file back in as normal character string--
fd tmpstr readline

fd closefile

%%--print converted string to stdout for debugging
tmpstr print (\n) print

%%--now search using a string instead of the "<1c60d8" value
%%--Note: writehexstring used above outputs hex characters A-F as a-f (lowercase)
tmpstr (1c60d8) anchorsearch true eq{
pop /poststr exch def

%%--poststr will have all the hexadecimal characters following your search string
poststr print (\n) print
}if

%%--At this point you have a normal string of hexadecimal characters that you could convert to ascii...
%%--...with a "lookup table".
(\n======End of Job Listing======\n) print

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2011 Apr 26, 2011

Wow this is great! I REALLY appreciate the help you have given me! Sorry for the late reply since I've been away from school for a while due to easter holiday!

How do I make it search for all <1c60D8 in the original file if I have more than one, and then "define" it and later search for it with your anchorsearchstring?

The "lookup table", is that something that I have to write myself or can I use something that is already there in postscript? (systemdict??) or some type of windows fontdictionary?

And once again, thank you for all the help, You rock!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 26, 2011 Apr 26, 2011

Joe,

I'll take "you Rock!" as a compliment, however the point here is for you to increase your knowledge/skills so that you can be a productive and contributing member in whatever groups you are involved with, starting with your class and on to a business or organization.

Toward that end, I would like you to do the following things before I write any more example code for you:

Write a description of the class that prompted your post on the forum.

Read and study Chapter 7 in the PostScript Language Tutorial and Cookbook.

Write out (do not use cut and paste) and test all the examples up to the Recursive Graphics section demonstrating fractals.

Change parameters, one at a time, and retest to prove that you understood what would result after making each change.

It is important in developing both your skill and understanding to do the assignment above as stated, as it could be accomplished in a couple of hours and you will get alot out of it if you apply yourself.

Apply what you now know to the question you asked - "How do I make it search for all <1c60D8 in the original file if I have more than one, and then "define" it and later search for it with your anchorsearchstring?". Remember that <...> denotes a hexadecimal input string, but the characters < and > do not exist in the resulting string.

Divide your question/problem into logical parts and then address each with what you know, particularly the looping and conditional statement concepts you just practiced. You won't be able to solve all of your question with Chapter 7, but you will have made a large leap forward.

This is how I started, except I began in Chapter 1, and I don't regret even one hour out of the many I have spent learning the PostScript language and how to apply it in a business setting. I haven't learned it all yet...

Oh, and by the way, when it is time to present your report in class, you will know what you are talking about, instead of just knowing someone that "Rocks!" on the internet.

You can learn it!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 27, 2011 Apr 27, 2011
LATEST

Thanks alot for all the encouragment and I will definitely try to do my best to do what you have told me! It will probably take me a while since I have a lot in school right now cause of missed exams and such but I'll probably get back to you in a week or so.

Thanks for all the help up untill now!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines