3

I'm trying to write a program that prints only the first page of a document using Google Cloud Print. I have gotten all parameters to work except for page_range and cannot decipher the Developer Guide on this matter. Is anyone able to tell me what's wrong with the format that I am using for page_range? I am using a JavaScript List

var ticket = {
 version: "1.0",
 print: {
  color: {
    type: "STANDARD_COLOR",
    vendor_id: "Color"
  },
  duplex: {
    type: "NO_DUPLEX"
  },
  copies: {copies: 1},
  media_size: {
     width_microns: 27940,
     height_microns:60960
  },
  page_orientation: {
    type: "LANDSCAPE"  
  },
   margins: {
     top_microns:0,
     bottom_microns:0,
     left_microns:0,
     right_microns:0
  },
  page_range: {
    interval: {
      start:1,
      end:1
    }
  }
 }
};
user2970721
  • 146
  • 10

2 Answers2

1

page_range contains a repeated field named interval. It's repeated so that you can request multiple ranges:

// Ticket item indicating what pages to use.
message PageRangeTicketItem {
  repeated PageRange.Interval interval = 1;
}

PageRange.Interval looks like this:

// Interval of pages in the document to print.
message Interval {
  // Beginning of the interval (inclusive) (required).
  optional int32 start = 1;

  // End of the interval (inclusive). If not set, then the interval will
  // include all available pages after start.
  optional int32 end = 2;
}

So try this to print pages 1 and 6-7:

page_range: {
  interval: [
    {
      start: 1,
      end: 1
    },
    {
      start: 6,
      end: 7
    }
  ]
}
Jacob Marble
  • 28,555
  • 22
  • 67
  • 78
  • Thanks! I'll give this a try tomorrow :) That makes sense. – user2970721 Dec 17 '15 at 04:15
  • As a side note, welcome to Stack Overflow! If my answer has a typo, or if I missed anything, then you can edit it yourself, or we can continue to chat here in the comments. If my answer turns out to be a solution for you, then click the check mark to the left of the answer. – Jacob Marble Dec 17 '15 at 06:38
  • Worked like a charm. Thank you again. – user2970721 Dec 17 '15 at 14:51
1

I recommend you to use this way

page_range: { interval: [ { start: 1, end: 7 } ] }

AhammadaliPK
  • 3,448
  • 4
  • 21
  • 39