Hello,
I'm attempting to implement stamp annotations in our application and I'm having an issue getting the image to display. I can create the annotation, but I'm having issues binding the image to it. Is there an example somewhere of how to get this working? I don't see one in the API documentation or in the demo apps.
Any help would be appreciated, thanks!
PdfRubberStampAnnotation Example
Moderator: Alex
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: PdfRubberStampAnnotation Example
Hello Mike,
The PdfAnnotation class has AppearanceGenerator property, which allows to get or set the appearance generator of annotation. For solving your task you need to create custom appearance generator. PDF Editor Demo has custom appearance generator for PDF signature field - the SignatureAppearanceGenerator class, which can be found in file "[InstallPath]\VintaSoft\Imaging .NET v9.0\Examples\WinForms\CSharp\PdfEditorDemo\DemosCommonCode.Pdf\AnnotationTool\FormFields\AppearanceGenerators\Signature\SignatureAppearanceGenerator.cs". Please try to create custom appearance generator for PDF annotation and let me know if you will have any question or problem.
Best regards, Alexander
The PdfAnnotation class has AppearanceGenerator property, which allows to get or set the appearance generator of annotation. For solving your task you need to create custom appearance generator. PDF Editor Demo has custom appearance generator for PDF signature field - the SignatureAppearanceGenerator class, which can be found in file "[InstallPath]\VintaSoft\Imaging .NET v9.0\Examples\WinForms\CSharp\PdfEditorDemo\DemosCommonCode.Pdf\AnnotationTool\FormFields\AppearanceGenerators\Signature\SignatureAppearanceGenerator.cs". Please try to create custom appearance generator for PDF annotation and let me know if you will have any question or problem.
Best regards, Alexander
-
- Posts: 56
- Joined: Mon Dec 02, 2019 11:19 pm
Re: PdfRubberStampAnnotation Example
That got me what I needed, thanks!
-
- Posts: 56
- Joined: Mon Dec 02, 2019 11:19 pm
Re: PdfRubberStampAnnotation Example
Hey Alex, I have a follow up question for you on this. Once I create the annotation, if I want to update the opacity of the image, how do I redraw it if I don't have access to the original image file?
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: PdfRubberStampAnnotation Example
Hello Mike,
Do you mean you do not know the background when you drawing an image? Please share more info about your problem.
Best regards, Alexander
Do you mean you do not know the background when you drawing an image? Please share more info about your problem.
Best regards, Alexander
-
- Posts: 56
- Joined: Mon Dec 02, 2019 11:19 pm
Re: PdfRubberStampAnnotation Example
Sure thing, what I'm trying to do is:
Create a stamp annotation with a custom image (Done).
<Do other things, doesn't matter what>
Come back to the stamp and change the opacity of the image without referencing the original file/clipboard data that was used to create the stamp.
I'm able to change the opacity value on the annotation, but when I try and redraw the image it's always blank. I haven't been able to find where (if anywhere) the ImageFigure is stored on the annotation object and I assume this is the issue but I would also assume the rendered image must be stored somewhere and I should be able to take that and re-render it but I am unable to find it.
Create a stamp annotation with a custom image (Done).
<Do other things, doesn't matter what>
Come back to the stamp and change the opacity of the image without referencing the original file/clipboard data that was used to create the stamp.
I'm able to change the opacity value on the annotation, but when I try and redraw the image it's always blank. I haven't been able to find where (if anywhere) the ImageFigure is stored on the annotation object and I assume this is the issue but I would also assume the rendered image must be stored somewhere and I should be able to take that and re-render it but I am unable to find it.
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: PdfRubberStampAnnotation Example
Thank you for information, we understood the problem. Please send us (to support@vintasoft.com) a small project, which demonstrates the problem - we will analyze your and provide the best solution for the problem.
Best regards, Alexander
Best regards, Alexander
-
- Posts: 56
- Joined: Mon Dec 02, 2019 11:19 pm
Re: PdfRubberStampAnnotation Example
I have sent a modified version of your PDFEditor demo that demonstrates the problem.
-
- Posts: 56
- Joined: Mon Dec 02, 2019 11:19 pm
Re: PdfRubberStampAnnotation Example
Thanks for the help dealing with this issue. It has been mostly resolved now but our QA team did manage to find one edge case.
When you take an image with no transparency on it, then reduce the opacity below 100% and then set it back to 100% the Vintasoft.Imaging.ImageProcessing.Color.SetAlphaChannelValueCommand.ExecuteInPlace call doesn't change the opacity. Using 99% works fine however. This appears to be an issue of setting an alpha value of 255. What is odd is that images with transparency on them to start with seem to work fine.
I will be sending an email to your support E-Mail with a relevant image and a code snippet, any help you could provide would be appreciated.
Thanks!
When you take an image with no transparency on it, then reduce the opacity below 100% and then set it back to 100% the Vintasoft.Imaging.ImageProcessing.Color.SetAlphaChannelValueCommand.ExecuteInPlace call doesn't change the opacity. Using 99% works fine however. This appears to be an issue of setting an alpha value of 255. What is odd is that images with transparency on them to start with seem to work fine.
I will be sending an email to your support E-Mail with a relevant image and a code snippet, any help you could provide would be appreciated.
Thanks!
-
- Site Admin
- Posts: 2397
- Joined: Thu Jul 10, 2008 2:21 pm
Re: PdfRubberStampAnnotation Example
Hello Mike,
Thank you for code snippet and images.
For solving the problem you need to use the code below in annotation appearance generator:
Best regards, Alexander
Thank you for code snippet and images.
For solving the problem you need to use the code below in annotation appearance generator:
Code: Select all
using (VintasoftImage image = imageResource.GetImage())
{
byte alpha = (byte)Math.Round(newOpacity * 255);
// if annotation does NOT have transparency
if (alpha == 255)
{
// remove the alpha channel
Vintasoft.Imaging.ImageProcessing.ChangePixelFormatCommand toBgr24 = new Vintasoft.Imaging.ImageProcessing.ChangePixelFormatCommand(PixelFormat.Bgr24);
toBgr24.ExecuteInPlace(image);
}
// if annotation has transparency
else
{
// set the alpha channel value
Vintasoft.Imaging.ImageProcessing.Color.SetAlphaChannelValueCommand setAlpha = new Vintasoft.Imaging.ImageProcessing.Color.SetAlphaChannelValueCommand(alpha);
setAlpha.ExecuteInPlace(image);
}
imageResource.SetImage(image, imageResource.Compression, new PdfCompressionSettings());
}