Generated PDF file not WCAG compatible

I try to add a TextStamp on my PDF file. I use this line of code (C#), in order to set the background color for my TextStamp: textStamp.TextState.BackgroundColor = Color.White;. When I download the generated PDF file and put it to PDF Accessibility Checker 2024, I have an error that the PDF file is not WCAG compatible. The exact error is the following and it is related to the line of code I wrote above: “Error while parsing the PDF document (Operator ‘rg’ not allowed in this current state.)”. Have you experienced anything like this before? Thank you in advance!

@ButchIV

It seems that you are encountering an issue with the background color of the TextStamp in your PDF file, which is causing it to fail WCAG compatibility checks. The error message “Operator ‘rg’ not allowed in this current state” typically indicates that there is a problem with the graphics state when trying to apply the background color.

To address this issue, you can try the following steps:

  1. Ensure Proper Graphics State: Before setting the background color, make sure that the graphics state is correctly initialized. This can sometimes be a problem if the TextStamp is not being added in the right context.

  2. Set Background Color Correctly: When setting the background color for the TextStamp, ensure that you are doing it after the TextStamp has been fully configured. Here’s a sample code snippet that demonstrates how to add a TextStamp with a background color:

    // Load the existing PDF document
    Document pdfDocument = new Document("input.pdf");
    
    // Create a TextStamp
    TextStamp textStamp = new TextStamp("Your Text Here");
    textStamp.TextState.BackgroundColor = Color.White; // Set the background color
    textStamp.XIndent = 100; // Set the X position
    textStamp.YIndent = 100; // Set the Y position
    
    // Add the TextStamp to the first page
    pdfDocument.Pages[1].AddStamp(textStamp);
    
    // Save the updated PDF document
    pdfDocument.Save("output.pdf");
    
  3. Check for Overlapping Elements: Ensure that there are no overlapping elements in your PDF that might be causing conflicts with the rendering of the TextStamp.

  4. Test with Different Colors: Sometimes, specific colors may cause issues. Try using a different color or even omitting the background color to see if the error persists.

  5. Update Aspose.PDF Library: Ensure that you are using the latest version of the Aspose.PDF library, as updates may contain fixes for known issues.

If the problem continues after trying these suggestions, consider reaching out to Aspose support for further assistance, as they may have more insights into specific compatibility issues with WCAG standards.

Feel free to ask if you have any more questions or need further clarification!

Sources:
[1]: Add Text Stamp In PDF File | Aspose.PDF for .NET API Reference