Don Lancaster
Don Lancaster

Reputation: 37

Getting Google Drive to output PS link

If I send the usual

/Border [ 0 0 0]                % [0 0 0 ] = none; [0 0 2] = debug 
/Color [ .7 0 0 ]
/Action <</Subtype /URI /URI cururlname>>
/ANN                            % annotation type
pdfmark                         % call pdf operators    
} def

to a PostScript program, Distiller provides the link just fine. Google Drive generates a link free image, as does GhostScript.

How do I get Google Drive to generate a live link or an actual PDF file?

I suspect some non-obvious command line entry is needed.

I'd expect working links both internal to Google Drive and elsewhere on the web on a produced .PDF output.

Upvotes: 0

Views: 96

Answers (1)

KenS
KenS

Reputation: 31199

That doesn't appear to be a complete pdfmark definition. There's no mark and you seem to be missing the Subtype for the annotation (there's a Subtype of URI for the Action but nothing for the annotation), there's also no Rect, which makes it difficult for the consumer to know where to place the annotation....

Eliding the Annotation Subtype causes Ghostscript's pdfwrite device to write it out as a Text annotation (its default). Eliding the Rect, but making the Annotation Subtype /Link, the pdfwrite device emits a Link Annotation, but Acrobat doesn't seem to actually display it anywhere.

If I borrow the example from page 23 of the pdfmark reference version 9 (from 2008, which is the most recent I have) and wrap it up as PostScript:

%!
[ /Rect [50 425 295 445] /Action << /Subtype /URI /URI (http://www.adobe.com) >> /Border [0 0 2] /Color [.7 0 0] /Subtype /Link /ANN pdfmark 

showpage

Then use Ghostscript:

gs -sDEVICE=pdfwrite -o out.pdf test.ps

The resulting file contains an Annot, of type Link, with a URI:

5 0 obj
<</Type/Page/MediaBox [0 0 595 842]
/Parent 3 0 R
/Resources<</ProcSet[/PDF]
/ExtGState 9 0 R
>>
/Annots[4 0 R]/Contents 6 0 R
>>
endobj
...
4 0 obj
<</Type/Annot
/Rect [50 425 295 445]
/Border [0 0 2]
/C [0.7 0 0]
/A<</URI(http://www.adobe.com)
/S/URI>>
/Subtype/Link>>endobj

Which Acrobat correctly displays as a Rectangle, and launches my web browser when I click in it.

Since your example isn't complete, I can't test it, but I can't see a problem here myself.

[EDIT]

Edited to add answers to the comments below, there was too much to write in a commnet:

  1. Your original file, using the same simple Ghostscript command line as in my answer, produces a PDF file with two links, both of which I can click in Acrobat and which launch a browser with the correct URL. So for me, using the current version of Ghostscript, your code works as expected. Perhaps I'm missing something. I've put my output file here

  2. I cannot answer questions relating to Google Drive, I don't use it and don't have any idea how it works. If it converts to PDF then I can't see any reason that wouldn't work as is.

  3. You can't build a Ghostscript command line into a PostScript procedure, or at least, not use it usefully afterwards, that's not how the command line works. Technically you could use setpagedevice to set the device, and OutputFile, you cannot set the input file any way other than the command line, though you could use the run operator. None of that will work if Ghostscript is started in SAFER mode and I would be amazed if Google is using Ghostscript and not using SAFER.

You can use the product operator to distinguish between interpreters, but since it returns a string you would have to write your own string compare to check for Distiller vs Ghostscript. Obviously your code would be executed contingent on the content of the string. Distiller returns (Distiller) and Ghostscript returns (GPL Ghostscript).

[Edit #2]

The Ghostscript command line is, unfortunately a thing of horror :-( No excuses, it's simply that it is an old program, worked on by many developers over the decades, and once something is implemented it's all but impossible to remove, there are howls of protest when that gets attempted.

Which one of the files you link to shouldn't work ? #21 doesn't work for me because it uses hard-coded filenames. If I set want_to_trace to false instead of true it produces a file. Possibly that doesn't 'work' but since I'm not sure what to expect it's hard to tell.

To get the file to work with want_to_trace true, I had to modify all the hard-coded paths in the program. Once I did that, I get a PDF file which has a working link (that is, Acrobat opens my web browser to a file on your site, or would if I were to let it).

You don't say what happens when you try to execute the program, in what way does it fail ? I would guess, personally, that the problem is that Ghostscript is executing in SAFER mode, in which case you won't be able to open the JPEG file, it will throw an invalidaccess error.

Upvotes: 0

Related Questions