PM> Install-Package SharpIpp · MIT · 50 звёзд
Исходники на GitHub
Реализация Internet Printing Protocol/1.1 и кусочков CUPS 1.0 на C#. Она печатает! И делает всякое другое с любым принтером, доступным по сети.
Лежит на nuget
PM> Install-Package SharpIpp
await using var stream = File.Open(@"c:\file.pdf", FileMode.Open);
var printerUri = new Uri("ipp://192.168.0.1:631");
var request = new PrintJobRequest
{
PrinterUri = printer,
Document = stream,
JobName = "Test Job",
IppAttributeFidelity = false,
DocumentName = "Document Name",
DocumentFormat = "application/octet-stream",
DocumentNaturalLanguage = "en",
MultipleDocumentHandling = MultipleDocumentHandling.SeparateDocumentsCollatedCopies,
Copies = 1,
Finishings = Finishings.None,
PageRanges = new[] {new Range(1, 1)},
Sides = Sides.OneSided,
NumberUp = 1,
OrientationRequested = Orientation.Portrait,
PrinterResolution = new Resolution(600, 600, ResolutionUnit.DotsPerInch),
PrintQuality = PrintQuality.Normal
};
var response = await client.PrintJobAsync(request);
CancelJobAsyncCreateJobAsyncGetJobAttributesAsyncGetJobsAsyncGetPrinterAttributesAsyncHoldJobAsyncPausePrinterAsyncPrintJobAsyncPrintUriAsyncPurgeJobsAsyncReleaseJobAsyncRestartJobAsyncResumePrinterAsyncSendDocumentAsyncSendUriAsyncValidateJobAsyncGetCUPSPrintersAsyncМетод CustomOperationAsync отправляет принтеру запрос, который ты собираешь сам целиком.
var request = new IppRequestMessage
{
RequestId = 1,
IppOperation = (IppOperation)0x000A,
Version = IppVersion.V11
};
request.OperationAttributes.AddRange(
new []
{
new IppAttribute(Tag.Charset, "attributes-charset", "utf-8"),
new IppAttribute(Tag.NaturalLanguage, "attributes-natural-language", "en"),
new IppAttribute(Tag.NameWithoutLanguage, "requesting-user-name", "test"),
new IppAttribute(Tag.Uri, "printer-uri", "ipp://localhost:631"),
new IppAttribute(Tag.Integer, "job-id", 1),
});
client.CustomOperationAsync("ipp://localhost:631", request);