Create printJob for a printerShare
Article
05/11/2023
5 contributors
Feedback
In this article
Namespace: microsoft.graph
Create a new printJob for a printerShare .
Also creates a new printDocument associated with the printJob.
Note: A user can submit up to ~10000 print jobs in 10 days.
Permissions
One of the following permissions is required to call this API. To learn more, including how to choose permissions, see Permissions .
In addition to the following permissions, the user or app's tenant must have an active Universal Print subscription and have a permission that grants Get printerShare access.
Permission type
Permissions (from least to most privileged)
Delegated (work or school account)
PrintJob.ReadWriteBasic, PrintJob.ReadWrite, PrintJob.ReadWriteBasic.All, PrintJob.ReadWrite.All
Delegated (personal Microsoft account)
Not Supported.
Application
Not Supported.
HTTP request
POST /print/shares/{printerShareId}/jobs
Name
Description
Authorization
Bearer {token}. Required.
Content-Type
application/json. Required.
Request body
In the request body, supply a JSON representation of a printJob object. The printJob object should only contain configuration property. All properties of configuration are nullable. All other fields, including job and document IDs, are set automatically during resource creation and should not be provided in request.
Right now, Universal Print supports only one printDocument per printJob object.
Response
If successful, this method returns a 201 Created
response code and a printJob object and associated printDocument in the response body.
Examples
Request
POST https://graph.microsoft.com/v1.0/print/shares/{printerShareId}/jobs
Content-Type: application/json
{
"configuration": {
"feedOrientation": "longEdgeFirst",
"pageRanges": [
{
"start": 1,
"end": 1
}
],
"quality": "medium",
"dpi": 600,
"orientation": "landscape",
"copies": 1,
"duplexMode": "oneSided",
"colorMode": "blackAndWhite",
"inputBin": "by-pass-tray",
"outputBin": "output-tray",
"mediaSize": "A4",
"margin": {
"top": 0,
"bottom": 0,
"left": 0,
"right": 0
},
"mediaType": "stationery",
"finishings": null,
"pagesPerSheet": 1,
"multipageLayout": "clockwiseFromBottomLeft",
"collate": false,
"scaling": "shrinkToFit",
"fitPdfToPage": false
}
}
// Code snippets are only available for the latest version. Current version is 5.x
var graphClient = new GraphServiceClient(requestAdapter);
var requestBody = new PrintJob
{
Configuration = new PrintJobConfiguration
{
FeedOrientation = PrinterFeedOrientation.LongEdgeFirst,
PageRanges = new List<IntegerRange>
{
new IntegerRange
{
Start = 1L,
End = 1L,
},
},
Quality = PrintQuality.Medium,
Dpi = 600,
Orientation = PrintOrientation.Landscape,
Copies = 1,
DuplexMode = PrintDuplexMode.OneSided,
ColorMode = PrintColorMode.BlackAndWhite,
InputBin = "by-pass-tray",
OutputBin = "output-tray",
MediaSize = "A4",
Margin = new PrintMargin
{
Top = 0,
Bottom = 0,
Left = 0,
Right = 0,
},
MediaType = "stationery",
Finishings = null,
PagesPerSheet = 1,
MultipageLayout = PrintMultipageLayout.ClockwiseFromBottomLeft,
Collate = false,
Scaling = PrintScaling.ShrinkToFit,
FitPdfToPage = false,
},
};
var result = await graphClient.Print.Shares["{printerShare-id}"].Jobs.PostAsync(requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
import (
"context"
msgraphsdk "github.com/microsoftgraph/msgraph-sdk-go"
graphmodels "github.com/microsoftgraph/msgraph-sdk-go/models"
//other-imports
)
graphClient := msgraphsdk.NewGraphServiceClientWithCredentials(cred, scopes)
requestBody := graphmodels.NewPrintJob()
configuration := graphmodels.NewPrintJobConfiguration()
feedOrientation := graphmodels.LONGEDGEFIRST_PRINTERFEEDORIENTATION
configuration.SetFeedOrientation(&feedOrientation)
integerRange := graphmodels.NewIntegerRange()
start := int64(1)
integerRange.SetStart(&start)
end := int64(1)
integerRange.SetEnd(&end)
pageRanges := []graphmodels.IntegerRangeable {
integerRange,
}
configuration.SetPageRanges(pageRanges)
quality := graphmodels.MEDIUM_PRINTQUALITY
configuration.SetQuality(&quality)
dpi := int32(600)
configuration.SetDpi(&dpi)
orientation := graphmodels.LANDSCAPE_PRINTORIENTATION
configuration.SetOrientation(&orientation)
copies := int32(1)
configuration.SetCopies(&copies)
duplexMode := graphmodels.ONESIDED_PRINTDUPLEXMODE
configuration.SetDuplexMode(&duplexMode)
colorMode := graphmodels.BLACKANDWHITE_PRINTCOLORMODE
configuration.SetColorMode(&colorMode)
inputBin := "by-pass-tray"
configuration.SetInputBin(&inputBin)
outputBin := "output-tray"
configuration.SetOutputBin(&outputBin)
mediaSize := "A4"
configuration.SetMediaSize(&mediaSize)
margin := graphmodels.NewPrintMargin()
top := int32(0)
margin.SetTop(&top)
bottom := int32(0)
margin.SetBottom(&bottom)
left := int32(0)
margin.SetLeft(&left)
right := int32(0)
margin.SetRight(&right)
configuration.SetMargin(margin)
mediaType := "stationery"
configuration.SetMediaType(&mediaType)
finishings := null
configuration.SetFinishings(&finishings)
pagesPerSheet := int32(1)
configuration.SetPagesPerSheet(&pagesPerSheet)
multipageLayout := graphmodels.CLOCKWISEFROMBOTTOMLEFT_PRINTMULTIPAGELAYOUT
configuration.SetMultipageLayout(&multipageLayout)
collate := false
configuration.SetCollate(&collate)
scaling := graphmodels.SHRINKTOFIT_PRINTSCALING
configuration.SetScaling(&scaling)
fitPdfToPage := false
configuration.SetFitPdfToPage(&fitPdfToPage)
requestBody.SetConfiguration(configuration)
result, err := graphClient.Print().Shares().ByShareId("printerShare-id").Jobs().Post(context.Background(), requestBody, nil)
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
GraphServiceClient graphClient = GraphServiceClient.builder().authenticationProvider( authProvider ).buildClient();
PrintJob printJob = new PrintJob();
PrintJobConfiguration configuration = new PrintJobConfiguration();
configuration.feedOrientation = PrinterFeedOrientation.LONG_EDGE_FIRST;
LinkedList<IntegerRange> pageRangesList = new LinkedList<IntegerRange>();
IntegerRange pageRanges = new IntegerRange();
pageRanges.start = 1L;
pageRanges.end = 1L;
pageRangesList.add(pageRanges);
configuration.pageRanges = pageRangesList;
configuration.quality = PrintQuality.MEDIUM;
configuration.dpi = 600;
configuration.orientation = PrintOrientation.LANDSCAPE;
configuration.copies = 1;
configuration.duplexMode = PrintDuplexMode.ONE_SIDED;
configuration.colorMode = PrintColorMode.BLACK_AND_WHITE;
configuration.inputBin = "by-pass-tray";
configuration.outputBin = "output-tray";
configuration.mediaSize = "A4";
PrintMargin margin = new PrintMargin();
margin.top = 0;
margin.bottom = 0;
margin.left = 0;
margin.right = 0;
configuration.margin = margin;
configuration.mediaType = "stationery";
configuration.finishings = null;
configuration.pagesPerSheet = 1;
configuration.multipageLayout = PrintMultipageLayout.CLOCKWISE_FROM_BOTTOM_LEFT;
configuration.collate = false;
configuration.scaling = PrintScaling.SHRINK_TO_FIT;
configuration.fitPdfToPage = false;
printJob.configuration = configuration;
graphClient.print().shares("{printerShareId}").jobs()
.buildRequest()
.post(printJob);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
const options = {
authProvider,
};
const client = Client.init(options);
const printJob = {
configuration: {
feedOrientation: 'longEdgeFirst',
pageRanges: [
{
start: 1,
end: 1
}
],
quality: 'medium',
dpi: 600,
orientation: 'landscape',
copies: 1,
duplexMode: 'oneSided',
colorMode: 'blackAndWhite',
inputBin: 'by-pass-tray',
outputBin: 'output-tray',
mediaSize: 'A4',
margin: {
top: 0,
bottom: 0,
left: 0,
right: 0
},
mediaType: 'stationery',
finishings: null,
pagesPerSheet: 1,
multipageLayout: 'clockwiseFromBottomLeft',
collate: false,
scaling: 'shrinkToFit',
fitPdfToPage: false
}
};
await client.api('/print/shares/{printerShareId}/jobs')
.post(printJob);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
<?php
// THIS SNIPPET IS A PREVIEW FOR THE KIOTA BASED SDK. NON-PRODUCTION USE ONLY
$graphServiceClient = new GraphServiceClient($requestAdapter);
$requestBody = new PrintJob();
$configuration = new PrintJobConfiguration();
$configuration->setFeedOrientation(new PrinterFeedOrientation('longedgefirst'));
$pageRangesIntegerRange1 = new IntegerRange();
$pageRangesIntegerRange1->setStart(1);
$pageRangesIntegerRange1->setEnd(1);
$pageRangesArray []= $pageRangesIntegerRange1;
$configuration->setPageRanges($pageRangesArray);
$configuration->setQuality(new PrintQuality('medium'));
$configuration->setDpi(600);
$configuration->setOrientation(new PrintOrientation('landscape'));
$configuration->setCopies(1);
$configuration->setDuplexMode(new PrintDuplexMode('onesided'));
$configuration->setColorMode(new PrintColorMode('blackandwhite'));
$configuration->setInputBin('by-pass-tray');
$configuration->setOutputBin('output-tray');
$configuration->setMediaSize('A4');
$configurationMargin = new PrintMargin();
$configurationMargin->setTop(0);
$configurationMargin->setBottom(0);
$configurationMargin->setLeft(0);
$configurationMargin->setRight(0);
$configuration->setMargin($configurationMargin);
$configuration->setMediaType('stationery');
$Configuration->setFinishings(null);
$configuration->setPagesPerSheet(1);
$configuration->setMultipageLayout(new PrintMultipageLayout('clockwisefrombottomleft'));
$configuration->setCollate(false);
$configuration->setScaling(new PrintScaling('shrinktofit'));
$configuration->setFitPdfToPage(false);
$requestBody->setConfiguration($configuration);
$result = $graphServiceClient->print()->shares()->byShareId('printerShare-id')->jobs()->post($requestBody);
For details about how to add the SDK to your project and create an authProvider instance, see the SDK documentation .
Response
Note: The response object shown here might be shortened for readability.
HTTP/1.1 201 Created
Content-Type: application/json
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#print/printJobs/$entity",
"id": "1825",
"createdDateTime": "2020-10-14T05:16:49-07:00",
"isFetchable": false,
"redirectedFrom": null,
"redirectedTo": null,
"createdBy": {
"id": "{userId}",
"displayName": "{username}",
"ipAddress": null,
"userPrincipalName": "{userupn}"
},
"status": {
"state": "paused",
"description": "The job is not a candidate for processing yet.",
"isAcquiredByPrinter": false,
"details": [
"uploadPending"
]
},
"configuration": {
"quality": "medium",
"dpi": 600,
"feedOrientation": "longEdgeFirst",
"orientation": "landscape",
"duplexMode": "oneSided",
"copies": 1,
"colorMode": "blackAndWhite",
"inputBin": "by-pass-tray",
"outputBin": "output-tray",
"mediaSize": "A4",
"mediaType": "stationery",
"finishings": null,
"pagesPerSheet": 1,
"multipageLayout": "clockwiseFromBottomLeft",
"collate": false,
"scaling": "shrinkToFit",
"fitPdfToPage": false,
"pageRanges": [
{
"start": 1,
"end": 1
}
],
"margin": {
"top": 0,
"bottom": 0,
"left": 0,
"right": 0
}
},
"documents": [
{
"id": "1477576d-5dab-4ea9-865c-c0b82cd70bd5",
"displayName": "",
"contentType": "",
"size": 0
}
]
}