public void SubmitPrint(GoogleCloudPrintClient client) { // Create a cloud job ticket first, it contains the printer setting of the document var cjt = new CloudJobTicket { Print = new PrintTicketSection { Color = new ColorTicketItem { Type = Color.Type.STANDARD_MONOCHROME }, Duplex = new DuplexTicketItem { Type = Duplex.Type.LONG_EDGE }, PageOrientation = new PageOrientationTicketItem { Type = PageOrientation.Type.LANDSCAPE }, Copies = new CopiesTicketItem { Copies = 1 } } }; // Create a request for file submission, you can either submit a url with SubmitFileLink class, or a local file with SubmitFileStream class var request = new SubmitRequest { PrinterId = "d08832da-03e4-a068-885b-46ea9750f3eb", Title = "teste", Ticket = cjt, Content = new SubmitFileLink("https://image.slidesharecdn.com/teste-140108070830-phpapp02/95/folha-de-teste-1-638.jpg?cb=1389164960") // or new SubmitFileStream(contentType, fileName, fileStream) }; // Submit request var response = client.SubmitJobAsync(request).Result; }
static async Task Main(string[] args) { var clientId = "#printClientId#"; var clientSecret = "#printClientSecret#"; var printerId = "#printer-id#"; var credPath = $"cerd.json"; var provider = new GoogleCloudPrintOAuth2Provider(clientId, clientSecret); var jsonString = System.IO.File.ReadAllText(credPath); Token token = JsonConvert.DeserializeObject <Token>(jsonString); var client = new GoogleCloudPrintClient(provider, token); client.OnTokenUpdated += (sender, e) => { string json = JsonConvert.SerializeObject(e); System.IO.File.WriteAllText(credPath, json); }; var ticket = new CloudJobTicket { Print = new PrintTicketSection { Color = new ColorTicketItem { Type = Color.Type.STANDARD_MONOCHROME }, //Duplex = new DuplexTicketItem { Type = Duplex.Type.LONG_EDGE }, PageOrientation = new PageOrientationTicketItem { Type = PageOrientation.Type.LANDSCAPE }, Copies = new CopiesTicketItem { Copies = 1 } } }; // Create a request for file submission, you can either submit a url with SubmitFileLink class, or a local file with SubmitFileStream class var request = new SubmitRequest { PrinterId = printerId, Title = "Ebay-Printer", Ticket = ticket, Content = new SubmitFileLink("URL HERE") }; // Submit request var response = await client.SubmitJobAsync(request); }
private static void SubmitJob() { var client = new GoogleCloudPrintClient(provider, token); var listRequest = new ListRequest { Proxy = proxy }; var listResponse = client.ListPrinterAsync(listRequest).Result; if (listResponse.Printers != null && listResponse.Printers.Any()) { for (int i = 0; i < listResponse.Printers.Count; i++) { Console.WriteLine($"{i + 1}. {listResponse.Printers.ElementAt(i).DisplayName}"); } int printerOption = -1; Console.Write("Please choose a printer to submit job: "); if (int.TryParse(Console.ReadLine(), out printerOption)) { var printer = listResponse.Printers.ElementAt(printerOption - 1); var printerRequest = new PrinterRequest { PrinterId = printer.Id }; var printerResponse = client.GetPrinterAsync(printerRequest).Result; if (printerResponse.Printers != null && printerResponse.Printers.Any()) { Console.Write("Do you print from Url or a local document? (Y: Url, N: Local Document)"); bool isUrl = Console.ReadLine().ToLower().Contains("y"); Console.WriteLine("Please enter the path to the url/ the local document"); string path = Console.ReadLine(); var cjt = new CloudJobTicket { Print = new PrintTicketSection { Color = new ColorTicketItem { Type = Color.Type.STANDARD_MONOCHROME }, Duplex = new DuplexTicketItem { Type = Duplex.Type.LONG_EDGE }, PageOrientation = new PageOrientationTicketItem() { Type = PageOrientation.Type.LANDSCAPE }, Copies = new CopiesTicketItem() { Copies = 3 } } }; JobResponse <SubmitRequest> response; if (isUrl) { var request = new SubmitRequest { PrinterId = printer.Id, Title = Guid.NewGuid().ToString(), Ticket = cjt, Content = new SubmitFileLink(path) }; response = client.SubmitJobAsync(request).Result; } else { using (var s = File.Open(path, FileMode.Open)) { var request = new SubmitRequest() { PrinterId = printer.Id, Title = Path.GetFileNameWithoutExtension(path), Ticket = cjt, Content = new SubmitFileStream("text/plain", path, s) }; response = client.SubmitJobAsync(request).Result; } } Console.WriteLine("Success: {0}", response.Success); } else { Console.WriteLine("No relevant printer is found."); } } } else { Console.WriteLine("There is no printer in the list"); } }