Validating a Postscript without trying to print it?

Saving data to Postscript in my app results in a Postscript file which I can view without issues in GhostView, but when I try to print it, the printer isn't able to print it because it seems to be invalid.

Is there a way to validate / find errors in Postscript files without actually sending it to a printer? Preferred would be some kind of Java API/library, but a program which does the same would be fine as well.

Edit #1 : no I don't know why it's invalid, nor even necessarily if it's invalid, but would like to be able to validate it outside of ghostview, or figure out what's going on when it can't print.

Answer : Well using the ps2ps trick I was able to see the output that Postscript does and there check the difference. The difference was that I am not allowed to have a decimal number for the width or height of images in the Postscript, but rather only integers. So I still didn't find a way to validate, but this way was good enough for my problem. Thanks.

Asked by: Oliver591 | Posted: 21-01-2022

Answer 1

Whenever I need to validate a PostScript file using Ghostscript without having to actually look at its rendered page images I use the "nullpage" device:

gswin32c ^
   -sDEVICE=nullpage ^
   -dNOPAUSE ^
   -dBATCH ^
   c:/path/to/file/to/be/validated.pdf-or-ps ^
   1>validated.stdout ^

In case of a problem, there will be a non-zero %errorlevel% set, and the validated.stderr logfile will contain all the messages Ghostscript spit out during rendering.

Answered by: Hailey753 | Posted: 22-02-2022

Answer 2

Do you know why it's invalid?

My suggestion would have been to feed it to Ghostscript/Ghostvoiew, but given Ghostview can view it, it would seem that at least some interpreters think it is valid Postscript.

So it may be something specific to your printer - either it's picky about something in the PS that Ghostscript allows, or it's accessing something that doesn't exist on your printer (filesystem, perhaps) or exceeding some limit of memory, or...

The point being that it may not be an erroneous PS program and so a library/API to validate it might not help

Edit: Does any of it print? Have you tried a printer from a different manufacturer (or vendor of Postscript interpreter, anyway). Does Ghostview give/log any warnings or errors?

Where (what application) does the document originate from?

Can you generate other instances of the document? (e.g. a really simple/empty one to see if that also gives errors)

Unless there's an API providing access to the specific interpreter that's used in your printer, I think you are validating it against another PS interpreter (Ghostscript).

Since there aren't that many PS clones in the world, getting access to another non-GS based one probably isn't going to be easy

Edit2: This link (if quite old information) gives information about how to get more details from your printer on the error:

Answered by: Lucas160 | Posted: 22-02-2022

Answer 3

If you can see it on ghostview, it means ghostscript can parse it.

So, one trick you could try using to print (but not to actually validate) your file would be to use ghostscript's postscript output mode (there is a wrapper called ps2ps for it, which mainly adds -sDEVICE=pswrite; there is also ps2ps2 which uses -sDEVICE=ps2write).

Answered by: Kellan352 | Posted: 22-02-2022

Similar questions

java - validating JAXB, but whitespace not ignored

some code snippets. The java coding doing the jaxb unmarshaling. pretty straightforward, copied out of tutorials online. JAXBContext jc = JAXBContext.newInstance( "xmlreadtest" ); Unmarshaller u = jc.createUnmarshaller(); // setting up for validation. SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); StreamSource schemaSource = new StreamSource(

java - Ignore element order while validating XML against XSD

We have an XML which needs to be validated against an XSD. The XML is being generated by XSTREAM. and We are using jaxp api's to validate the XML against the respective XSD. Unfortunately, currently our test case fail as the generated XML has elements/Tags in different order/sequence than the XSD. Is it possible to ignore the order of elements in generated XML while validating it against XSD? Thanks for t...

Getting Schema info from XML while validating in Java

I need to validate XML file against XML Schema so that the schema info is taken from the XML. I have XML document which defines its namespace. Like this: <?xml version="1.0" encoding="UTF-8"?> <myelement xmlns="mynamespace"> </myelement> The schema location is not in the document so I'd need to tell the validator where is the schema for given namespace. Right now...

java - Error while validating XML file with XSD

I have a xml file, let's call it test.xml and I have a schema for validation (schema.xsd). I'm also using the last version of TomCat. I was wondering what could cause the following errors : Error: URI=file:///C:/../Upload/test.xml Line=2: Document is invalid: no grammar found. Error: URI=file:///C:/../Upload/test.xml Line=2: Document root element "TEST_ROOT", must match DOCTYPE root "null". Sincerl...

validating xml in java as the document is built

I am working on converting an excel spread sheet into an xml document that needs to be validated against a schema. I am currently building the xml document using the DOM api, and validating at the end using SAX and a custom error handler. However, I would really like to be able to validate the xml produced from each Cell as I parse the excel document so I can indicate which cells are problematic in a friendlier way.

java - Design patterns for validating a file

We have to validate a CSV file containing various configuration parameters. Are there any standard design patterns to do this type of validation. More details: There are different types of records - each with their own validation logic Certain records cross reference other records There are rules on the order of the records There are rules on the eligibility of duplicate re...

Are there any java libraries for validating user supplied HTML, on the server side?

I have a service which takes the user supplied rich text (can have HTML tags) and saves it into the database. That data gets used by some other application. But sometimes the user supplied data has missing HTML tags and wrong closing tags. I want to validate if the user supplied data is valid HTML or not and depending on that I want to warn the user. Are there any java libraries to do HTML validation?

java - Validating an integer or String without try-catch

Ok, I'm lost. I am required to figure out how to validate an integer, but for some stupid reason, I can't use the Try-Catch method. I know this is the easiest way and so all the solutions on the internet are using it. I'm writing in Java. The deal is this, I need someone to put in an numerical ID and String name. If either one of the two inputs are invalid I must tell them they made a mistake. Ca...

java - Validating XML using XSD with regex pattern

I am parsing a XML file against a XSD containing some regex patterns used for checking input data, but only this regex generates an error, even if it passes into the Eclipse XSD plugin: InvalidRegex: Pattern value '(((com|org)\.)+(\b[a-z]+[.]{1}\b)+)?[A-Z]{1}[A-Za-z]+' is not a valid regular expression. The reported error was: 'This expression is not supported in the current option setting.'....

java - Validating parameters according to a fixed reference

The following method is for setting the transfer type of an FTP connection. Basically, I'd like to validate the character input (see comments). Is this going overboard? Is there a more elegant approach? How do you approach parameter validation in general? Any comments are welcome. public void setTransferType(Character typeCharacter, Character optionalSecondCharacter) throws NumberFormatExcep...

Still can't find your answer? Check out these amazing Java communities for help...

Java Reddit Community | Java Help Reddit Community | Java Community | Java Discord | Java Programmers (Facebook) | Java developers (Facebook)