PdfFileStamp not working on all pdf

@tefan57

We were able to reproduce the issue in our environment. We changed the values of X,Y coordinates to make sure that they are within the page boundaries. The code worked with our sample PDF file but it did not add stamp on your PDF. Therefore, we have logged the ticket shared above. We will inform you once its resolved.

We are sorry for the inconvenience.

Hi,

Thank you for the update.

This is for us a very serious issue. It is a show stopping bug.

Do you have any insight into the problem, and how long it will take to get it fixed?

Regards,
Stefan

@tefan57

We will surely investigate the issue on first come first serve basis as per the free support policies. Furthermore, your concerns have been recorded as well and we will consider them during ticket investigation. We will inform you as soon as we make some definite progress towards ticket resolution. Please spare us some time.

We are sorry for the inconvenience.

Hi,

Are there any updates on the situation?

My client, Swedish Police Force, who purchased the Aspose license find this issue very concerning.

They were consindering extending their license for use in several other projects, but are now uncertain if Aspose is a good fit.

I need to report back when you believe this issue might be fixed.

Please provide me with some feedback.

Regs,
Stefan

@tefan57
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54711

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@tefan57

The reason is dynamic XFA that generates pages dynamically, any static content can’t be applied or added here. But we can detect that form is dynamic XFA and convert it into standard AcroForm, then add stamp.

We also noticed that for current document some text fragments are converted incorrectly so we created the additional issue (PDFNET-54711) to solve that.

Hi,

FYI, I tried converting the XFA to AcroForm using the code below.
It had no effect.
The issue does not seem to be limited to XFA.

Regs,
Stefan

pdfDocument.getForm().setType(FormType.Standard);*
pdfDocument.removeMetadata();*
pdfDocument.flatten(); *
pdfDocument.save(targetName +"_fixed.pdf");*
pdfDocument = new Document(targetName +"_fixed.pdf");*

And by no effect I mean that I was not able to stamp the pdf that was converted to AcroForm either.
The actual conversion worked.

Regs,
Stefan

@tefan57

Would you kindly share the obtained PDF document in your environment after flattening it? Have you used the latest version?

We have same problem. On Some pdf stamp is not getting added.

@pgkulkarni

Can you please share the sample PDF document and the code snippet that you are using? We will test the scenario in our environment and address it accordingly.

Please find the sample document
D106082023153739.pdf (234.3 KB)

Following is the code snippet for adding stamp

                    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(filename);

                    PdfPageEditor pEdit = new PdfPageEditor();
                    pEdit.BindPdf(filename);

                    customPageNo = Convert.ToInt32(Math.Round(Convert.ToDouble(strlist[0])));
                    Aspose.Pdf.PageSize size = pEdit.GetPageSize(customPageNo);
                    xpos = eSignPDFHelper.GetXPosition(size.Width, Convert.ToInt32(Math.Round(Convert.ToDouble(strlist[1]))));
                    ypos = eSignPDFHelper.GetYPosition(size.Height, Convert.ToInt32(Math.Round(Convert.ToDouble(strlist[2]))));

                    Aspose.Pdf.ImageStamp imageStamp = new Aspose.Pdf.ImageStamp(downloadedMessageInfo + "\\" + fle.Name);
                  
                    imageStamp.Rotate = Aspose.Pdf.Rotation.None;
                    imageStamp.Background = true;
                    imageStamp.XIndent = xpos;
                    imageStamp.YIndent = Convert.ToInt32(ypos);

                    pdfDocument.Pages[customPageNo].AddStamp(imageStamp);

                    pdfDocument.Save(filename);

@pgkulkarni

This code snippet contains some undefined and missing objects and we are unable to use it. Can you please share it with the hardcoded values of X and Y Indents with which you are facing the issue? We will test the scenario in our environment and address it accordingly. Also, it would be helpful if you can share the image file as well that is used to add image stamp.

Yes, using the latest version.

full function:

public static boolean JBS_AddTextSignature(String text,String sourceName, String targetName)
{
try
{

		 Document pdfDocument = new Document(sourceName);
		 
		 
		 pdfDocument.getForm().setType(FormType.Standard);
		 pdfDocument.removeMetadata();
		 pdfDocument.flatten();	
		 pdfDocument.save(targetName +"_fixed.pdf");
		 
		 pdfDocument = new Document(targetName +"_fixed.pdf");
		 		
		 
        // create text stamp
        TextStamp textStamp = new TextStamp(text);
        // set whether stamp is background
        textStamp.setBackground(true);
        // set origin
        textStamp.setXIndent(600);
        textStamp.setYIndent(48);
        // rotate stamp
        textStamp.setRotate(Rotation.on90);
        // set text properties
        textStamp.getTextState().setFont(FontRepository.findFont("Arial"));
        textStamp.getTextState().setFontSize(12.0F);
        

        for (int Page_counter = 1; Page_counter <= pdfDocument.getPages().size(); Page_counter++) {
            // add stamp to all pages of PDF file
            pdfDocument.getPages().get_Item(Page_counter).addStamp(textStamp);
            System.out.println("Added");
        }
        
        // save output document
        pdfDocument.save(targetName);
		
		
		
		
        
        return true;
	}
	catch(Exception e)
	{
		return false;
	}		
}<a class="attachment" href="/uploads/default/79372">wordTest2.pdf_fixed.pdf</a> (111.5 KB)

wordTest2.pdf_fixed.pdf (111.5 KB)

This is the flattened pdf, that still will not accept textstamp

@tefan57

Thanks for providing the requested information. We have updated the ticket accordingly and will perform investigation from this perspective. We will update you once we have some investigation results. Please spare us some time. We apologize for the inconvenience.

We have 9 page pdf document which already attached as sample document and we are trying stamping image on every page which is not visible
Please pfa sample stamping image sample image.png (420 Bytes)

                    Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(filename);

                    PdfPageEditor pEdit = new PdfPageEditor();
                    pEdit.BindPdf(filename);

                    customPageNo = 1;//2,3,4
                    Aspose.Pdf.PageSize size = pEdit.GetPageSize(customPageNo);
                    xpos = 467;//466,451,413
                    ypos = 41;//22,40,381

                    Aspose.Pdf.ImageStamp imageStamp = new Aspose.Pdf.ImageStamp(fle.Name);
               

                    imageStamp.Rotate = Aspose.Pdf.Rotation.None;
                    imageStamp.Background = true;
                    imageStamp.XIndent = xpos;
                    imageStamp.YIndent = Convert.ToInt32(ypos);

                    pdfDocument.Pages[customPageNo].AddStamp(imageStamp);

                    pdfDocument.Save(filename);

@tefan57

We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): PDFNET-54805

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

Hi,

Has there been any progress on this matter?
As previously this bug is a complete show stopper for us.

If there is not fix we will need to terminate the use of Aspose.

The client is the largest pulic authority in Sweden.

Regs,
Stefan

@tefan57

The following code is able to add stamp using PdfFileStamp. This is our output (Förfrågan (1).output_23_6__Standard.pdf)

com.aspose.pdf.facades.PdfFileStamp fileStamp = new com.aspose.pdf.facades.PdfFileStamp();
// Open Document
        fileStamp.bindPdf(dataDir + "Förfrågan (1).pdf");

        Form form = fileStamp.getDocument().getForm();
        System.out.println(form.getType());

        if (form.getType()==FormType.Dynamic){
            form.setType(FormType.Standard);
        }
// Create stamp
        com.aspose.pdf.facades.Stamp stamp = new com.aspose.pdf.facades.Stamp();
        stamp.setStampId(1); //draft watermark has id = 1, used by JBS_RemoveDraftWatermark
        stamp.bindLogo(new com.aspose.pdf.facades.FormattedText("This is sample", java.awt.Color.BLACK, null, com.aspose.pdf.facades.FontStyle.Helvetica, com.aspose.pdf.facades.EncodingType.Winansi, true, 8));
        stamp.setOrigin(10, 400); // stamp.setOrigin(600, 48); <= Customer is using this value
        stamp.setRotation(90.0F);
        stamp.setBackground(false);

// Add stamp to PDF file
        fileStamp.addStamp(stamp);

// Save updated PDF file
        fileStamp.save(dataDir + "Förfrågan (1).output_23_6__Standard.pdf");

// Close fileStamp
        fileStamp.close();

The reason why you can’t see a TextStamp using your code in JBS_AddTextSignature method, that you are trying to set a stamp out of page boundaries. Actual page size has width 595 pixels, but textStamp.setXIndent(600). The stamp is placed but it is where as shown on the screenshot (Screenshot_.png)

This is result when XIndent is 500 - stamp is visible (Förfrågan (1).pdf_23_6__out_XIndent(500).pdf)

Förfrågan (1).pdf_23_6__out_XIndent(500) (1).pdf (185.8 KB)
Screenshot_.png (139.8 KB)
Förfrågan (1).pdf_23_6__out_XIndent(500) (1).pdf (185.8 KB)