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.

Wed Feb 19, 2020 2:33 pm

Hi,

I am using the latest version of Spire.PDF .net 4.6. I have a requirement to print PDF's generated from a separate system. When in test mode I want to add a "Testing" watermark before printing. I have tried using the following code and then printing but the Watermark does not appear:

var pdf = new PdfDocument();
pdf.LoadFromFile(filePath);
PdfPageBase page = pdf.Pages[0];
page.BackgroundImage = watermark; // This is a Image type

pdf.PrintSettings.PrinterName = item.QueueName;
pdf.PrintSettings.Duplex = System.Drawing.Printing.Duplex.Vertical;
pdf.PrintSettings.Color = true;
pdf.Print();

IF use the following code:

private void AddWaterMark(string filePath, Image watermark)
{
var pdf = new PdfDocument();
pdf.LoadFromFile(filePath);
PdfPageBase page = pdf.Pages[0];
page.BackgroundImage = watermark;
pdf.SaveToFile(filePath);
pdf.Dispose();

}


and then reload the saved file the watermark appears when printed.

regards
Dan.

dankenny
 
Posts: 5
Joined: Sat Feb 15, 2020 3:45 pm

Thu Feb 20, 2020 3:08 am

Hello,

Thanks for your inquiry.
I indeed noticed that if directly printing the PDF document without saving, the watermark does not appear. This issue has been posted to our Dev team with the ticket SPIREPDF-3061 for further investigation. If there is any update, we will let you know.
As a workaround, you could save the PDF document to the stream and then reload it for printing. Below is the code for reference.
Code: Select all
   
    //Add watermark...
    MemoryStream stream = new MemoryStream();
    pdf.SaveToStream(stream, FileFormat.PDF);
    pdf.Dispose();
    pdf.LoadFromStream(stream);
    //Print...


Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Mon Feb 24, 2020 3:43 am

Hello,

Hope you are doing well.
After our Dev team's investigation, we found that if the PDF document is not saved, the data of the image watermark cannot be written into the PDF, so the watermark would not appear when printing. Thus, you need to save the PDF document before printing.
If there is any other question, just feel free to contact us.

Sincerely,
Rachel
E-iceblue support team
User avatar

rachel.lei
 
Posts: 1571
Joined: Tue Jul 09, 2019 2:22 am

Return to Spire.PDF

cron