High level methods for filling forms

105 views
Skip to first unread message

Stefano D'Amico

unread,
Jan 18, 2016, 2:01:45 AM1/18/16
to PDFHummus interest group
Hi Gal,
have you sample code on how to fill forms?

Best regards
Stefano

Gal Kahana

unread,
Jan 19, 2016, 6:59:23 AM1/19/16
to PDFHummus interest group
Hi Stefano,
i'm afraid that i don't have anything like this yet.
tell you what though, we are in the middle of a discussion about this in the github issues, and there are already code samples,
parhaps going through it will help you:

[and once we get through this i'll write something up].

Gal.

Stefano D'Amico

unread,
Jan 19, 2016, 4:42:25 PM1/19/16
to PDFHummus interest group
Awesome! Thanks Gal!

Stefano D'Amico

unread,
Feb 20, 2017, 9:00:57 AM2/20/17
to PDFHummus interest group
Hi,
I have a problem to set the font position of my acroform...

/Tx BMC 
BT
/Helv 9 Tf 0 g
0 g
2 3.1835 Td                      <---- I do not know calculate it!
(Hello world) Tj
ET
EMC

It depends on the alignment of the text (Left, Center, Right) 
Some idea?

Best Regards
Stefano

Gal Kahana

unread,
Feb 20, 2017, 9:05:39 AM2/20/17
to PDFHummus interest group
you can use the appearance stream bbox + compute the string width using the font widths array (or just do left align...)

--
You received this message because you are subscribed to a topic in the Google Groups "PDFHummus interest group" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pdfhummus-interest-group/PjrBg1JhRoo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pdfhummus-interest...@googlegroups.com.
To post to this group, send email to pdfhummus-in...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pdfhummus-interest-group/3559d99e-1683-4b9b-b128-8a9d26843758%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Stefano D'Amico

unread,
Feb 20, 2017, 1:16:12 PM2/20/17
to PDFHummus interest group
My code is...

...
ObjectIDType AP_id;
std::string xValue = "Hello World!";

PDFFormXObject* xobjectForm = pdfWriter.StartFormXObject(PDFRectangle(0,0,X,Y));   //X,Y are BBox dimensions (parameters obtained from Rect property of Acroform field)

const std::string font_file = "C:\\Work\\PDF-Writer\\PDF-Writer_src\\TestMaterials\\fonts\\arial.ttf";
PDFUsedFont* uFont = pdfWriter.GetFontForFile(font_file);
AbstractContentContext::TextOptions textOptions(uFont,9,AbstractContentContext::eGray,0);

// PDFUsedFont::TextMeasures tm = uFont->CalculateTextDimensions(xValue, 9);
XObjectContentContext* xobjectContentContext = xobjectForm->GetContentContext();

xobjectContentContext->WriteFreeCode("/Tx BMC \n");
xobjectContentContext->WriteText(2,3.1835,xValue,textOptions);    // To calculate!!!
xobjectContentContext->WriteFreeCode("EMC");
AP_id = xobjectForm->GetObjectID();
pdfWriter.EndFormXObjectAndRelease(xobjectForm);
return AP_id;  // /N 
..

Should I use CalculateTextDimensions() to calculate the length of the string?

To unsubscribe from this group and all its topics, send an email to pdfhummus-interest-group+unsub...@googlegroups.com.

Gal Kahana

unread,
Feb 20, 2017, 1:43:59 PM2/20/17
to PDFHummus interest group
If you have a PDFUsedFont instance then yeah, use it.

Stefano D'Amico

unread,
Feb 20, 2017, 1:52:05 PM2/20/17
to PDFHummus interest group
Thanks Gal, I will try it. :-)
Reply all
Reply to author
Forward
0 new messages