Add Image in an Existing PDF File using C# with Aspose.PDF for .NET

Hi,

Currently i am closely following the example provided in "Add Image in an Existing PDF File (Facades)"

Here are the sample of the codes :

float lowerLeftX = 510.5F;
float lowerLeftY = 21F;
float upperRightX = 681F;
float upperRightY = 33F;

for (int i = 0; i < 4; i++)
{

mender = new PdfFileMend();
mender.BindPdf("input.pdf");

float lLeftX = lowerLeftX + (i * distance);
float lLeftY = lowerLeftY;
float uRightX = upperRightX + (i * distance);
float uRightY = upperRightY;

bool returnValue = mender.AddImage(@"C:\Image.jpg", 1, lowerLeftX, lowerLeftY, upperRightX, upperRightY);

if (!returnValue)
{
throw new Exception("Exception");
}

mender.Save("output.pdf");


mender.Close();


}

Basically my objective is to draw a series of 8 vertical lines using a custom logic. In this example, i have simplified it by just drawing 4 series of vertical lines.

Apparently the code can only draw up until 4 vertical lines. At the fifth execution, the AddImage method returns the false value. I am not sure why it returns the false value.

For your information, i have independently drawn the lines at the designated coordinate and it works properly.

I guessed that there is a limitation in opening and closing the PdfFileMend, please correct me if i am wrong.

Regards,

hadi teo

Hi Hadi,

Thank you for the details.

It seems that you are facing an evaluation restriction. In evaluation mode (without a license), only 4 items are allowed from any collection to be processed. To avoid such evaluation restrictions, I would suggest you to request a free temporary license for 30 days and evaluate your required features. Please visit the following link for further details on How to get a temporary license.

Also, I have modified your code as below:

// create a Pdf license object

Aspose.Pdf.License licensePDF = new Aspose.Pdf.License();

// instantiate license file

licensePDF.SetLicense("D:\\AP Data\\Aspose.Total.lic");

float lowerLeftX = 510.5F;

float lowerLeftY = 21F;

float upperRightX = 681F;

float upperRightY = 33F;

PdfFileMend mender = new PdfFileMend();

mender.BindPdf("input.pdf");

for (int i = 0; i < 6; i++)

{

float lLeftX = lowerLeftX + (i * distance);

float lLeftY = lowerLeftY;

float uRightX = upperRightX + (i * distance);

float uRightY = upperRightY;

bool returnValue = mender.AddImage("image.jpg", 1, lLeftX, lLeftY, uRightX, uRightY);

if (!returnValue)

{

throw new Exception("Exception");

}

}

mender.Save("output.pdf");

mender.Close();

Please feel free to contact support in case you have any query.

Thank You & Best Regards,