Embed a PDF page into a PDF form (field) ?

A forum for questions or concerns related to the PDF-XChange Core API SDK

Moderators: TrackerSupp-Daniel, Tracker Support, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Tracker Supp-Stefan

Forum rules
DO NOT post your license/serial key, or your activation code - these forums, and all posts within, are public and we will be forced to immediately deactivate your license.

When experiencing some errors, use the IAUX_Inst::FormatHRESULT method to see their description and include it in your post along with the error code.
Post Reply
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Embed a PDF page into a PDF form (field) ?

Post by whoit »

Is is possible, using any of the Tracker libraries, to embed a PDF page into a field in a different PDF document (form) ?

For example, I have a PDF Form that includes a few text fields,
and I'd like to use another field to contain a pdf page from another document
(kind of like a screenshot - however I do NOT want the image to be bitmap)

Thanks,
Wayne
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Sasha - Tracker Dev Team »

Hello whoit,

We did not quite understand what do you want. Can you provide more detailed description and a picture of what you want?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: Embed a PDF page into a PDF form (field) ?

Post by whoit »

I need to be able to open a PDF document (1), and also open a PDF Form (2).
Then I need to take a page from the PDF Document (1) and insert it into a Button Field (as an Icon)
within the PDF Form (2).

I have provided a sample graphic and form.
Attachments
sample.pdf
Sample - open, click the button on the page. Select a PDF to add it to the button as an icon. In need to do this in code.
(102.98 KiB) Downloaded 199 times
pdf template option.pdf
Graphic explanation.
(64.86 KiB) Downloaded 201 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Sasha - Tracker Dev Team »

Hello whoit,

Now that's what i call a detailed sample :D
What you want is doable, though should be available from the next release when the work with forms should be updated.
The steps should be the following:
1) https://sdkhelp.pdf-xchange.com/vie ... ieldByName
2) https://sdkhelp.pdf-xchange.com/vie ... eld_Widget
3) https://sdkhelp.pdf-xchange.com/vie ... Annotation
4) https://sdkhelp.pdf-xchange.com/vie ... ation_Data
of this type
https://sdkhelp.pdf-xchange.com/vie ... ata_Widget
And the final step will be this:
https://sdkhelp.pdf-xchange.com/vie ... et_SetIcon

HTH,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: Embed a PDF page into a PDF form (field) ?

Post by whoit »

Alex - Glad you liked it! (don't get used to it! :wink: )

Ok so now I have some follow-up questions:

(You didn't think I was done, did you?? :) )

Is there any way to do this in the current version of the libs?
(Perhaps a different kind of form field?
or adding the image via disk file instead of opening into Tracker libs first?)

So of course the next question is: when the release supporting this be available?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Sasha - Tracker Dev Team »

Well, you can try doing that by using the code links that I've post (I think that code is available right now). If something does not work - the release will be at a week or so - Stefan wrote you in another thread (we update all of our products at once - they have the same Core).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
whoit
User
Posts: 269
Joined: Tue Jul 07, 2015 3:30 pm

Re: Embed a PDF page into a PDF form (field) ?

Post by whoit »

Great - we'll give it a try.

Thanks again!
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Embed a PDF page into a PDF form (field) ?

Post by mmasood »

Hi Alex,

I am following the steps that you mentioned the post above but need some help completing the last step.

Following is the code that I have:

Code: Select all

PDFXEdit.IPXC_FormField field = pdfControlInvisible.Doc.CoreDoc.AcroForm.GetFieldByName(fld.FieldName);

PDFXEdit.IPXC_Annotation annotation = field.get_Widget(0);

IPXC_AnnotData_Widget annotdata = (IPXC_AnnotData_Widget)annotation.Data;

// open a pdf that is to be set on the first document
pdfEditor.OpenDocFromPath(@"SP.pdf");
                        
annotdata.SetIcon(PXC_AnnotAppType.AAT_Normal, pdfEditor.Doc.CoreDoc.GetXForm([color=#FF0000]???[/color]), false);
Questions:

1. Is this the approach that you are talking about?
2. What should I pass to the GetXForm function?

Regards,
M
User avatar
Tracker Supp-Stefan
Site Admin
Posts: 17824
Joined: Mon Jan 12, 2009 8:07 am
Location: London
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Tracker Supp-Stefan »

Hello M Masood,

Sasha mentioned above that this process will work from next build onwards, but he is currently investigating if it can be achieved with the current one as well. He will post in the topic later if he has further advise for how to do it with the available tools.

Cheers,
Stefan
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Sasha - Tracker Dev Team »

Hi guys,

So we've tried with different methods and it appears that not enough functionality was available through the SDK interfaces. We've added the CreateXFormFromPage method to the IPXC_Document interface that will be available from the next release (317) that should be out in a week or so if everything goes as planned.
Thus using this method will allow to convert given page in the source document into an XForm in the destination document. And then using the SetIcon method the widget's icon will be modified.

HTH,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Embed a PDF page into a PDF form (field) ?

Post by mmasood »

Hi Alex,

I have downloaded the latest build and updated the code to below:

Code: Select all

PDFXEdit.IPXC_FormField field = pdfControl1.Doc.CoreDoc.AcroForm.GetFieldByName("button");

PDFXEdit.IPXC_Annotation annotation = field.get_Widget(0);

IPXC_AnnotData_Widget annotdata = (IPXC_AnnotData_Widget)annotation.Data;

// open a pdf that is to be set on the first document                        
pdfControl2.OpenDocFromPath(@"SP.pdf");

IPXC_Page page1 = pdfControl2.Doc.CoreDoc.Pages[0];

IPXC_XForm xform = pdfControl2.Doc.CoreDoc.CreateXFormFromPage(page1);

annotdata.SetIcon(PXC_AnnotAppType.AAT_Normal, xform, false);

I am getting the exception "Value does not fall within the expected range." on the last line.

How do I fix this issue?

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

This code works for me with your sample. Here's my code:
https://gist.github.com/Polaringu/f661a5af12c8fbf7e7fd

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Embed a PDF page into a PDF form (field) ?

Post by mmasood »

Hi Alex,

I am trying the code that you provided. It does not give me an exception but does not do anything either. There is no icon added to the button after the process is done. I have attached a sample project with the post. Is there something missing in the code that is causing the issue?

Regards,
M
Attachments
clStampingPDF.rar
(851.23 KiB) Downloaded 193 times
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

The code worked correctly, but you'll need to change the widget's layout type (set it to show the icon):
https://gist.github.com/Polaringu/f661a ... con-cs-L13

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
mmasood
User
Posts: 101
Joined: Fri Sep 18, 2015 9:49 pm

Re: Embed a PDF page into a PDF form (field) ?

Post by mmasood »

Hi Alex,

I am trying to run the updated code (with the line that you added) and it is doing nothing. Just creates a PDF file with nothing set as the button icon. I also tried it with a new PDF Form but still the same thing.

Regards,
M
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: Embed a PDF page into a PDF form (field) ?

Post by Sasha - Tracker Dev Team »

Hello mmasood,

The strange thing is that this is working correctly when you have one Editor ActiveX Control with multiple documents opened and also works well on the Core API level - when you open two IPXC_Document.
But when you have two different Controls then this issue occurs - that's what I investigated. Right now I can't say why does this behaves like this, though I've managed to find a strange solution described here:
https://gist.github.com/Polaringu/36072 ... t-cs-L2-L4

HTH,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Post Reply