We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Delete Text Stamp by ID not working

Hi,


I’ve been trying several solutions to get this issue resolved and I always seem to come up with the same conclusion; the text stamps aren’t being deleted. I might be missing something fundamentally simple and I have followed several other posts where this has been reported, namely this thread Deleting Text Stamp by ID not working where a possible Document and PdfContentEditor clash could cause the text stamps to not be stripped out.

Currently, I have a single method that is responsible for the removal of these stamps, code pasted below;
private static void existingClassification(string path)
{
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.BindPdf(path);
contentEditor.DeleteStampById(1123581321);
contentEditor.Save(path);

}

The ID is applied to the stamp when I apply it to the document, I have currently commented out any mention to Document pdf = new Document(path); subsequently to try and remove that possible issue but still, the issue is persisting.

Has anyone else come across this previously, I have even attempted to wrap the section of code above in a try catch to see if I missing an exception but the whole block executes ‘perfectly’.

Thanks,
Jak

Hi Jak,


Thanks for contacting support.

I have tested the scenario using Aspose.Pdf for .NET 9.3.0 and as per my observations, the stamp is properly being removed using its ID. For testing purposes, I have used the following code snippet to add Text Stamp to PDF file.

[C#]

Aspose.Pdf.Document
pdfDocument = new Aspose.Pdf.Document();<o:p></o:p>

pdfDocument.Pages.Add();

DateTime dtServerTime = DateTime.Now;

DateTime dtEST = DateTime.Now;

Aspose.Pdf.Facades.FormattedText txtFormatted = new Aspose.Pdf.Facades.FormattedText();

txtFormatted.AddNewLineText("Processed/Reviewed By:");

txtFormatted.AddNewLineText(dtEST.ToString());

TextStamp textStamp = new TextStamp(txtFormatted);

textStamp.Background = true;

textStamp.BottomMargin = 50;

textStamp.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;

textStamp.VerticalAlignment = VerticalAlignment.Bottom;

textStamp.XIndent = 10;

textStamp.YIndent = 10;

textStamp.TextState.FontSize = 10.0F;

textStamp.Opacity = 100;

//Set ID of stamp

textStamp.setStampId(999);

pdfDocument.Pages[1].AddStamp(textStamp);

pdfDocument.Save(“c:\pdftest\Test_output2.pdf”);


Then I have used the following code to remove the stamp and its properly being removed.

[C#]

//load source document<o:p></o:p>

Aspose.Pdf.Facades.PdfContentEditor contentEditor = new Aspose.Pdf.Facades.PdfContentEditor();

contentEditor.BindPdf("c:\\pdftest\\Test_output2.pdf");

//remove stamp by Id (without stamps iterating)

contentEditor.DeleteStampByIds(new int[] { 999 });

//save result into intermediate file (may be stored into memory stream to don't deal with temporary flles)

contentEditor.Save(“c:/pdftest/Stamp_Removed.pdf”);


In case you still face any problem, please share the resource PDF document and ID of Stamp so that we can test the scenario at our end. We are sorry for your inconvenience.

Hi Nayyer,


I tried the code as you put it and it is still failing to remove the text stamp, I have attached the PDF in question and the ID I am using is 11235813. Just to try and provide as much clarity as possible, I have also inserted the code I am currently using below as well.

To add the text stamp;
Document pdf = new Document(path);

TextStamp txtStamp = new TextStamp(classification);

txtStamp.HorizontalAlignment = HorizontalAlignment.Center;
txtStamp.VerticalAlignment = VerticalAlignment.Bottom;
txtStamp.TextState.FontSize = 20;
txtStamp.TextState.ForegroundColor = Color.Red;
txtStamp.TextState.Font = FontRepository.FindFont(“Arial”);
txtStamp.setStampId(11235813);

foreach (Page page in pdf.Pages)
{
page.AddStamp(txtStamp);
}

pdf.Save(path);

To remove the stamp:
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.BindPdf(path);
contentEditor.DeleteStampById(11235813);
contentEditor.Save(@“C:\temp\test.pdf”);

Ideally as well I’d like to avoid saving to a new file and would instead like to replace ‘C:\temp\test.pdf’ with ‘path’ so the original file is just resaved but with the stamps removed.

Thanks

Hi Nayyer,


After some more digging around, I’ve gotten to the root of the issue. It seems that even though another developer has called the SetLicense method, this has only applied to for the Aspose Words module of our Total license and makes sense that when I try and manipulate the PDF, the software thinks it’s running in a trial state.

Is there no way that I can call a global license method, this forum post would seem to suggest it’s not How to apply license for Aspose.Total for .Net, but it seems a little convoluted to have to call the SetLicense method for every module when a Total license has been purchased?

More a point of curiosity, the main issue in this thread has been resolved so I’m happy for this to be marked as closed or resolved or whatever the process is for this.

Thanks

jak893:
To remove the stamp:
PdfContentEditor contentEditor = new PdfContentEditor();
contentEditor.BindPdf(path);
contentEditor.DeleteStampById(11235813);
contentEditor.Save(@“C:\temp\test.pdf”);

Ideally as well I’d like to avoid saving to a new file and would instead like to replace ‘C:\temp\test.pdf’ with ‘path’ so the original file is just resaved but with the stamps removed.
Hi Jak,

Thanks for sharing the details.

I have again tested the scenario using Aspose.Pdf for .NET 9.3.0 in Visual Studio 2012 application where I have set the target platform of application as .NET Framework 4.0, running over Windows 7 (x64) and as per my observations, the Stamp object is properly being removed from PDF file. I have used the same code snippet to add stamp object, as you have stated in your earlier post.

Now concerning to your other requirement of removing the stamp and saving output in same file, please try using the following code snippet.

Can you please share some details regarding your working environment which can help us in replicating this issue at our end. We are sorry for this inconvenience.

[C#]

//
load source PDF file in Document object
<o:p></o:p>

Document doc = new Document(new FileStream("c:/pdftest/WithStamp - Copy.pdf", FileMode.OpenOrCreate));

PdfContentEditor contentEditor = new PdfContentEditor();

// bind Doccument object to Content Editor

contentEditor.BindPdf(doc);

contentEditor.DeleteStampById(11235813);

// save the updated Document object to save file (source/input)

doc.Save();

jak893:
After some more digging around, I’ve gotten to the root of the issue. It seems that even though another developer has called the SetLicense method, this has only applied to for the Aspose Words module of our Total license and makes sense that when I try and manipulate the PDF, the software thinks it’s running in a trial state.

Is there no way that I can call a global license method, this forum post would seem to suggest it’s not How to apply license for Aspose.Total for .Net, but it seems a little convoluted to have to call the SetLicense method for every module when a Total license has been purchased?
Hi Jak,

Every API under Aspose.Total umbrella has its own implementation and separate Document Object Model and they require individual license initialization. As you are using Aspose.Words for .NET and Aspose.Pdf for .NET in single application/solution, so you need to individually call setLicense method for both API’s.

[C#]

Aspose.Pdf.License license = new Aspose.Pdf.License();<o:p></o:p>

license.SetLicense("E:\Aspose.Total.lic");

Aspose.Words.License wordlic = new Aspose.Words.License();

wordlic.SetLicense("e:\Aspose.total.lic");