Tue Jun 25, 2024 8:30 am
Hello,
You'll find my code below, and also a video attached showing the described behavior:
public async Task PrintPdfStream(MemoryStream pdfStream, string printerName)
{
isEndPrint = false;
// create the PDF printer object
Spire.Pdf.License.LicenseProvider.SetLicenseKey(".................................");
Spire.Pdf.PdfDocument pdf = new Spire.Pdf.PdfDocument();
pdf.DocumentInformation.Title = this.Identifiant_IDT.ToString(false);
pdf.LoadFromStream(pdfStream);
PdfLayerCollection pdflayers = pdf.Layers;
foreach (Spire.Pdf.Graphics.Layer.PdfLayer layer in pdflayers)
{
if (layer.PrintState == Spire.Pdf.Graphics.LayerPrintState.Nerver) { pdflayers.RemoveLayer(layer); break; }
}
PaperSize paperSize;
PdfPrintSettings pdfprintsettings = new PdfPrintSettings();
pdfprintsettings.EndPrint += Pdfprintsettings_EndPrint;
paperSize = new PaperSize(this.Enveloppe.DisplayName, (Int32)MillimetersToInch(this.Enveloppe.Dimensions.Hauteur_mm), (Int32)MillimetersToInch(this.Enveloppe.Dimensions.Longeur_mm));
pdfprintsettings.PaperSize = paperSize;
// set the document name
pdfprintsettings.DocumentName = "Enveloppe_" + this.Identifiant_IDT.ToString(false);
pdfprintsettings.Landscape = true;
// set printer name
pdfprintsettings.PrinterName = printerName;
pdfprintsettings.Color = false;
// set to print without margins
pdfprintsettings.SetPaperMargins(0, 0, 0, 0);
pdfprintsettings.Duplex = Duplex.Simplex;
// enable silent printing
pdf.PrintSettings.PrintController = new StandardPrintController(); // Empêcher l'affichage de la boîte de dialogue d'impression
pdf.PrintSettings.Color = false;
await Task.Run(() =>
{
try
{
if (!TrackPrintJobExist(pdfprintsettings.DocumentName))
{
// start PDF file printing
pdf.Print(pdfprintsettings);
}
else
{
ResumeErroredPrintJobs(pdfprintsettings.DocumentName);
}
TrackPrintJob(printerName, pdfprintsettings.DocumentName);
}
catch (Exception ex)
{
throw new Exception("Erreur lors de l'impression" + Environment.NewLine + ex.Message);
}
});
pdfStream.Close();
}
Login to view the files attached to this post.