I m trying to convert multiple file types(for ex- .txt) into pdf using ghostscript. I am able to get the .ps file but that is not getting converted to .pdf !! Its been two days now I am working on it .Seriously need some help.
Asked
Active
Viewed 778 times
0
-
1Welcome to SO. Please show exactly what you have tried. How do you get a .ps file from the text files? What gs command line and what gs version are you using? – Stefan Hegny Nov 24 '16 at 15:34
-
Further; what operating system are you using, what version of Ghostscript, what command line, what is the back channel output ? You are aware that Ghostcrip doesn't handle text as an input ? Only PDF, and PostScript; GhostPCL handles PCL and PXL and GhostXPS handles XPS as an input. – KenS Nov 24 '16 at 15:57
-
I have used the code mentioned on this URL ..but that is not working. http://aspalliance.com/1447_Creating_PDFs_with_C_using_Ghostscript.all – Harshit Agarwal Nov 24 '16 at 15:58
-
@KenS... I belive Ghostscript converts .txt to .ps ..!! – Harshit Agarwal Nov 24 '16 at 16:00
-
I believe you are mistaken :-) Its possible to write a PostScript program which will read a text file, and lay it out on a page, with varying degrees of success, but Ghostscript itself does **not** handle text files, if you pass a text file to Ghostscript it will attempt to interpret it as PostScript and will, almost immediately I would guess, throw a PostScript error. Because the PCL specification states that a file without the appropriate language markers should be treated as 'text' you *can* send a text file to GhostPCL. No layout or font control though. – KenS Nov 24 '16 at 16:09
-
@KenS..do u know some mechanism using which i can convert various file types into pdf . Be it .msg or be it .html or be it anything ...but using ghostscript ..!! – Harshit Agarwal Nov 24 '16 at 16:16
-
The URL you point doesn't suggest that Ghostscript can accept text. It has you print from an application to a virtual PostScript printer, and then feed that into Ghostscript to get a PDF file. Now, what you need to do here is explain what you've done (please don't just point to the URL again), and which part of what you've done doesn't work, you should also say what you mean by 'doesn't work'. Does it crash, throw an error, produce garbage, something else ? Finally note that Ghostscript is licensed under the AGPL, if you use Ghostscript.NET then you will need to publish your source too. – KenS Nov 24 '16 at 16:16
-
The **only** files you can directly convert into PDF using Ghostscript are PostScript files. GhostPCL can additionally convert PCL and PXL and GhostXPS can handle XPS. That's all. – KenS Nov 24 '16 at 16:17
-
It does not throw any error ..but it does not either give any output..only thing it does is ..it gives me a GSOUTPUT.PS. file ... – Harshit Agarwal Nov 24 '16 at 16:19
-
I know, you said that. And I pointed out that the code there does not convert text files to PDF directly by using Ghostscript. It launches an application to process the text file, then has hte application print to a virtual PostScript printer. **That** step produces PostScript, the PostScript is sent to Ghostscript for conversion to PDF. Now as I said, there's a heck of a lot of steps that goes through and no indication form you as to where the problem occurs, or indeed what the problem is. 'Doesn't work' is insufficient for anyone to help you. – KenS Nov 24 '16 at 16:22
-
So you need to debug it, does the application launch, does it print to the printer (does a PostScript file get produced), does Ghostscript laucnh, does it give any messages on the back channel etc. – KenS Nov 24 '16 at 16:23
-
Right, so you have a PostScript file, that means that either Ghostscript isn't getting launched, or it is producing an error (most likely its not getting launched). Can you run Ghostscript from the command line on that PostScirpt file ? WHat happens ? – KenS Nov 24 '16 at 16:24
-
I get this .. GPL Ghostscript 8.56 (2007-03-14) Copyright (C) .. Error: /undefinedfilename in (GSOUTPUT.PS.) Operand stack: Execution stack: %interp_exit .runexec2 --nostringval-- --nostringval-- --nostringval- - 2 %stopped_push --nostringval-- --nostringval-- --nostringval-- fa lse 1 %stopped_push Dictionary stack: --dict:1139/1684(ro)(G)-- --dict:0/20(G)-- --dict:70/200(L)-- Current allocation mode is local Last OS error: No such file or directory GPL Ghostscript 8.56: Unrecoverable error, exit code 1 – Harshit Agarwal Nov 24 '16 at 16:30
-
So, you've got the filename wrong (and are using an ancient version of Ghostscript to boot). Almost certainly you simply haven't specified the full path to the file, try again but this time give Ghostscript the full path, You should probably also consider getting a version of Ghostscript less than 9 years old too. The current version is 9.20 – KenS Nov 24 '16 at 16:35
-
the file that is being produced is the same as I mentioned i.e. GSOUPUT.PS. (yes there is a dot. after PS) – Harshit Agarwal Nov 24 '16 at 16:39
-
The undefinedfilename error means Ghostscript can't find the file. Did you specify the **full** drive and path to the file ? The only likely reason that Ghostscript can't find the file is that you haven't given it the correct path, especially if you are executing it from somewhere other than the directory where the file is created. – KenS Nov 24 '16 at 16:49
-
I specified the full path .. and also changed the ghostscript version to gs909w32.exe .. But still the the same thing comes on the command prompt ..!!!! Just want to make sure if the filename that i m getting is correct ..it is GSOUTPUT.PS. (there is a dot. after PS in the filename) – Harshit Agarwal Nov 24 '16 at 16:53
-
I have no idea if the filename is 'correct', I assume you've checked the file is present. There is, realistically, no reason other than the file being missing, or the fielname being incorrect, for that error. Try copying the file somewhere else with a different name and try again. You could also give the entire command line, since you haven't mentioned it. If you're going to upgrade, why update to an old version ? – KenS Nov 24 '16 at 16:59
-
can i have your email id ..so that i can share the screenshots and then perhaps u can find the exact problem.. WE can upgrade to any newer version u say ..once my code gets approved by my head in the organization... – Harshit Agarwal Nov 24 '16 at 17:05
-
You can post screenshots to dropbox, or some other public location and post a URL here. – KenS Nov 24 '16 at 20:32