EldoS | Feel safer!

Software components for data protection, secure storage and transfer

How to change pdf sign image in C++ application

Also by EldoS: CallbackProcess
A component to control process creation and termination in Windows and .NET applications.
#33286
Posted: 05/11/2015 09:13:50
by Burak Dağlı (Basic support level)
Joined: 03/03/2015
Posts: 8

Hi,

I tried to change pdf sign image in C++ application, but I could not be success. I wrote code as follow, but image was not changed.


Code
QImage tmp("eimza.JPG");
            std::vector<uint8_t> * vector_ = new std::vector<uint8_t>;

            for (unsigned i=0; i<tmp.width(); ++i)
            {
               for (unsigned j=0; j<tmp.height(); ++j)
                   vector_->push_back((uint8_t)tmp.pixel(i,j));
            }

            TElPDFImage *Image = new TElPDFImage();
            Image->set_Data(*vector_);
            Image->set_Height(tmp.height());
            Image->set_Width(tmp.width());
            Image->set_ImageType(pitCustom);
            Image->set_ColorSpaceType(pcstRGB);
            TElPDFSignatureWidgetProps *widgetProps = Sig->get_WidgetProps();
            widgetProps->ClearImages();
            widgetProps->AddImage(Image);


#33287
Posted: 05/11/2015 09:19:19
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

Please try to set TElPDFSignatureWidgetProps.BackgroundStyle to pbsCustom value.

I’ve noticed there is no license ticket linked to your user account on EldoS site. Technical Support is provided to customers with the linked license tickets. You will find your license ticket together with all the details about how to use it in the registration e-mail that we’ve sent to you upon the purchase.

If you are evaluating the product and don't have a license yet, please let us know and then you can have support according to Basic support level. Basic support level includes answering basic technical questions that appear during product evaluation period.
#33288
Posted: 05/11/2015 09:24:15
by Dmytro Bogatskyy (EldoS Corp.)

Thank you for contacting us.

Quote
widgetProps->AddImage(Image);

The AddImage() method adds a foreground image. Without offset and size parameters the AddImage() method adds the image into the pdf document that could be used later using its resource name (in your code it is not used).

For the background image you would need to use appropriate properties TElPDFSignatureWidgetProps.Background and BackgroundStyle, please refer to the article for details: https://www.eldos.com/documentation/sb...round.html
#33292
Posted: 05/13/2015 03:01:19
by Hamdi Yilmaz (Standard support level)
Joined: 05/11/2015
Posts: 3

Hi,

I tried to this case, but image wasn't showed. I suspected whether background properties are worked. Also, I saw that background properties are not implemented for C++ in documentation. https://www.eldos.com/documentation/sbb/documentation/ref_cl_pdfsignaturewidgetprops_prp_background.html

My code

Code
      QImage tmp("eimza.JPG");
            std::vector<uint8_t> * vector_ = new std::vector<uint8_t>;

            for (unsigned i=0; i<tmp.width(); ++i)
            {
               for (unsigned j=0; j<tmp.height(); ++j)
                   vector_->push_back((uint8_t)tmp.pixel(i,j));
            }

            TElPDFSignatureWidgetProps *widgetProps = Sig->get_WidgetProps();
            widgetProps->set_BackgroundStyle(pbsCustom);
            widgetProps->get_Background()->set_Height(tmp.height());
            widgetProps->get_Background()->set_Width(tmp.width());
            widgetProps->get_Background()->set_Data(*vector_);
            widgetProps->get_Background()->set_ImageType(pitJPEG);
            widgetProps->get_Background()->set_ColorSpaceType(pcstCMYK);
            widgetProps->set_AutoStretchBackground(true);
#33293
Posted: 05/13/2015 03:34:26
by Dmytro Bogatskyy (EldoS Corp.)

Hello,

Quote

widgetProps->get_Background()->set_ImageType(pitJPEG);
widgetProps->get_Background()->set_ColorSpaceType(pcstCMYK);

The image type pitJPEG expect the raw jpeg data (simply the contents of "eimza.JPG" file). And I think, the color space type should be pcstRGB (it is common for jpeg format).
If you want to set the image data pixel by pixel (like you do, for example, pcstRGB color space type should occupy 3 bytes for each pixel) then you should set the image type property to pitCustom value.
#33294
Posted: 05/13/2015 03:53:29
by Hamdi Yilmaz (Standard support level)
Joined: 05/11/2015
Posts: 3

I had tried pitRGB type and pitCustom, but result was not changed. I dont want to set pixel by pixel specially. Only I want to set any image. If you have a example for C++, can you share example?
#33295
Posted: 05/13/2015 05:05:25
by Dmytro Bogatskyy (EldoS Corp.)

Hello,

Quote
If you have a example for C++, can you share example?

Here it is the sample code for loading and setting jpeg image:
Code
std::ifstream img;
img.open("test.jpg", std::ios::binary | std::ios::in);
if (!img.is_open())
{
   std::cout << "Unable to open file" << std::endl;   
   return;
}

std::vector<uint8_t> buf;

std::noskipws(img);
img.seekg(0, img.end);
buf.resize((int)img.tellg());
img.seekg(0);
img.read((char *)&buf.front(), buf.size());

TElPDFSignatureWidgetProps *widgetProps = Sig->get_WidgetProps();
widgetProps->set_BackgroundStyle(pbsCustom);
widgetProps->get_Background()->set_Width(100); // set the actual image dimension
widgetProps->get_Background()->set_Height(100);
widgetProps->get_Background()->set_Data(buf);
widgetProps->get_Background()->set_ImageType(pitJPEG);
#33296
Posted: 05/13/2015 06:16:13
by Hamdi Yilmaz (Standard support level)
Joined: 05/11/2015
Posts: 3

thank you very much
Also by EldoS: Callback File System
Create virtual file systems and disks, expose and manage remote data as if they were files on the local disk.

Reply

Statistics

Topic viewed 906 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!