Hi,
I am currently encountering an error when trying to stamps every page on this file :
test.pdf (4.5 MB)
this is my snippet code :
private byte[] StampDocumentStream(byte[] inputFileByte, string text)
{
try
{
MemoryStream stream = new MemoryStream();
stream.Write(inputFileByte, 0, inputFileByte.Length);
// Initialize license object
Aspose.Pdf.License license = new Aspose.Pdf.License();
// Set license
license.SetLicense("Aspose.Total.lic");
Aspose.Pdf.Document pdfDocument = new Aspose.Pdf.Document(stream);
for (int iCount = 1; iCount <= pdfDocument.Pages.Count; iCount++)
{
double PageHeight = pdfDocument.Pages[iCount].PageInfo.Height;
double PageWidth = pdfDocument.Pages[iCount].PageInfo.Width;
//Vertical Stamp
// Create text stamp
TextStamp textStampVertical = new TextStamp(text);
// Set whether stamp is background
//textStampVertical.Background = true;
// Set origin
textStampVertical.XIndent = 30;
textStampVertical.YIndent = PageHeight/2 -90;
// Rotate stamp
textStampVertical.Rotate = Rotation.on90;
// Set text properties
textStampVertical.TextState.Font = FontRepository.FindFont("Arial");
textStampVertical.TextState.FontSize = 8.0F;
//set Opacity
textStampVertical.Opacity = 1;
//textStamp.TextState.FontStyle = FontStyles.Bold;
//textStamp.TextState.FontStyle = FontStyles.Italic;
textStampVertical.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
// Add stamp to particular page
pdfDocument.Pages[iCount].AddStamp(textStampVertical);
//Horizontal Stamp
// Create text stamp
TextStamp textStampHorizontal = new TextStamp(text);
// Set whether stamp is background
//textStampHorizontal.Background = true;
// Set origin
textStampHorizontal.XIndent = PageWidth/2 - 90;
textStampHorizontal.YIndent = 40;
//// Rotate stamp
//textStampHorizontal.Rotate = Rotation.on90;
// Set text properties
textStampHorizontal.TextState.Font = FontRepository.FindFont("Arial");
textStampHorizontal.TextState.FontSize = 8.0F;
//set Opacity
textStampHorizontal.Opacity = 1;
//textStamp.TextState.FontStyle = FontStyles.Bold;
//textStamp.TextState.FontStyle = FontStyles.Italic;
textStampHorizontal.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Black);
// Add stamp to particular page
pdfDocument.Pages[iCount].AddStamp(textStampHorizontal);
}
// Save output document
pdfDocument.Save(stream);
return stream.ToArray();
}
catch (Exception ex)
{
throw;
}
}
the error shown in this following image
image.png (14.4 KB)
with the following stack trace detail
at #=zja7JJd$U2W06aggliaZlkoM__d3ui0nfHg==.#=zhMl62JfRNDpw()
at #=zLbJE4Thqp$AoD7iO7NY$L_gRPQkvYEshSIf5M83Pt1CZNArrlA==.#=z39esnEs=(#=z3upXeq5THn$6Qn7mKi09R2gbTlJO5dAj8hZq8Y09$DBV #=z7NHVjFSMTo_l, #=z2sWIMxV8eAjKD0_ULJmTormGQ1wSu$7w9nesDow= #=zY3m_7LslRzND)
at #=zsv$VvVkppwAOIobTWMt8sW2LOb0QgwFtfg==.#=zzWjbI4A=()
at #=zDCMCmc4wZbmQDytmeOnMmHv7lQV57qDLzw==.#=z39esnEs=(Stream #=zkGubm0s=)
at #=zHJxHrkrWO2NCOoxu2thrPbZ4hjCD.#=z39esnEs=(Stream #=zkGubm0s=)
at Aspose.Pdf.Document.#=zg9hU84stvRSb(Stream #=zOOkOZ74=, SaveOptions #=z1vc_OHw6isWz)
at Aspose.Pdf.Document.Save(Stream output)
at PortalLHP.Web.Controllers.DirektoriLHPController.StampDocumentStream(Byte[] inputFileByte, String text)