You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@guacamole.apache.org by Amarjeet Singh <am...@gmail.com> on 2017/11/15 14:48:07 UTC

INFO : Print automatically by appending string in Ghostscript

Hi Team,


I want to automatically print the PDF by appending the following string  in
the input_stream before *ghost script *command executes and generate pdf in
output_stream.

String : -

%AUTOPRINT[ /_objdef {PrintAction} /type /dict /OBJ pdfmark[
{PrintAction} << /Type /Action /S /Named /N /Print >> /PUT pdfmark[
{Catalog} << /OpenAction {PrintAction} >> /PUT pdfmark

If I append it in file.ps and then run gs script then it works and
file.pdf automatically print the PDF but I cannot do that with
guacamole as gs is sending output as stream with "-sOutputFile=-" and

taking input from input_stream.

gs -q -dNOPAUSE -dBATCH -dSAFER -dPARANOIDSAFER -sDEVICE=pdfwrite
-sOutputFile=file.pdf -c .setpdfwrite -f  file.ps

Will it work if I append the above string in the buffer ?   //

void guac_rdpdr_process_print_job_write(guac_rdpdr_device* device,
        wStream* input_stream, int completion_id) {

    guac_client* client = device->rdpdr->client;
    guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
    guac_rdp_print_job* job = (guac_rdp_print_job*) rdp_client->active_job;

    unsigned char* buffer;
    int length;
    int status;

    /* Read buffer of print data */
    Stream_Read_UINT32(input_stream, length);
    Stream_Seek(input_stream, 8);  /* Offset */
    Stream_Seek(input_stream, 20); /* Padding */
   * buffer = Stream_Pointer(input_stream);*

    /* Write data only if job exists, translating status for RDP */
    if (job != NULL && (length = guac_rdp_print_job_write(job,
                    buffer, length)) >= 0) {
        status = STATUS_SUCCESS;
    }

    /* Report device offline if write fails */
    else {
        status = STATUS_DEVICE_OFF_LINE;
        length = 0;
    }

    wStream* output_stream = guac_rdpdr_new_io_completion(device,
            completion_id, status, 5);

    Stream_Write_UINT32(output_stream, length);
    Stream_Write_UINT8(output_stream, 0); /* Padding */

    svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream);

}

What are the options I have if I want to achieve the above ? Is there
anything  else I can do to append it ?

Thanks and Regards,

Amarjeet Singh

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
Browsers which  lacks PDF Viewer, I need to show a download link and a
message that "PDF viewer is not installed or install PDF viewer " to the
user.

I will be working on that.

On Mon, Dec 11, 2017 at 11:42 AM, Amarjeet Singh <am...@gmail.com>
wrote:

> I have tested it  in Edge, Chrome, Firefox and IE .
>
> Adobe Acrobat Reader is required in the client machine to view it in
> iframe which lacks inbuilt PDF Viewer ( only in Internet Explorer )
>
>
>
> On Mon, Dec 11, 2017 at 10:58 AM, Mike Jumper <mi...@guac-dev.org>
> wrote:
>
>> On Dec 10, 2017 21:07, "Amarjeet Singh" <am...@gmail.com> wrote:
>>
>> Thanks Mike.
>>
>> I have done that. I have appended the name action.
>> Now, It automatically opens the print menu of the browser when we click on
>> Guacamole Printer to print documents instead of downloading the documents.
>>
>> Finally did it :)
>>
>>
>> How is the behavior across browsers, particularly browsers which lack a
>> PDF
>> viewer?
>>
>> - Mike
>>
>
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Mike Jumper <mi...@guac-dev.org>.
Sounds good. Thanks, Amarjeet.

- Mike


On Thu, Mar 15, 2018 at 1:17 AM, Amarjeet Singh <am...@gmail.com>
wrote:

> I will look into it and if I will find anything I will update the same in
> the thread.
>
> I want to give it a shot.
>
>
>
>
> On Thu, Mar 15, 2018 at 1:41 PM, Mike Jumper <mi...@guac-dev.org>
> wrote:
>
> > On Thu, Mar 15, 2018 at 1:03 AM, Amarjeet Singh <am...@gmail.com>
> > wrote:
> >
> > > ...
> > > *Any Suggestions how to check if browser has inbuilt pdf viewer or
> > whether
> > > it will open pdf file in an iframe *
> > >
> > >
> > As far as I know, it is not possible to determine whether the browser
> has a
> > built-in PDF viewer, or more generally, whether an attempt to open a PDF
> > within an iframe will succeed. I actually looked into streamlining
> printing
> > as you describe toward the end of 2016, and this issue was primary reason
> > that I gave up on the concept as impossible. If this situation hasn't
> > changed since then (it sounds like it hasn't), then we may still be out
> of
> > luck.
> >
> > - Mike
> >
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
I will look into it and if I will find anything I will update the same in
the thread.

I want to give it a shot.




On Thu, Mar 15, 2018 at 1:41 PM, Mike Jumper <mi...@guac-dev.org>
wrote:

> On Thu, Mar 15, 2018 at 1:03 AM, Amarjeet Singh <am...@gmail.com>
> wrote:
>
> > ...
> > *Any Suggestions how to check if browser has inbuilt pdf viewer or
> whether
> > it will open pdf file in an iframe *
> >
> >
> As far as I know, it is not possible to determine whether the browser has a
> built-in PDF viewer, or more generally, whether an attempt to open a PDF
> within an iframe will succeed. I actually looked into streamlining printing
> as you describe toward the end of 2016, and this issue was primary reason
> that I gave up on the concept as impossible. If this situation hasn't
> changed since then (it sounds like it hasn't), then we may still be out of
> luck.
>
> - Mike
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Mike Jumper <mi...@guac-dev.org>.
On Thu, Mar 15, 2018 at 1:03 AM, Amarjeet Singh <am...@gmail.com>
wrote:

> ...
> *Any Suggestions how to check if browser has inbuilt pdf viewer or whether
> it will open pdf file in an iframe *
>
>
As far as I know, it is not possible to determine whether the browser has a
built-in PDF viewer, or more generally, whether an attempt to open a PDF
within an iframe will succeed. I actually looked into streamlining printing
as you describe toward the end of 2016, and this issue was primary reason
that I gave up on the concept as impossible. If this situation hasn't
changed since then (it sounds like it hasn't), then we may still be out of
luck.

- Mike

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
It works if browser has the inbuilt pdf viewer or local machine has pdf
viewer installed.

Print preview in an iframe works in chrome and firefox  ( as they have
inbuilt PDF Viewer )
IE needs local PDF viewer otherwise it will show the blank pop-up ( iframe
) and download it.

I will contribute. I need to look into the issue and check if browser
doesn't have inbuilt pdf viewer it automatically downloads instead showing
blank iframe pop-up.

*Any Suggestions how to check if browser has inbuilt pdf viewer or whether
it will open pdf file in an iframe *

Regards,
Amarjeet SIngh

On Thu, Mar 15, 2018 at 1:01 PM, Mike Jumper <mi...@guac-dev.org>
wrote:

> Amarjeet, have you been able to get this to work? Is this something you are
> looking to contribute?
>
> - Mike
>
>
> On Sun, Jan 7, 2018 at 10:39 AM, Amarjeet Singh <am...@gmail.com>
> wrote:
>
> > Sorry for the late reply.
> > Haven't tested yet.
> > Now I have tested it and if adobe reader is not installed then it
> > automatically downloads the file ( which was default behavior of
> Guacamole
> > ).
> > But if adobe is there in the machine then it automatically open the print
> > menu of the browser.
> >
> > On Dec 11, 2017 11:45 AM, "Mike Jumper" <mi...@guac-dev.org>
> wrote:
> >
> > > On Dec 10, 2017 22:12, "Amarjeet Singh" <am...@gmail.com> wrote:
> > >
> > > I have tested it  in Edge, Chrome, Firefox and IE .
> > >
> > > Adobe Acrobat Reader is required in the client machine to view it in
> > iframe
> > > which lacks inbuilt PDF Viewer ( only in Internet Explorer )
> > >
> > >
> > > And if the user lacks a PDF viewer, what happens?
> > >
> >
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Mike Jumper <mi...@guac-dev.org>.
Amarjeet, have you been able to get this to work? Is this something you are
looking to contribute?

- Mike


On Sun, Jan 7, 2018 at 10:39 AM, Amarjeet Singh <am...@gmail.com>
wrote:

> Sorry for the late reply.
> Haven't tested yet.
> Now I have tested it and if adobe reader is not installed then it
> automatically downloads the file ( which was default behavior of Guacamole
> ).
> But if adobe is there in the machine then it automatically open the print
> menu of the browser.
>
> On Dec 11, 2017 11:45 AM, "Mike Jumper" <mi...@guac-dev.org> wrote:
>
> > On Dec 10, 2017 22:12, "Amarjeet Singh" <am...@gmail.com> wrote:
> >
> > I have tested it  in Edge, Chrome, Firefox and IE .
> >
> > Adobe Acrobat Reader is required in the client machine to view it in
> iframe
> > which lacks inbuilt PDF Viewer ( only in Internet Explorer )
> >
> >
> > And if the user lacks a PDF viewer, what happens?
> >
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
Sorry for the late reply.
Haven't tested yet.
Now I have tested it and if adobe reader is not installed then it
automatically downloads the file ( which was default behavior of Guacamole
).
But if adobe is there in the machine then it automatically open the print
menu of the browser.

On Dec 11, 2017 11:45 AM, "Mike Jumper" <mi...@guac-dev.org> wrote:

> On Dec 10, 2017 22:12, "Amarjeet Singh" <am...@gmail.com> wrote:
>
> I have tested it  in Edge, Chrome, Firefox and IE .
>
> Adobe Acrobat Reader is required in the client machine to view it in iframe
> which lacks inbuilt PDF Viewer ( only in Internet Explorer )
>
>
> And if the user lacks a PDF viewer, what happens?
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Mike Jumper <mi...@guac-dev.org>.
On Dec 10, 2017 22:12, "Amarjeet Singh" <am...@gmail.com> wrote:

I have tested it  in Edge, Chrome, Firefox and IE .

Adobe Acrobat Reader is required in the client machine to view it in iframe
which lacks inbuilt PDF Viewer ( only in Internet Explorer )


And if the user lacks a PDF viewer, what happens?

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
I have tested it  in Edge, Chrome, Firefox and IE .

Adobe Acrobat Reader is required in the client machine to view it in iframe
which lacks inbuilt PDF Viewer ( only in Internet Explorer )



On Mon, Dec 11, 2017 at 10:58 AM, Mike Jumper <mi...@guac-dev.org>
wrote:

> On Dec 10, 2017 21:07, "Amarjeet Singh" <am...@gmail.com> wrote:
>
> Thanks Mike.
>
> I have done that. I have appended the name action.
> Now, It automatically opens the print menu of the browser when we click on
> Guacamole Printer to print documents instead of downloading the documents.
>
> Finally did it :)
>
>
> How is the behavior across browsers, particularly browsers which lack a PDF
> viewer?
>
> - Mike
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Mike Jumper <mi...@guac-dev.org>.
On Dec 10, 2017 21:07, "Amarjeet Singh" <am...@gmail.com> wrote:

Thanks Mike.

I have done that. I have appended the name action.
Now, It automatically opens the print menu of the browser when we click on
Guacamole Printer to print documents instead of downloading the documents.

Finally did it :)


How is the behavior across browsers, particularly browsers which lack a PDF
viewer?

- Mike

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
Thanks Mike.

I have done that. I have appended the name action.
Now, It automatically opens the print menu of the browser when we click on
Guacamole Printer to print documents instead of downloading the documents.

Finally did it :)


On Dec 10, 2017 19:32, "Amarjeet Singh" <am...@gmail.com> wrote:

> Thanks Mike.
>
> How to know whether it's a last block or not?
>
> On Sun, Dec 10, 2017 at 1:09 PM, Mike Jumper <mi...@guac-dev.org>
> wrote:
>
>> On Sat, Dec 9, 2017 at 10:02 PM, Amarjeet Singh <am...@gmail.com>
>> wrote:
>>
>> > I want to append the Print Named Action in the same PostScript file
>> that is
>> > being received  via RDP to the file descriptor.
>> >
>>
>> To append, you would write() your PostScript immediately prior to closing
>> the file descriptor to the GhostScript process, after the last block of
>> data from RDP has been received and written to that same file descriptor.
>>
>> - Mike
>>
>
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
Thanks Mike.

How to know whether it's a last block or not?

On Sun, Dec 10, 2017 at 1:09 PM, Mike Jumper <mi...@guac-dev.org>
wrote:

> On Sat, Dec 9, 2017 at 10:02 PM, Amarjeet Singh <am...@gmail.com>
> wrote:
>
> > I want to append the Print Named Action in the same PostScript file that
> is
> > being received  via RDP to the file descriptor.
> >
>
> To append, you would write() your PostScript immediately prior to closing
> the file descriptor to the GhostScript process, after the last block of
> data from RDP has been received and written to that same file descriptor.
>
> - Mike
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Mike Jumper <mi...@guac-dev.org>.
On Sat, Dec 9, 2017 at 10:02 PM, Amarjeet Singh <am...@gmail.com>
wrote:

> I want to append the Print Named Action in the same PostScript file that is
> being received  via RDP to the file descriptor.
>

To append, you would write() your PostScript immediately prior to closing
the file descriptor to the GhostScript process, after the last block of
data from RDP has been received and written to that same file descriptor.

- Mike

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
I want to append the Print Named Action in the same PostScript file that is
being received  via RDP to the file descriptor.

I want to append at its end to automatically open the pdf.

https://stackoverflow.com/a/11305061

<goog_604726844>
https://www.gnostice.com/nl_article.asp?id=157&t=Create_an_Auto_Print_PDF


On Sun, Dec 10, 2017 at 5:30 AM, Mike Jumper <mi...@guac-dev.org>
wrote:

> On Sat, Dec 9, 2017 at 12:07 PM, Amarjeet Singh <am...@gmail.com>
> wrote:
>
> > How can I append  print named action in the post script file  before
> > ghostscript converts it into pdf ?
> >
> >
> The GhostScript process created to handle each print job reads its input
> from a pipe, while the Guacamole side of that process writes all data
> received via RDP to the file descriptor on its end of the pipe:
>
> https://github.com/apache/guacamole-server/blob/
> f72de10328ae39fcbf067333b0c2a2c9aecc441b/src/protocols/rdp/
> rdp_print_job.c#L623-L624
>
> If you want to insert arbitrary PostScript before the PostScript received
> from RDP, you would need to write() your PostScript before any of the data
> received from RDP is written but after the initial "file" instruction is
> sent, taking care to retry the write() in case GhostScript cannot read
> everything written at once.
>
> - Mike
>

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Mike Jumper <mi...@guac-dev.org>.
On Sat, Dec 9, 2017 at 12:07 PM, Amarjeet Singh <am...@gmail.com>
wrote:

> How can I append  print named action in the post script file  before
> ghostscript converts it into pdf ?
>
>
The GhostScript process created to handle each print job reads its input
from a pipe, while the Guacamole side of that process writes all data
received via RDP to the file descriptor on its end of the pipe:

https://github.com/apache/guacamole-server/blob/f72de10328ae39fcbf067333b0c2a2c9aecc441b/src/protocols/rdp/rdp_print_job.c#L623-L624

If you want to insert arbitrary PostScript before the PostScript received
from RDP, you would need to write() your PostScript before any of the data
received from RDP is written but after the initial "file" instruction is
sent, taking care to retry the write() in case GhostScript cannot read
everything written at once.

- Mike

Re: INFO : Print automatically by appending string in Ghostscript

Posted by Amarjeet Singh <am...@gmail.com>.
How can I append  print named action in the post script file  before
ghostscript converts it into pdf ?



On Wed, Nov 15, 2017 at 8:18 PM, Amarjeet Singh <am...@gmail.com>
wrote:

> Hi Team,
>
>
> I want to automatically print the PDF by appending the following string
> in the input_stream before *ghost script *command executes and generate
> pdf in output_stream.
>
> String : -
>
> %AUTOPRINT[ /_objdef {PrintAction} /type /dict /OBJ pdfmark[ {PrintAction} << /Type /Action /S /Named /N /Print >> /PUT pdfmark[ {Catalog} << /OpenAction {PrintAction} >> /PUT pdfmark
>
> If I append it in file.ps and then run gs script then it works and file.pdf automatically print the PDF but I cannot do that with guacamole as gs is sending output as stream with "-sOutputFile=-" and
>
> taking input from input_stream.
>
> gs -q -dNOPAUSE -dBATCH -dSAFER -dPARANOIDSAFER -sDEVICE=pdfwrite -sOutputFile=file.pdf -c .setpdfwrite -f  file.ps
>
> Will it work if I append the above string in the buffer ?   //
>
> void guac_rdpdr_process_print_job_write(guac_rdpdr_device* device,
>         wStream* input_stream, int completion_id) {
>
>     guac_client* client = device->rdpdr->client;
>     guac_rdp_client* rdp_client = (guac_rdp_client*) client->data;
>     guac_rdp_print_job* job = (guac_rdp_print_job*) rdp_client->active_job;
>
>     unsigned char* buffer;
>     int length;
>     int status;
>
>     /* Read buffer of print data */
>     Stream_Read_UINT32(input_stream, length);
>     Stream_Seek(input_stream, 8);  /* Offset */
>     Stream_Seek(input_stream, 20); /* Padding */
>    * buffer = Stream_Pointer(input_stream);*
>
>     /* Write data only if job exists, translating status for RDP */
>     if (job != NULL && (length = guac_rdp_print_job_write(job,
>                     buffer, length)) >= 0) {
>         status = STATUS_SUCCESS;
>     }
>
>     /* Report device offline if write fails */
>     else {
>         status = STATUS_DEVICE_OFF_LINE;
>         length = 0;
>     }
>
>     wStream* output_stream = guac_rdpdr_new_io_completion(device,
>             completion_id, status, 5);
>
>     Stream_Write_UINT32(output_stream, length);
>     Stream_Write_UINT8(output_stream, 0); /* Padding */
>
>     svc_plugin_send((rdpSvcPlugin*) device->rdpdr, output_stream);
>
> }
>
> What are the options I have if I want to achieve the above ? Is there anything  else I can do to append it ?
>
> Thanks and Regards,
>
> Amarjeet Singh
>
>