Pdf File Not Loading Properly

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

@sureshkumar.arumugam,

Can you provide the pdf document affected, please? Also, what version of the API are you using?

84_page.pdf (924.8 KB)

Aspose.PDF - .Nuget Version (23.4.0)

@sureshkumar.arumugam,

Using the exact version of the API I run the following code and it worked fine as the output showed:

private void Logic()
{
    Document doc = new Document($"{PartialPath}_input.pdf");

    List<string> watermarkData = new List<string> { "Welcome 20230403_1", "I", "suresh l", "asdsadsadasd sadasdasdasd asdsadsadsad sadsadsadasd", "::ffff:127.0.0.1", "12:39 IST" };

    FormattedText formattedText = new FormattedText(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;
    doc.Pages.ToList().ForEach(x =>
    {

        if (x != null) x.AddStamp(topleftWatermark);
        x.FreeMemory();
    });
    string filePath = @"D:\working\samplefiles";


    doc.Save($"{PartialPath}_output.pdf");
}

The input and output files:
AddingStamps_input.pdf (924.8 KB)
AddingStamps_output.pdf (953.4 KB)

I am not able to replicate this problem.

By any chance are you running this in a none windows machine?