I have a pdf file with 85 total pages.
After loading the file to stream, some pages will be “null”; the first three pages will be fine. Please locate the screenshot.
sample_screenshoot.png (39.8 KB)
Code :
string pdfFilePath = @"D:\Users\samplefiles\Free_Test_Data_1MB_PDF.pdf";
Stream stream = System.IO.File.OpenRead(pdfFilePath);
Document document = new Document(stream);
List<string> watermarkData = new() { "Welcome 20230403_1", "I","suresh l", "asdsadsadasd sadasdasdasd asdsadsadsad sadsadsadasd", "::ffff:127.0.0.1", "12:39 IST" };
FormattedText formattedText = new(watermarkData[0], System.Drawing.Color.Red,System.Drawing.Color.White,
Aspose.Pdf.Facades.FontStyle.Helvetica,
EncodingType.Macroman,
false,
20);
watermarkData.RemoveAt(0);
watermarkData.ForEach(f =>
{
formattedText.AddNewLineText(f);
});
TextStamp topleftWatermark = new TextStamp(formattedText);
topleftWatermark.VerticalAlignment = VerticalAlignment.Center;
topleftWatermark.HorizontalAlignment = HorizontalAlignment.Center;
topleftWatermark.Opacity = 10;
topleftWatermark.RotateAngle = 45;
topleftWatermark.TextAlignment = HorizontalAlignment.Center;
topleftWatermark.WordWrap = true;
topleftWatermark.Scale = false;
document.Pages.ToList().ForEach(x =>
{
if (x != null) x.AddStamp(topleftWatermark);
x.FreeMemory();
});
string filePath = @"D:\working\samplefiles";
string path1 = Path.Combine(filePath, String.Concat(Guid.NewGuid(), "_apose_output.pdf"));
document.Save(path1);