C# code to fill a PDF form

PDF-XChange Editor SDK for Developers

Moderators: TrackerSupp-Daniel, Tracker Support, Paul - Tracker Supp, Vasyl-Tracker Dev Team, Chris - Tracker Supp, Sean - Tracker, Ivan - Tracker Software, 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.
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

C# code to fill a PDF form

Post by Nisha »

Hi guys, I am new to this library I need c# code to fill a PDF form to fulfill one of our client requirement.

Update
I referred some developer forum and found this code and modified as per my requirement. My objective is to enter some value through code in PDF form field named company. But when I execute the following code it is not printing the value in the form field. Please let me know what must be done to achieve my objective.

Code: Select all

                PDFXEdit.IPXV_Inst pxvInst;
                PDFXEdit.IPXC_Inst pxcInst;

                PDFXEdit.pxvInst = new PXV_Inst();
                PDFXEdit.pxvInst.Init();
                PDFXEdit.pxcInst = (PDFXEdit.IPXC_Inst)pxvInst.GetExtension("PXC");

                PDFXEdit.IPXC_Document pDoc = pxcInst.OpenDocumentFromFile(inputPDF, null);

                if (pDoc.HasAcroForm)
                {
                    PDFXEdit.IPXC_FormField ff = pDoc.AcroForm.GetFieldByName("Company");
                    int nID = pxvInst.Str2ID("op.fields.modify", false);
                    PDFXEdit.IOperation pOp = pxvInst.CreateOp(nID);
                    PDFXEdit.ICabNode input = pOp.Params.Root["Input"];
                    input.Add().v = ff;
                    PDFXEdit.ICabNode options = pOp.Params.Root["Options"];
                    options["Mask"].v = 0x00000100; // Value modification
                    options["Value.Value"].v = "Hello";
                    pOp.Do();
                  }
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Please post in the correct forum thread so that we can reply you on a much faster scale. This should be in the Editor SDK forum.
As for your question. For starters, let's understand whether you are using the IPXV_Control (like in our FullDemo application sample) or do you need this to be done without the UI interaction via the Operations only? If you are using the IPXV_Control and you want to modify the opened document directly, then you will have to pass the document opened in the Control (the IPXV_Document) to the operation and then you will see the results. Another way is opening the IPXC_Document, modifying it with the operation and then opening it in the Control.
If you don't have the IPXV_Control, then you will have to open the IPXC_Document, modify it with the Operation and then save the document with the WriteTo/WriteToFile method.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

My apology to post it in different forum, I want to do the above thing without the UI interaction and I tried adding writeTo function but its not working. Hence I am reposting this to Editor SDK forum.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

I will move the forum post.
Have you checked the FullDemo sample project? Also, please read this first:
https://sdkhelp.pdf-xchange.com/view/PXV:CoClasses

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Sorry, but I did refer Full Demo sample project but I feel that I am missing out on something. Can you please provide some sample program..
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

If you do have the FullDemo sample, then you should see that the opening of the documents on UI level (IPXV_Document) should be done via the https://sdkhelp.pdf-xchange.com/vi ... ocFromPath method or by using the Control's standard Open Command.
Then you can access it by https://sdkhelp.pdf-xchange.com/vi ... ontrol_Doc property and pass it to the operation that you have mentioned.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

But I want to fill the form without UI
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

My bad, though you needed the UI. Can you give me a code sample that is not working for you (WriteTo should of solved the problem).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

This is the code which is not working. Please let me know what I am missing...

Code: Select all

IPXV_Inst pxvInst;
IPXC_Inst pxcInst;

pxvInst = new PXV_Inst();
pxvInst.Init(null, devkey);  // devkey is a string variable that has license key
pxcInst = (IPXC_Inst)pxvInst.GetExtension("PXC");

IPXC_Document pDoc = pxcInst.OpenDocumentFromFile(inputPDF, null); \\ inputPDF is string variable where I have specified my PDF file path
if (pDoc.HasAcroForm)
{
                 
    IPXC_FormField ff = pDoc.AcroForm.GetFieldByName("Company");
    int nID = pxvInst.Str2ID("op.fields.modify", false);
    IOperation pOp = pxvInst.CreateOp(nID);
    ICabNode input = pOp.Params.Root["Input"];
    input.Add().v = ff;
    ICabNode options = pOp.Params.Root["Options"];
    options["Mask"].v = 0x00000100; // Value modification
    options["Value.Value"].v = "Hello";
    pOp.Do();
}
pDoc.WriteToFile(inputPDF);
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

What I see is that you are missing pDoc.Close(); because the same code works for me in the FullDemo environment.
The steps should be as followed: 1) Open document 2) Modify Document 3) Write Document to file 4) Close document 5) Open document with PDF Editor (or other viewer).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

I added pDoc.close to my code but still it is not working. Can you please send me an example project demonstrating the same...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

I've made a sample and indeed, in the case of the non-UI usage (there is no IPXV_Document) the logic is somewhat different and does not work as it is intended to.
For now, you can use this as a workaround - in your case this should be the same:

Code: Select all

ff.SetValueText("New Text");
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

I have added ff.SetValueText("Hello"); immediately after this line:

IPXC_FormField ff = pDoc.AcroForm.GetFieldByName("Company");

But still it is not working...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Here's my sample project that works:
FieldsModifySample_Simplified.zip
(13.71 KiB) Downloaded 107 times
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Thankyou, its working :)

Can you please provide me some tutorial/ working example that would help me create acroform without UI consisting of text field. Or should I create a new post for this.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Well here's a snippet on how to do this with some properties/styles that you might require:

Code: Select all

PDFXEdit.IPXC_Document coreDoc = pxcInst.NewDocument();
PDFXEdit.PXC_Rect rc;
rc.left = 0;
rc.right = 500;
rc.top = 800;
rc.bottom = 0;
PDFXEdit.IPXC_UndoRedoData urd;
coreDoc.Pages.AddEmptyPages(0, 1, ref rc, null, out urd);
rc.left = 10;
rc.right = 100;
rc.top = 100;
rc.bottom = 10;
PDFXEdit.IPXC_FormField ff = coreDoc.AcroForm.CreateField("txtEsempio", PDFXEdit.PXC_FormFieldType.FFT_Text, 0, ref rc);
ff.SetFlags(0, (uint)PDFXEdit.PXC_FormFieldFlag.TFF_MultiLine);
ff.SetFlags((uint)PDFXEdit.PXC_FormFieldFlag.TFF_DoNotScroll, (uint)PDFXEdit.PXC_FormFieldFlag.TFF_DoNotScroll);
ff.SetFlags((uint)PDFXEdit.PXC_FormFieldFlag.TFF_Comb, (uint)PDFXEdit.PXC_FormFieldFlag.TFF_Comb);
PDFXEdit.IPXC_Annotation widget = ff.Widget[0];
PDFXEdit.IPXC_AnnotData aData = widget.Data;
PDFXEdit.IPXC_AnnotData_Widget aWData = (PDFXEdit.IPXC_AnnotData_Widget)aData;
var color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
color.SetRGB(0.0f, 1.0f, 1.0f);
aWData.FColor = color;
color.SetRGB(0.0f, 1.0f, 0.0f);
aWData.SColor = color;
widget.Data = aWData;
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

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

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

If an acroform has multiline text field that how do we write text in new line using c# code.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Well, just use the new line character - that's all.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Sorry, but do I need to add new line char in the line where i set the text.

ff.SetValueText("New Text");
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Code: Select all

ff.SetValueText("New\nText");
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Thank you :)
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Can I change the color of the text which we add to text field ? If yes then how this can be done...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

You can set the default text color with the IPXC_AnnotData_Widget::DefaultTextColor property.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

I am trying the following code to change the text color of the value entered through code in text field

IColor color = null;
color.SetRGB(0.0f, 0.0f, 0.8f);
pXC_AnnotData.DefaultTextColor = color;

I am not able to put appropriate defination on the following line:
IColor color = null;

Can you please help...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Here's a solution:
viewtopic.php?p=125177#p125070
Also, here's a link to the IColor documentation, where you can see the See Also section that can help you find the method that can create/initialize this or that interface, or methods where the interface is being used:
https://sdkhelp.pdf-xchange.com/view/PXV:IColor

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Sorry for missing the code snippet you shared earlier, I have shared my code it is not throwing any error but it is still not changing the color of the text. Is it because I have set ff.Widget[0] is the Widget Id similar to field Id. Please explain with an example if possible...

IPXC_FormField ff = pDoc.AcroForm.GetFieldByName("Bill ToRow1");
ff.SetValueText("XYZ Company 12345678910\n 201 Broadstreet 1234567810");

IPXC_Annotation widget = ff.Widget[0];
IPXC_AnnotData aData = widget.Data;
IPXC_AnnotData_Widget aWData = (PDFXEdit.IPXC_AnnotData_Widget)aData;

IColor color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
color.SetRGB(0.0f, 0.0f, 0.8f);
aWData.DefaultTextColor = color;


pDoc.WriteToFile(inputPDF);

pDoc.Close();
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Refer to the sample that I gave you again and see whether you have done everything as it shows (as a tip - look at the bottom of it).

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Thankyou so much for the tip, it worked :)
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

:)
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

I used the below code to change the font of the text entered in text field. But nothing happens..

uint fontWeight = 700;
IPXC_Font pdfFont = pDoc.CreateNewFont("Verdana", 0, fontWeight);
aWData.DefaultFont = pdfFont;

Is there anything else that I am missing ?
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Can you provide a fully working code sample project (do not forget to remove your key if you have one) so I can see where the problem is exactly.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Below is my working example

IPXV_Inst pxvInst;
IPXC_Inst pxcInst;

pxvInst = new PXV_Inst();
pxvInst.Init(null, devKey);
pxcInst = (IPXC_Inst)pxvInst.GetExtension("PXC");
IAUX_Inst auxInst = (IAUX_Inst)pxvInst.GetExtension("AUX");

IPXC_Document pDoc = pxcInst.OpenDocumentFromFile(inputPDF, null);

if (pDoc.HasAcroForm)
{
IPXC_FormField ff = pDoc.AcroForm.GetFieldByName("Bill ToRow1");
ff.SetValueText("XYZ Company 12345678910\n 201 Broadstreet 1234567810");

IPXC_Annotation widget = ff.Widget[0];
IPXC_AnnotData aData = widget.Data;
IPXC_AnnotData_Widget aWData = (PDFXEdit.IPXC_AnnotData_Widget)aData;

IColor color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
color.SetRGB(0.0f, 0.0f, 0.8f);
aWData.DefaultTextColor = color;

uint fontWeight = 700;
IPXC_Font pdfFont = pDoc.CreateNewFont("Verdana", 0, fontWeight);
aWData.DefaultFont = pdfFont;
widget.Data = aWData;

pDoc.WriteToFile(inputPDF);
pDoc.Close();
}
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

That is a code snippet not a project. Also, what exactly do you mean by nothing happens?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

This is it I have in my project. I am trying to enter some data in text field and I am trying to change the color and font of the data that I am going to programmatically enter in the text field. At present I am able to change the color of the text but I am not able to able the change the font of the text. If I specify font name as "Verdana" in my code and try executing the code the font of the text is not changed to "Verdana"...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Is the font weight being changed? Try getting the default font, setting it's weight and then setting the default font.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Yes, I want to programmatically change Font Name, weight and size. I tried changing font weight by using DefaultFontSize but it did'nt change the size of default font. Please help.
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Well you are setting the text before changing the font parameters, thus the expected result.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

I tried changing the font parameters before setting the text but still the font is not changed. Please correct me below is my code.

IPXC_FormField ff = pDoc.AcroForm.GetFieldByName("Bill ToRow1");
IPXC_Annotation widget = ff.Widget[0];
IPXC_AnnotData aData = widget.Data;
IPXC_AnnotData_Widget aWData = (PDFXEdit.IPXC_AnnotData_Widget)aData;
IPXC_Font pdfFont = pDoc.CreateNewFont("Cambria", 0, 1000);
aWData.DefaultFont = pdfFont;
ff.SetValueText("XYZ Company 12345678910\n201 Broadstreet 1234567810");
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Code: Select all

PDFXEdit.IPXC_FormField ff = coreDoc.AcroForm.CreateField("txtEsempio", PDFXEdit.PXC_FormFieldType.FFT_Text, 0, ref rc);
ff.SetFlags(0, (uint)PDFXEdit.PXC_FormFieldFlag.TFF_MultiLine);
ff.SetFlags((uint)PDFXEdit.PXC_FormFieldFlag.TFF_DoNotScroll, (uint)PDFXEdit.PXC_FormFieldFlag.TFF_DoNotScroll);
ff.SetFlags((uint)PDFXEdit.PXC_FormFieldFlag.TFF_Comb, (uint)PDFXEdit.PXC_FormFieldFlag.TFF_Comb);
PDFXEdit.IPXC_Annotation widget = ff.Widget[0];
PDFXEdit.IPXC_AnnotData aData = widget.Data;
PDFXEdit.IPXC_AnnotData_Widget aWData = (PDFXEdit.IPXC_AnnotData_Widget)aData;
var color = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
color.SetRGB(0.0f, 1.0f, 1.0f);
aWData.FColor = color;
color.SetRGB(0.0f, 1.0f, 0.0f);
aWData.SColor = color;
aWData.DefaultFont = coreDoc.CreateNewFont("Cambria", 0, 1000);
aWData.DefaultFontSize = 50;
ff.SetValueText("XXXXXX");
widget.Data = aWData;,
Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

I referred the code snippet and tried the following but still it is not changing the font nor the font size.

IPXC_FormField ff = pDoc.AcroForm.GetFieldByName("Bill ToRow1");
IPXC_Annotation widget = ff.Widget[0];
IPXC_AnnotData aData = widget.Data;
IPXC_AnnotData_Widget aWData = (PDFXEdit.IPXC_AnnotData_Widget)aData;
IColor Icolor = auxInst.CreateColor(PDFXEdit.ColorType.ColorType_RGB);
Color color = Color.FromName("Green");
Icolor.SetRGB(GetFloatFormat(color.R), GetFloatFormat(color.G), GetFloatFormat(color.B));
aWData.DefaultTextColor = Icolor;
aWData.DefaultFont = pDoc.CreateNewFont("Verdana", 0, 700);
aWData.DefaultFontSize = 150;
ff.SetValueText("XYZ Company 12345678910\n201 Broadstreet 1234567810");
widget.Data = aWData;
pDoc.WriteToFile(inputPDF);
pDoc.Close();
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

How are you checking that? Use the Select Fields tool to select a field and then open it's properties - should be the values that you are setting.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Pardon me if I am wrong, but I am not using UI...
Through code I am trying to enter some value in text field and I am trying to change the font properties and text color along with it. At present I am only able to change text color but I am not able to change the font. If possible can you please share some example...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

I'm talking about opening the resulting file with the PDF Editor and seeing the results, not using the SDK UI.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

I tried opening the resultant file from PDF Editor and in that I can see that it had changed the font...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

That's great.

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Sorry for the late reply, thanks for your workaround but I was wondering why the font remains unchanged if see the resultant file in microsoft edge even the font color change is visible but the problem is only when the font changes...
Sasha - Tracker Dev Team
User
Posts: 5522
Joined: Fri Nov 21, 2014 8:27 am
Contact:

Re: C# code to fill a PDF form

Post by Sasha - Tracker Dev Team »

Hello Nisha,

Can you provide screenshots of this, so that I can understand better?

Cheers,
Alex
Subscribe at:
https://www.youtube.com/channel/UC-TwAMNi1haxJ1FX3LvB4CQ
Nisha
User
Posts: 43
Joined: Tue May 22, 2018 9:31 am

Re: C# code to fill a PDF form

Post by Nisha »

Hi,

Please refer the attachments
Attachments
domain-name-invoice-template_test.pdf
Original PDF file
(1.71 MiB) Downloaded 73 times
PDF file shown in Microsoft Edge
PDF file shown in Microsoft Edge
PDF file shown in Adobe Reader
PDF file shown in Adobe Reader
Post Reply