Hello,
we have a problem with the Aspose.Pdf.AddStamp method.
Adobe Acrobat Reader can’t open some of our Pdfs after stamping.
We use the following code snippet to stamp our Pdfs:
var textStamp = new Aspose.Pdf.TextStamp(stampText)
{
Background = false,
Opacity = 0.5,
RotateAngle = 50,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center,
TextAlignment = Aspose.Pdf.HorizontalAlignment.Center
};
textStamp.TextState.Font = FontRepository.FindFont(“Arial”);
textStamp.TextState.FontSize = 72.0f;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(121, 177, 0));
var pdfDoc = new Aspose.Pdf.Document(fileName);
for (var i = 1; i <= pdfDoc.Pages.Count; i++)
pdfDoc.Pages[i].AddStamp(textStamp);
pdfDoc.Save(outFileName);
In the attachment you will find one Pdf before and after stamping.
Maybe there is a connection to the exception that is shown in debug output after call of AddStamp.
‘A first chance exception of type ‘System.IO.EndOfStreamException’ occurred in mscorlib.dll’
Thank you very much for your support.
Kind regards,
Oliver
Hi Oliver,
Hi,
thank you for your support. It’s right, with version 8.5 the pdf looks fine.
But there is one more thing:
What we do, is adding the same stamp (textStamp) to several documents in a loop.
We have to create the Stamp within the loop for every turn. Isn’t it possible to create the stamp once and add it in a loop to several documents (like the source below)?
The Dispose-statement seems to do some harm to the stamp-object.
Could you please check?
Thank you and kind regards,
Oliver
var textStamp = new Aspose.Pdf.TextStamp(stampText)
{
Background = false,
Opacity = 0.5,
RotateAngle = 50,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center,
TextAlignment = Aspose.Pdf.HorizontalAlignment.Center
};
textStamp.TextState.Font = FontRepository.FindFont(“Arial”);
textStamp.TextState.FontSize = 72.0f;
textStamp.TextState.FontStyle = FontStyles.Bold;
textStamp.TextState.FontStyle = FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(121, 177, 0));
foreach (var file in pdfs)
{
if (!File.Exists(file)) continue;
var pdfDoc = new Aspose.Pdf.Document(file);
for (var i = 1; i <= pdfDoc.Pages.Count; i++)
pdfDoc.Pages[i].AddStamp(textStamp);
var outFileName = new FileInfo(file).Name;
pdfDoc.Save(Path.Combine(outputDirectory, outFileName));
pdfDoc.Dispose();
}
Hi Oliver,
Sorry for the inconvenience faced. While using the latest version of Aspose.Pdf for NET 8.5.0, I've managed to reproduce the reported stamping issue on our side and logged it in our bug tracking system as PDFNEWNET-36049 for further investigation and resolution. I've also linked your request to this issue and you will be notified via this thread as soon as it is resolved.
Please feel free to contact us for any further assistance.
Best Regards,
The issues you have found earlier (filed as PDFNEWNET-36049) have been fixed in Aspose.Pdf for .NET 8.7.0.
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi,
I’m afraid, it does not work properly. Using the code below, I get a NullPointerException on the second file - first page of several 3-page-pdfs. Could you please check?
Thank you.
Kind regards,
Oliver
private void btnStart_Click(object sender,
EventArgs e)
{
string stampText = "Wasserzeichen";
string[] pdfs = Directory.GetFiles("C:\\_Temp\\Aspose_AddStamp\\Daten", "*.pdf");
var textStamp = new Aspose.Pdf.TextStamp(stampText)
{
Background = false,
Opacity = 0.5,
RotateAngle = 50,
HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Center,
VerticalAlignment = Aspose.Pdf.VerticalAlignment.Center,
TextAlignment = Aspose.Pdf.HorizontalAlignment.Center
};
textStamp.TextState.Font = Aspose.Pdf.Text.FontRepository.FindFont("Arial");
textStamp.TextState.FontSize = 72.0f;
textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold;
textStamp.TextState.FontStyle = Aspose.Pdf.Text.FontStyles.Italic;
textStamp.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.FromArgb(121, 177, 0));
foreach (var file in pdfs)
{
if (!File.Exists(file))
{
continue;
}
using (var fs = new FileStream(file, FileMode.Open, FileAccess.ReadWrite))
{
var pdfDoc = new Aspose.Pdf.Document(fs);
for (var i = 1; i <= pdfDoc.Pages.Count; i++)
{
pdfDoc.Pages[i].AddStamp(textStamp); // Exception !!!
}
pdfDoc.Save();
pdfDoc.Dispose();
fs.Close();
}
}
Hi Oliver,
I
have tested the scenario and have managed to reproduce the same problem that when adding Stamp over more than one document, NullReferenceException is occurred. For the sake
of correction, I have separately logged this problem as PDFNEWNET-36147 in our
issue tracking system. We will further look into the details of this problem and
will keep you updated on the status of correction. Please be patient and spare
us little time. We are sorry for this inconvenience.<o:p></o:p>
The issues you have found earlier (filed as PDFNEWNET-36147) have been fixed in Aspose.Pdf for .NET 9.2.0.
The blog post for this release is created over this link
This message was posted using Notification2Forum from Downloads module by Aspose Notifier.
Hi,
this works fine now (with 9.2.1 because of the license-problem in 9.2.0).
Thanks for your support.
kind regards,
Oliver
Hi Oliver,