Spire.PDF is a professional PDF library applied to creating, writing, editing, handling and reading PDF files without any external dependencies. Get free and professional technical support for Spire.PDF for .NET, Java, Android, C++, Python.

Mon Jun 24, 2024 4:20 pm

Hello,

I'm trying to silentlty print a PDF using the following recommandation: "doc.PrintSettings.PrintController = new StandardPrintController();"
However I still have a brief message while printing. (Spire.PDF 10.6.7).

Is there any workaround to fix that ?

Thanks,

fpernisek
 
Posts: 12
Joined: Wed Jun 15, 2016 7:02 am

Tue Jun 25, 2024 2:32 am

Hello,

Thanks for your inquriy.
I used the following code to test and did not encounter the issue you mentioned. Here I attach my test project for your reference. What does the "brief message" you mentioned mean? Can you take a screenshot and show us? To help us investigate further, can you provide us with a project that can reproduce your problem? You can upload it to the attachment or send it to this email: support@e-iceblue.com. Thanks in advance.
Code: Select all
 //Create a PdfDocument object
 PdfDocument doc = new PdfDocument();
 //Load a PDF file
 doc.LoadFromFile(@"test.pdf");
 //Specify printer name
 doc.PrintSettings.PrinterName = "HP ColorLaserJet MFP M278-M281 PCL-6 (V4)";
 //Silent printing
 doc.PrintSettings.PrintController = new StandardPrintController();
 //Print document
 doc.Print();


Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

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();

}

fpernisek
 
Posts: 12
Joined: Wed Jun 15, 2016 7:02 am

Tue Jun 25, 2024 10:22 am

Hello,

Thanks for your reply.
Please try to specify the print settings using the following code. If the issue exists,, please reply and let us know and we will test it further.
Code: Select all
 pdf.PrintSettings.Landscape = true;
 pdf.PrintSettings.PrinterName = "printer name";
 pdf.PrintSettings.Color = false;
 pdf.PrintSettings.SetPaperMargins(0,0,0, 0);
...
 pdf.PrintSettings.PrintController = new StandardPrintController();
 pdf.Print();


Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Tue Jun 25, 2024 2:29 pm

I've already tried the proposed code (moving the StandardPrinterController just before the print). It doesn't change anything.

For information I've tried another Nuget (Evopdf.Print) with the property "ShowStatusDialog= false" and it works fine.

Thanks in advance for you support (quite urgent as we are about to start a production based on Spire.PDF).

fpernisek
 
Posts: 12
Joined: Wed Jun 15, 2016 7:02 am

Wed Jun 26, 2024 1:31 am

Hello,

Thanks for your reply.
Sorry, the explanation in the previous letter may not be clear. Please comment out "PdfPrintSettings pdfprintsettings=new PdfPrintSettings();" and use "pdf. Print();" to print instead of "pdf. Print (pdfprintsettings);". The settings for printing can be set through "pdf. PrintSettings. XXX", for example, "pdf. PrintSettings. Landscape=true;". After making these changes, the dialog box will no longer appear on my end. If it still doesn't work on your end, we suggest that you provide us with a simplified project that can be run directly, and we will further investigate. Thank you in advance.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Wed Jun 26, 2024 10:22 am

Hello,

It's clear now ;-).

It works like a charm !

Thanks a lot !

Have a nice day.

fpernisek
 
Posts: 12
Joined: Wed Jun 15, 2016 7:02 am

Thu Jun 27, 2024 2:43 am

Hello,

Thanks for your reply.
I'm glad to hear this news. If you have any other questions, please feel free to write to me.

Sincerely,
William
E-iceblue support team
User avatar

William.Zhang
 
Posts: 454
Joined: Mon Dec 27, 2021 2:23 am

Return to Spire.PDF

cron