I went ahead and wrote a test program that will apply multiple lines of stamp text to each page of the document. Some documents contain a mix of portrait and landscape pages, therefore I need to add the stamp text page by page cause i use the page height and width to place the stamp. As I am interating thru the page count when I go from a landscape page to a portrait, it appears the stamp text is getting added but it's not visible...I can highlight the stamp text and copy and paste to a text document to verify it's there but its just not visible in the PDF document.
The stamp info (i.e. text, color, font, etc) is loaded in a list and it iterated thru for each page and does not change...
The sample pdfs are attached.
ConsoleApplication1.PDFServicesWS.ServiceWS pdfServices = new ConsoleApplication1.PDFServicesWS.ServiceWS();
pdfServices.Timeout = 4800000;
ConsoleApplication1.PDFServicesWS.PDFDocument pdfDocument = new ConsoleApplication1.PDFServicesWS.PDFDocument();
pdfDocument.FileContent = ReadFromFile(@"C:\ifass_extract\stamp\2.pdf");
pdfDocument.FileName = @"C:\ifass_extract\stamp\2.pdf";
ConsoleApplication1.PDFServicesWS.PDFStampBox pdfStampBox = new ConsoleApplication1.PDFServicesWS.PDFStampBox();
pdfStampBox.StampLineList = new ConsoleApplication1.PDFServicesWS.PDFStampLine[4];
pdfStampBox.StampHeight = 80;
pdfStampBox.StampWidth = 200;
pdfStampBox.StampTop = 30;
pdfStampBox.StampRight = 30;
pdfStampBox.StampRotation = -5;
pdfStampBox.ShowBorder = true;
pdfStampBox.BorderWidth = 1;
ConsoleApplication1.PDFServicesWS.PDFStampLine pdfStampLine1 = new ConsoleApplication1.PDFServicesWS.PDFStampLine();
pdfStampLine1.FontFamily = ConsoleApplication1.PDFServicesWS.FontStyle.HelveticaBold;
pdfStampLine1.FontSize = 12;
pdfStampLine1.FontColorRed = 139;
pdfStampLine1.FontColorGreen = 35;
pdfStampLine1.FontColorBlue = 35;
pdfStampLine1.YOffset = 4;
pdfStampLine1.Text = "APPROVED";
pdfStampBox.StampLineList[0] = pdfStampLine1;
ConsoleApplication1.PDFServicesWS.PDFStampLine pdfStampLine2 = new ConsoleApplication1.PDFServicesWS.PDFStampLine();
pdfStampLine2.FontFamily = ConsoleApplication1.PDFServicesWS.FontStyle.Helvetica;
pdfStampLine2.FontSize = 8;
pdfStampLine2.FontColorRed = 0;
pdfStampLine2.FontColorGreen = 0;
pdfStampLine2.FontColorBlue = 0;
pdfStampLine2.YOffset = 3;
pdfStampLine2.Text = "Date Received: Date Of Action:";
pdfStampBox.StampLineList[1] = pdfStampLine2;
ConsoleApplication1.PDFServicesWS.PDFStampLine pdfStampLine3 = new ConsoleApplication1.PDFServicesWS.PDFStampLine();
pdfStampLine3.FontFamily = ConsoleApplication1.PDFServicesWS.FontStyle.Helvetica;
pdfStampLine3.FontSize = 10;
pdfStampLine3.FontColorRed = 0;
pdfStampLine3.FontColorGreen = 0;
pdfStampLine3.FontColorBlue = 0;
pdfStampLine3.YOffset = 3;
pdfStampLine3.Text = "11/25/2001 12/10/2002";
pdfStampBox.StampLineList[2] = pdfStampLine3;
ConsoleApplication1.PDFServicesWS.PDFStampLine pdfStampLine4 = new ConsoleApplication1.PDFServicesWS.PDFStampLine();
pdfStampLine4.FontFamily = ConsoleApplication1.PDFServicesWS.FontStyle.Helvetica;
pdfStampLine4.FontSize = 8;
pdfStampLine4.FontColorRed = 0;
pdfStampLine4.FontColorGreen = 0;
pdfStampLine4.FontColorBlue = 0;
pdfStampLine4.YOffset = 5;
pdfStampLine4.Text = "FL OFFICE OF INSURANCE REGULATION";
pdfStampBox.StampLineList[3] = pdfStampLine4;
pdfDocument = pdfServices.StampDocument(pdfDocument, pdfStampBox);
SaveToFile(pdfDocument.FileContent, @"C:\ifass_extract\stamp\edms_stamped.pdf");
public PDFDocument StampDocument(PDFDocument pdfDocument, PDFStampBox pdfStampBox)
PDFCommon common = new PDFCommon();
PDFDocument stampedPdf = new PDFDocument();
MemoryStream inStream = common.ByteArrayToMStream(pdfDocument.FileContent);
MemoryStream outStream = new MemoryStream();
PdfFileInfo fileInfo = new PdfFileInfo(inStream);
int numPages = fileInfo.NumberofPages;
Aspose.Pdf.Kit.PdfFileStamp stamper = new PdfFileStamp(inStream, outStream);
for (int i = 1; i <= numPages; i++)
{
float iTextWidth = 0; float iTextHeight = 0;
//Get height, width and rotation of the current page
float iPageHeight = 0; float iPageWidth = 0; int iRotation = 0;
iPageHeight = fileInfo.GetPageHeight(i);
iPageWidth = fileInfo.GetPageWidth(i);
iRotation = fileInfo.GetPageRotation(i);
float StampX = 0; float StampY = 0; float iOffset = 0;
StampX = iPageWidth - (pdfStampBox.StampWidth + pdfStampBox.StampRight);
StampY = iPageHeight - (pdfStampBox.StampHeight + pdfStampBox.StampTop);
iOffset = pdfStampBox.StampTop;
// For each line of the stamp as defined in the ini file
foreach (PDFStampLine stampLine in pdfStampBox.StampLineList)
{
Stamp stamp = new Stamp();
stamp.Pages = new int[] { i };
Aspose.Pdf.Kit.FormattedText ft = new FormattedText(stampLine.Text,
new Aspose.Pdf.Kit.FontColor(stampLine.FontColorRed, stampLine.FontColorGreen, stampLine.FontColorBlue),
stampLine.FontFamily,
EncodingType.Winansi,
false,
stampLine.FontSize);
// Set stamp information and apply to PDF document
iTextWidth = ft.TextWidth; iTextHeight = ft.TextHeight;
stamp.SetOrigin(StampX + (pdfStampBox.StampWidth - iTextWidth) / 2, (iPageHeight - iOffset));
iOffset = iOffset + iTextHeight + stampLine.YOffset;
stamp.Rotation = pdfStampBox.StampRotation;
stamp.BindLogo(ft);
stamper.AddStamp(stamp);
}
}
stamper.Close();
stampedPdf.IsSuccessful = true;
stampedPdf.FileName = pdfDocument.FileName.Replace(".pdf", "_stamped.pdf");
stampedPdf.FileContent = common.MStreamToByteArray(outStream);
return stampedPdf;