Issue with watermarking using Aspose.PDF 24.11.0 as Specified argument was out of the range of valid values

Hi Team,

we facing following error “Specified argument was out of the range of valid values. (Parameter ‘Unrecognized filter type.’)” while applying watermarking. pdf having ~900 pages it is failing in 213 page number.

Aspose pdf version : 24.11.0 - Licensed

Thanks
Saravana

@Saravana1983

The error message “Specified argument was out of the range of valid values. (Parameter ‘Unrecognized filter type.’)” that you are encountering while applying watermarking to your PDF document could be related to the specific properties or types of artifacts being used in your code.

Here are a few steps you can take to troubleshoot and potentially resolve this issue:

  1. Check Artifact Types: Ensure that the artifact types you are using for the watermark are valid. The Aspose.PDF library supports specific artifact types, and using an unsupported type may lead to this error.

  2. Review the Watermark Implementation: Make sure that the code you are using to apply the watermark adheres to the expected structure and types defined in the Aspose.PDF documentation. If you are using custom types or values, verify that they are correctly defined.

  3. Inspect the PDF Content: Since the error occurs on a specific page (213), check the content of that page. There may be something unique about it that is causing the watermarking process to fail. Look for any unusual elements or properties that might not be compatible with the watermarking feature.

  4. Update Aspose.PDF Version: If possible, consider updating to a newer version of Aspose.PDF. There may have been bug fixes or improvements in later versions that could resolve this issue.

  5. Sample Code: If you need a reference for how to correctly apply a watermark, here is a basic example of how to add a watermark using Aspose.PDF:

    Document pdfDocument = new Document("input.pdf");
    Page page = pdfDocument.getPages().get(1); // Get the first page
    
    // Create a watermark artifact
    Artifact watermark = new Artifact();
    watermark.setType(Artifact.ArtifactType.Watermark);
    watermark.setText("Sample Watermark");
    watermark.setOpacity(0.5);
    watermark.setRectangle(new Rectangle(100, 100, 300, 200)); // Set position
    
    // Add the watermark to the page
    page.getArtifacts().add(watermark);
    pdfDocument.save("output.pdf");
    

If the issue persists after trying these suggestions, consider reaching out to Aspose support with detailed information about your implementation and the specific PDF file you are working with.

Sources:
[1]: Add watermark to PDF|Aspose.PDF for Java - Aspose Documentation

Class : Aspose.Pdf.Document
Method: AddStamp
Error : Specified argument was out of the range of valid values. (Parameter ‘Unrecognized filter type.’)

I have tried the code you suggested, still facing same issue and not any issue with document too, we are using latest pdf version 24.11.0 with license

@Saravana1983

Would you kindly share your sample document as well as sample code snippet with us? We will test the scenario in our environment and address it accordingly.

Hi,
Thanks for quick response. we don’t have dummy document to replicate this issue. but i have attached issue page screenshot. look like “page.Artifacts” throw an exception,
code snippet:
var stream = new MemoryStream();

using (request)
{
var license = new License();
license.SetLicense(LicenseConstants.ASPOSE);
using (Document document = new Document(request))
{
int padding = 24;
var textState = new TextState
{
Font = FontRepository.FindFont(“Verdana”),
ForegroundColor = Color.LightCoral,
};
TextStamp header = new(“WaterMarkTest”, textState)
{
TextState =
{
FontSize = 28
},
HorizontalAlignment = HorizontalAlignment.Center,
VerticalAlignment = VerticalAlignment.Center,
RotateAngle = 23,
Opacity = 0.27,
Background = false,
};

     foreach (var page in document.Pages)
     {
         page?.AddStamp(header);
     }
     document.Save(stream);

}

Thanks
Saravana
issue 1.png (26.3 KB)

@Saravana1983

The issue looks like a specific PDF document that is why we requested one. If you could please arrange and share sample file with us, we will be able to reproduce it in our environment and address the issue accordingly.