Free Support Forum - aspose.com

Scanned documents and background image

Hello,
i try to add a background image on scanned document but i cant see my image.
With a classic document, i see the picture.

This is my code

PdfFileInfo fileInfo = new PdfFileInfo(inFile);

Stamp aStamp = new Stamp();
aStamp.BindImage(imageFile);
aStamp.IsBackground = true;
//specifies the position of stamp
aStamp.SetOrigin(50, fileInfo.GetPageHeight(1) / 2);
//sizes the background
aStamp.SetImageSize(425, 250);
PdfFileStamp stamper = new PdfFileStamp(inFile, outFile);
stamper.AddStamp(aStamp);
stamper.Close();

I add in file attachment a PDF example.

Do you have a solution for my problem?

Thanks

Hi Julien,

If you set the IsBackground property of the Stamp class to false as shown below, the image will show on the scanned PDF:


aStamp.IsBackground = false;

I hope this helps. If you have any further questions, please do let us know.
Regards,

thanks shahzad its work but the picture is over the text :frowning:

so there is no solution to put the picture under the text? (remove background?)

Hi Julien,

I understand your concern and I have logged this issue as PDFKITNET-25127 in our issue tracking system. Our team will look into this issue in detail and you’ll be updated via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

thank you, what is the average response time?

Hi Julien,

I would like to share with you that response time for the resolution of the issues depends upon the number of issues already in the queue and the complexity of the current issue; however, I have asked our team to share the ETA of this issue. Please spare us some time for the initial investigation. You’ll be updated via this forum thread as soon as some response regarding the ETA is received.

We’re sorry for the inconvenience.
Regards,

Hi Julien,

Our team has looked into this issue in detail and I would like to share with you that the fix for this issue will be available at the end of July 2011. You’ll be notified via this forum thread once it is resolved.

We’re sorry for the inconvenience.
Regards,

Hi Julien,

The problem to set a background image in concrete scanned document
(probleme_fond.pdf) is bound with its specific structure. At first blush
we can think that probleme_fond.pdf contains text content but indeed it
contains non-transparent image as background and invisible text over.
In other words we can think that we see text but indeed we see raster
picture (to be sure just zoom in the document enough). So your code
works fine but you are unable to see the new background through opaque
old background.



Thus the problem here is not related to Aspose.Pdf for .NET but in this specific document. However you can achieve the positive result using code snippet shared below. The first part or it is the code that you have already shared and
the second part just make non-transparent raster image “some
transparent” so we can see new background. I have also attached the resultant PDF document that I have generated with upcoming release version of Aspose.Pdf for .NET 6.4.0 (which is expected to be released within this week). In case you have any further query, please feel free to contact.

[C#]
PdfFileInfo fileInfo = new PdfFileInfo(“d:/pdftest/probleme_fond.pdf”);
Aspose.Pdf.Facades.Stamp aStamp = new Aspose.Pdf.Facades.Stamp();
aStamp.BindImage(“d:/pdftest/aspose-logo.png”);
aStamp.IsBackground = true;
aStamp.SetOrigin(50, fileInfo.GetPageHeight(1) / 2);
aStamp.SetImageSize(425, 250);
PdfFileStamp stamper = new PdfFileStamp(“d:/pdftest/probleme_fond.pdf”, “d:/pdftest/probleme_fond-updated.pdf”);
stamper.AddStamp(aStamp);
stamper.Close();

// Adding some transparency for previous background image.
Document doc = new Document(“d:/pdftest/probleme_fond-updated.pdf”);
foreach (Page page in doc.Pages)
{
MemoryStream msIn = new MemoryStream();
page.Resources.Images[1].Save(msIn);
Bitmap bitmap = new Bitmap(msIn);
Bitmap newBitmap = new Bitmap(bitmap.Width, bitmap.Height);
for (int y = 0; y < bitmap.Height; y++)
for (int x = 0; x < bitmap.Width; x++)
{
System.Drawing.Color color = bitmap.GetPixel(x, y);
if (color.R <= 200 && color.G <= 200 && color.B <= 200)
newBitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(255, 0, 0, 0));
else
newBitmap.SetPixel(x, y, System.Drawing.Color.FromArgb(0, 0, 0, 0));
}
MemoryStream msOut = new MemoryStream();
newBitmap.Save(msOut, System.Drawing.Imaging.ImageFormat.Tiff);
page.Resources.Images.Replace(1, msOut);
}
doc.Save(“d:/pdftest/probleme_fond-Final.pdf”);

The issues you have found earlier (filed as 25127) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.