Skip to main content
Known Participant
March 17, 2016
Question

Need to print document WITHOUT margins using javascript, please

  • March 17, 2016
  • 1 reply
  • 1451 views

G'day Javascripters.

I really, really need to print without page margins (edge to edge). I'm trying to use Java as the print setter (using Applescript Objective C), and so far it's been successful, but we're getting a 36 point margin around each page, and we want zero on tiled pages.

I'm try to use a java script I found here... remove white margin with javascript (JavaScript) with no success. According to the documentation, margins for printers don't have a setting. I do NOT want to go back to using the GUI with the print dialog, it's much, much slower.

Can anyone tell me please why this does not work? I've tried all sorts of alterations, but just get a 'Can't understand 'do script'' message. Even though I've found the java documentation, I simply don't know what I'm doing!

tell application "Adobe Acrobat"

  activate

  tell page 1 of document 1

  set t to my removePDFMargins

  do script t

  end tell

end tell

on removePDFMargins()

  set Params to ""

  set Params to Params & "function CropPage()" & return

  set Params to Params & "{" & return

  set Params to Params & "console.clear();" & return

  set Params to Params & "console.show();" & return

  set Params to Params & "Media = this.getPageBox(\"" & "Media" & "\");" & return

  set Params to Params & "this.setPageBoxes(\"" & "Media" & "\", 0, 0, Media);" & return

  set Params to Params & "Crop = this.getPageBox(\"" & "Crop" & "\");" & return

  set Params to Params & "this.setPageBoxes(\"" & "Crop" & "\", 0, 0, Crop);" & return

  set Params to Params & "Trim = this.getPageBox(\"" & "Trim" & "\");" & return

  set Params to Params & "this.setPageBoxes(\"" & "Trim" & "\", 0, 0, Trim);" & return

  set Params to Params & "BBox = this.getPageBox(\"" & "BBox" & "\");" & return

  set Params to Params & "this.setPageBoxes(\"" & "Crop" & "\", 0, 0, BBox);" & return

  set Params to Params & "Bleed = this.getPageBox(\"" & "Bleed" & "\");" & return

  set Params to Params & "this.setPageBoxes(\"" & "Bleed" & "\", 0, 0, Bleed);" & return

  set Params to Params & "}" & return

  return Params

end removePDFMargins

This topic has been closed for replies.

1 reply

Legend
March 17, 2016

Are you able to achieve this - edge to edge printing - from the print dialog? If so, what settings do you choose?

The code you posted has nothing to do with printing.

OzSanta2Author
Known Participant
March 17, 2016

No, not really edge to edge, just very narrow margins, simply by choosing the printer called 'Large Page Printer'.

However, calling this printer from JavaScript adds 1/2" margins for some reason, that's why I thought reducing the margins to 0 might help.

BTW, what is the 'console' and it's role?

Regards

Brian Christmas

Inspiring
March 17, 2016

The JavaScript console is for developers to develop and debug scripts to be used within a PDF. It is also possible to create lists in the console using Adobe Reader or Acrobat and then cut and paste the data into other applications.