0

Solution is in last comment, but just in case if anyone is looking for workaround I summarized it here: http://sourceforge.net/mailarchive/message.php?msg_id=30391589


I managed to build GSDjVu with MinGW and current stable GhostScript (9.06). Quest in transforming Bash scripts to CMD wasn't so hard, but I was surprised that gsdjvu (gs interpreter with gsdjvu driver) doesn't accept PDF for input as expected. It accepts only PostScript. To avoid writing huge temp files I thought to make a pipeline, and here is example:

set args=-sstdout=nul -dSAFER -dNOPAUSE -dBATCH

gs %args% -sDEVICE=pswrite -sOutputFile=- test.pdf |^
   gsdjvu %args% -sDEVICE=djvusep -sOutputFile=- - |^
   csepdjvu - test.djvu

Which results in error:

*** csepdjvu: corrupted input file (lost RLE sync.)
*** (..\..\..\tools\csepdjvu.cpp:647)

Internal error at ./base/gdevdjvu.c:2831

 
If I output the result of gsdjvu to a file instead pipe, then there is no error:

gs %args% -sDEVICE=pswrite -sOutputFile=- test.pdf |^
   gsdjvu %args% -sDEVICE=djvusep -sOutputFile=test.sep -

csepdjvu test.sep test.djvu

 
Now if I compare file output from gsdjvu (test.sep) and pipe output from same (test2.sep):

gs %args% -sDEVICE=pswrite -sOutputFile=- test.pdf |^
   gsdjvu %args% -sDEVICE=djvusep -sOutputFile=- - > test2.sep

I get this diff:

screenshot

which after trivial analyses reveals that 0A is represented in piped output as 0D0A, or "line endings" are changed from Unix LF to Windows CRLF.

Why can this be, and is there a way to remedy it?
Or maybe it is a bug?

theta
  • 24,593
  • 37
  • 119
  • 159

1 Answers1

1

I'm not sure how DjVuLibre can fail to accept PDF as an input, since as far as I know it is a Ghostscript device. Do you have some documentation that says this can't be done ? If so, I would complain to the maintainers, I can't see any reason for this.

Since this works with file output, the logical answer is that there is some newline translation going on.

Some quick googling reveals that there is a lot of discussion about this, but I can't see anything which precisely matches your experience. You should probably tag this for MingW or more sensibly take it to a MingW support forum.

Or just stop piping the I/O around.

KenS
  • 30,202
  • 3
  • 34
  • 51
  • Ken, thanks for your input. Stopping pipes is not acceptable, as both PostScript and separation files, many times multiply input file size, and using temp files is slower (and lame) if it could be avoided. OTOH, GSDjVu should be able to accept PDF (`gsdjvu -h` reports PDF support), and I've already tried on Ubuntu in the past and it worked great - `djvudigital` bash script wrapper piped separation file to `csepdjvu` and it worked as said. But in current problem it's `gsdjvu` that writes file with LF character, but pipes with CRLF. – theta Jan 22 '13 at 11:48
  • It's sure something around MinGW. Only recent version of GhostScript can be compiled on it, w/o hunting for patches on trial and error. I'm not sure which GS version introduced MinGW possibility nor I did try to compile clean GS, as it's already available in binary format, but maybe I should try to see if it would accept PDF input. As for piping I don't know where to report this problem - you suggest I write to MinGW list and not to GS or DjVuLibre lists? – theta Jan 22 '13 at 11:49
  • Well it doesn't seem to be a GS issue, nor a DjVuLibre issue as such (I could be wrong here) but a bit of Googling found me an awful lot of complaints that stdin wasn't binary mode, and therefore would do CR/LF translation. Which seems more like a problem with MingW than anything else, to me. We don't specifically support compiling on MingW (or Cygwin), so you're on your own if you want to do that. Though we have recently incorporated some patches that *should* compile, its basically not a supported platform for us. – KenS Jan 22 '13 at 13:57
  • OK, thanks. I'll focus a search on point you suggested (mingw stdin), and then perhaps contact their list, and report results here. – theta Jan 22 '13 at 14:09
  • Finally, with further help from @KenS and other people this is possible recipe: http://sourceforge.net/mailarchive/message.php?msg_id=30391589 – theta Jan 23 '13 at 19:47