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

Free Support Forum - aspose.com

ASPOSE PDF Stamp

Hi Team,
I am using ASPOSE PDF stamp function to stamp the pages in the PDF document with a PNG image.

It is working fine if the stamp position is same for all the pages. Since in our case PDF is having pages of different size hence the position is also different. So we are looping through each page to calculate the page size and the stamp position.

If we call AddStamp function for each page then the output is very large with respect to original file.

The Input file detail:
Size: 96MB
Pages: 1922

Output File Detail:
Size: 450 MB
Pages: 1922

If AddStamp is called once for all pages the file size remains same with KB more in size.

Kindly let us know why the file size is increased so much as the stamp image size is 21KB only.
Also Please suggest the best way to stamp pages with different stamp position depending on the page dimension.

Thanks
Dipak Pandey

@dipakp

Thank you for contacting support.

Would you please share narrowed down code snippets along with respective files via Google Drive, Dropbox etc. so that we may try to reproduce and investigate it in our environment to help you out.

Following is the Code Snippets we are currently using in our application:
int x = Convert.ToInt32(ConfigurationManager.AppSettings[“CourtStampPositionX”]);
int y = Convert.ToInt32(ConfigurationManager.AppSettings[“CourtStampPositionY”]);
Document pdfDocument = new Document(mergedPdf);
PdfFileStamp fileStamp = new PdfFileStamp(pdfDocument);
FileStream imageStream = new FileStream(imgPath, FileMode.Open);
Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindImage(imageStream);
stamp.SetImageSize(50.0f, 50.0f);
stamp.IsBackground = false;
PdfFileInfo pdfFileInfo = new PdfFileInfo(pdfDocument);
int noofpage = pdfFileInfo.NumberOfPages;
for (int i = 1; i <= noofpage; i++) {
var pageWidth = pdfFileInfo.GetPageWidth(i) - x;
var pageHeight = pdfFileInfo.GetPageHeight(i) - y;
stamp.SetOrigin(pageWidth, pageHeight);
stamp.Pages = new int[] { i };
fileStamp.AddStamp(stamp);
}
imageStream.Close();
pdfDocument.Save(mergedPdf);

PFB the Google Drive link where all the files related are saved

https://drive.google.com/open?id=120Gt9z1V3UJKI6rSZkNXspCDZQlHVkp-

@dipakp

Thank you for sharing requested resources.

Would you please also share the code snippet where you are calling AddStamp method once for all the pages, so that we may proceed to investigate and help you out.

As I shared code snippet with you in for loop we are calling AddStamp method as per our requirement we need to stamp in every page at specific location according to page size.

Below is the code to stamp all pages with same stamp origin. Its just remove the loop and stamp page indexes.

int x = Convert.ToInt32(ConfigurationManager.AppSettings[“CourtStampPositionX”]);
int y = Convert.ToInt32(ConfigurationManager.AppSettings[“CourtStampPositionY”]);
Document pdfDocument = new Document(mergedPdf);
PdfFileStamp fileStamp = new PdfFileStamp(pdfDocument);
FileStream imageStream = new FileStream(imgPath, FileMode.Open);
Aspose.Pdf.Facades.Stamp stamp = new Aspose.Pdf.Facades.Stamp();
stamp.BindImage(imageStream);
stamp.SetImageSize(50.0f, 50.0f);
stamp.IsBackground = false;
PdfFileInfo pdfFileInfo = new PdfFileInfo(pdfDocument);
var pageWidth = pdfFileInfo.GetPageWidth(i) - x;
var pageHeight = pdfFileInfo.GetPageHeight(i) - y;
stamp.SetOrigin(pageWidth, pageHeight);
fileStamp.AddStamp(stamp);
imageStream.Close();
pdfDocument.Save(mergedPdf);

@dipakp

Thank you for sharing the details.

We are investigating the scenario and will get back to you soon.

1 Like

Hi Farhan,

What is the ETA for the closure of the issue? Is there any process to move this to critical or severity A issue as
this issue is impacting our business.

@dipakp

Currently initial investigations are in progress and we will share our findings with you in couple of days. Please be patient and spare us some time.

@dipakp

Thank you for being patient.

Please try using below code snippet in your environment and then share your kind feedback with us.

int x = 100;
int y = 100;
Document pdfDocument = new Document(dataDir + "Defence Doc Test.pdf");
FileStream imageStream = new FileStream(dataDir + "courtstamp.png", FileMode.Open);
ImageStamp imageStamp1 = new ImageStamp(imageStream);
PdfFileInfo pdfFileInfo = new PdfFileInfo(pdfDocument);
int noofpage = pdfFileInfo.NumberOfPages;
for (int i = 1; i <= noofpage; i++)
{
    var pageWidth = pdfFileInfo.GetPageWidth(i) - x;
    var pageHeight = pdfFileInfo.GetPageHeight(i) - y;
    imageStamp1.XIndent = pageWidth;
    imageStamp1.YIndent = pageHeight;
    imageStamp1.Height = 50.0f;
    imageStamp1.Width = 50.0f;
    imageStamp1.Rotate = Rotation.None;
    pdfDocument.Pages[i].AddStamp(imageStamp1);
}
imageStream.Close();
pdfDocument.OptimizeSize = true;
pdfDocument.Save(dataDir + "Defence Doc Test_out_18.12.pdf");

We hope this will be helpful. Please feel free to contact us if you need any further assistance.

Thanks Team,

We are working on the code suggested.
this is to update that we have moved to the paid support hence request to do the needful.

Thanks,
Dipak Pandey

@dipakp

Thank you for the information.

With paid support you may report your issues at Paid Support Helpdesk. In case you have already reported a problem which has been logged in our issue management system, then you can also request to raise priority of such issues over HelpDesk as per your requirements.

@Farhan.Raza

Code is working as per our requirement.
Thanks for your support.