0

I have a Ghostscript to split PDF books in 50 pages interval. The problem is the GS is removing the transparency (I think this is called alpha channel in technical terms: http://www.peteryu.ca/tutorials/publishing/pdf_manipulation_tips) of the annotations. Look at the following paragraph from a book. The highlight was fully readable before the splitting.

Now, it is blacked out.

So, I am looking for a way to do the splitting using other tools like PDFtk or any other tool which will not flatten my annotations.

Ultimately, I want to run the script on a folder of files using Hazel in Mac.

Here is the Ghostscript if it helps: ($1 is Hazel's way of importing the file, I think).

echo "Page count: "
ournum=`gs -q -dNODISPLAY -c "("$1") (r) file runpdfbegin  pdfpagecount = quit" 2>/dev/null`
declare -i counter;
declare -i counterplus;
counter=1;
while [ $counter -le $ournum ] ; do
echo $counter
newname=`echo $1 | sed -e s/\.pdf//g`
reallynewname=$newname-$counter.pdf
counterplus=$counter+50;
yes | gs -dBATCH -sOutputFile=$reallynewname -dFirstPage=$counter -  dLastPage=$counterplus -sDEVICE=pdfwrite "$1" >& /dev/null
counter=$counterplus
done;

Can you guys help me with this?

Thanks

Dellu
  • 139
  • 1
  • 11
  • Annotations hsould not, in general be 'flattened', though I'm not sure what you mean by 'flattened' in this case. Whether you mean the annotation has been moved into the body of the document, or had transparency removed (as seems to be implied by your referencing alpha channels, which is rather less than the PDF definition of transparency). If you have a problem, then raise it as a bug, if people don;t do that then they won't get fixed! – KenS Sep 23 '16 at 07:10
  • Yes, I mean the transparency has been removed. I am not going to raise this as a bug because this problem has been known about Ghostscript for a long time. I am not expecting a sudden fix of the problem. There is a lot of discussion on this. What I want is an alternative script implemented using another tool. – Dellu Sep 23 '16 at 13:16
  • There's not (as far as I'm aware) any such knowledge in the Ghostscript development team. Nor is there apparently any such discussion in bug threads that I can find (I could be mistaken obviously). Transparency is supposed to be conserved, if its not then that would be a bug. Offhand I'm not even sure how you add transparency to an annotation, I'd have to go and look up the spec for that. If you don't want Ghostscript fixed, then I'd suggest you don't add a Ghostscript tag. Please note that Stack Overflow rules specifically prohibit 'please recommend some software' type questions. – KenS Sep 23 '16 at 14:09
  • I would be glad to see Ghostscript fixed. I am just afraid that it might not be in a near vicinity. So, great; I look it up if you can. And, I am not requesting alternative application. I am requesting a fix to it: or a solution based on other tools or by combining. One interesting approach a person suggested was to feed the first half with GS, and push the outputs to pdftk. I am not at all closer to be programmer. I cannot do so. Had I have some experiencer, I would have solved the issues in Gs by combining it with pdftk. – Dellu Sep 23 '16 at 14:11
  • FWIW screenshots don't help. I'm not doubting what you say, but its impossible to determine a problem, or fix it, based on a screenshot. You also don;t say what version of Ghostscript you are using. It looks to me like the problem 'may be' your PDF reader. I just tried a test here, and the output of Ghostscript works just fine in Ghostscript, Acrobat, MupPDF and some other PDF consuming tools I have available. However, pdf.js shows it as opaque. To my mind that;a a bug in the consumer, not Ghostscript! – KenS Sep 23 '16 at 14:17
  • You can look at the PDF file I created here https://www.dropbox.com/s/yjtg2cxa7xiqkto/out.pdf?dl=0 This PDF file is fine regarding the annotation in a number of PDF consumers, but not pdf.js – KenS Sep 23 '16 at 14:20
  • I also uploaded the original https://www.dropbox.com/s/j275ejntnpsuh52/test.pdf?dl=0 THIs one was created by Acrobat, and shows the same problem. – KenS Sep 23 '16 at 14:27
  • Regarding the Ghostscript; I am using the latest version. I have been having this issue over 2 years now. So, it cannot be due to a single bug in one of the version of GS. Another note: I am using Mac OS. You might be right that the problem in the OS. I am not able to see these annotations in Preview and many other mac applications. Acrobat is able to display them. What made me to point to GS is the fact that these annotations are fine before the running of the GS (If I split them using Acrobat or some other tool, they come out readable in Preview) – Dellu Sep 23 '16 at 15:06
  • That sort of sounds like a problem with Preview. However, we know from experience that Acrobat actually ignores appearance streams with annotations and always generates a new appearance. I don't have instant access to a Mac, but I'll try and test this out next week before a forthcoming trip to the US. Otherwise it will have to wait until the week after. – KenS Sep 24 '16 at 12:58
  • As far as I can see there are 2 problems here. Firstly, Ghostscript's pdfwrite device isn't maintaining the annotation as an annotation, its embedding the content into the new PDF file. However, the content is correct. The second problem is that Apple's Preview (I was forced to use OS/X 10.8 but I suspect its common to all) is handling the transparency (which **is** present) incorrectly. In fact it seems to me Preview is ignoring it altogether. We might fix the pdfwrite problem in the future, if someone opens a bug report for it (b'cos I'll forget). I can't find any previous report of this. – KenS Sep 26 '16 at 12:49
  • Preview cannot show the annotation. But, other softwares like Foxtrot and PDF expert are not also able to display it (Adobe can show it; strange behaviour). So, the problem is, as you said, probably at the Ghostscript: or the system at large (MacOS). As for the bug, I can report it. Thank you for the follow up. – Dellu Sep 26 '16 at 12:57
  • hey KenS, is there any progress on gs? – Dellu Dec 06 '16 at 16:28
  • Well, as far as I can see you never opened a bug report. If people don't open bug reports I don't fix problems (because, as I said, I forget, I have a lot to do already). As it happens a customer recently reported (http://bugs.ghostscript.com/show_bug.cgi?id=697309) the annotations not being preserved, so I've recently been working on that. Its a non-trivial problem but I have it partially working. As regards Preview not displaying transparency, I don't really see that as our problem..... – KenS Dec 06 '16 at 16:36
  • OK, I will open a bug report too. I didn't know where to report the bug. – Dellu Dec 06 '16 at 16:51
  • There's no need for a bug report about annotations not staying as annotations, I already have a report for that, and duplicates will just get closed – KenS Dec 06 '16 at 16:55

0 Answers0