Do you own a Debenu Quick PDF Library version 7, 8, 9, 10, 11, 12, 13 or iSEDQuickPDF license? Upgrade to Debenu Quick PDF Library 14 today!
Populate rich text form field with formatted text |
Post Reply |
Author | |
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
Posted: 20 Feb 14 at 9:13AM |
Morning all. my app allows the user to modify a standard letter including bold and underlined text etc.
When I pass this info to the PDF using QP.SetFormFieldValue it only passes plain text and not the formatted rich text. As I have a RichTextBox in VB6 I can use .textRTF rather than just .text but this just then includes the actual RTF code, for example, {\rtf1\ansi\deff0{\fonttbl{\f0\fnil\fcharset0 Times New Roman;}} \viewkind4\uc1\pard\lang1033\f0\fs23 We thank you for your recent enquiry and are pleased to provide our quotation, drawings and job \par specification for the supply and delivery of the FleXaire cooling units and ancillaries described. Can anyone help with this problem? Many Thanks
|
|
Ingo
Moderator Group Joined: 29 Oct 05 Status: Offline Points: 3524 |
Post Options
Thanks(0)
|
Hi!
As far as i know form fields in QuickPDF only works with plain text. Sorry. Cheers, Ingo
|
|
Cheers,
Ingo |
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
I was running version 9.14 but found that in 9.15 a new function SetFormFieldRichTextString was added. I have updated to 9.16 now so I can access this new function but after trying it I am getting an empty form field.
There is limited documentation about this new function but I found this: The required format of the input string is defined in the PDF Specification under the section titled "Field Dictionaries"
I cannot find this though.
|
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
Does anyone else have any experience of using QP.SetFormFieldRichTextString in VB6 as I have tried everything and am still getting an empty form field in the pdf.
|
|
jpbro
Senior Member Joined: 29 Mar 11 Status: Offline Points: 77 |
Post Options
Thanks(0)
|
Can you post a small code sample that generates a PDF with a form field, and attempts to populate it? I can experiment here to see if I can find a solution for you.
|
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
Thank you, there is nothing mentioned in the developers guide and little anywhere else. My code doesn't create a new form but uses an existing template PDF with a form field added. I did it this way as I couldn't find how to set the properties of the form field to allow rich text editing.
Anyway the snippet that covers the filling of the field is this: Call QP.SetFormFieldRichTextString(1, "RV", LetterContent) The page only has a single form field for test purpose hence the '1' and the LetterContent is the variable that stores the rich text string. If you need the template pdf I could email it. Any help is greatly appreciated as this is the first problem I have not found a solution for.
|
|
jpbro
Senior Member Joined: 29 Mar 11 Status: Offline Points: 77 |
Post Options
Thanks(0)
|
Hi Andy, can you send me the sample PDF at jbrown "at" statslog.com?
|
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
Email sent, thank you.
|
|
jpbro
Senior Member Joined: 29 Mar 11 Status: Offline Points: 77 |
Post Options
Thanks(0)
|
What we've found so far (for anyone following), is that according to the PDF1.7 spec definition of "RichText", it appears to be different from what we might know as "RichText", or "RTF". PDF seems to be expecting a valid XML document, with support for some specific tags such as <i> and <b>.
I've been trying to get QPDF to take the example XML in the PDF spec as the value parameter for the SetFormFieldRichTextString method, but so far even that sample text taken directly from the spec doesn't show up in the form field. I've tried a bunch of variations too without success. Perhaps someone who has used the SetFormFieldRichTextString method successfully can provide a working example? |
|
AndrewC
Moderator Group Joined: 08 Dec 10 Location: Geelong, Aust Status: Offline Points: 841 |
Post Options
Thanks(0)
|
Hello, The easiest way to determine what format is required would be to set up a rich text formfield in Acrobat and then populate it with some text manually and then save the file. You should then use GetFormFieldRichTextString to retrieve the required XML string that is generated by Adobe. These two functions were originally added for a customer who needed to use it exactly this way. Setting up a formfield for RichText editing requires a whole lot of extra code to handle fonts, styles and the xml etc.. and a whole lot of documentation The PDF file format is very complex and there are areas of the PDF that Debenu Quick PDF Library (DQPL) currently doesn't support and this is one of those areas. Also DQPL doesn't have the functions required to generate the required appearance streams for rich text fields at the moment. ie. We don't have code to parse and render the XML. This may be why you say you cannot get it working. Once you have updated the XML you will currently need to load the file into Acrobat to have it update the appearance streams. We are continually adding new features to the library but because the specification is so large and complex we can't add everything and we don't have access to the hundreds of developers that Acrobat does. Andrew. |
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
Hi Andrew, I tried what you suggested, getting the xml string from an existing box with text, then firing the exact same string back to a second empty identical field, but unfortunately the bos remains empty. I can only assume there is some addtitional info I need to send to the field to get it to display.
If I can get the xml firing back correctly and displaying, then I can work on writing a module to convert the rtf string into the xml version.
|
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
Update:
I have succeeded in populating the pdf field with rich text. I used the GetFormFieldRichTextString to get some sample xml code, then as the SetFormFieldRichTextString wasn't working, I tried just using the SetFormFieldValue to send this code into the form field and it worked!! So now I just need to write a routine to convert RTF to XML.... I keep everyone posted.
|
|
jpbro
Senior Member Joined: 29 Mar 11 Status: Offline Points: 77 |
Post Options
Thanks(1)
|
I too have been unable to get the SetFormFieldRichTextString method to work, but calling SetFormFieldValue with valid PDF XML seems to work.
In case anyone needs a basic RTF to PDF Rich Text XML converter, I've done a bit of work on one in VB6. It handles paragraph alignment (left, right, center), font colours, font face and size, and bold, italic, and underline styles. Other RTF will just be ignored. I haven't tested it too extensively, so there may well be bugs, but it seems to be working pretty well so far. To use it, just pass a RichTextBox control to the RtfToPdfXml function, and pass the results to the SetFormFieldValue method of a QuickPdf object.
Edited by jpbro - 25 Feb 14 at 4:09PM |
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
Superb work and thank you. Now as the FlattenFormField removes formatting if we combine this code with making the form fields read only we end up with a secure formatted pdf with rich styling.
About to test it but looks like the strength of some members of this community has solved my problem. Many thanks |
|
jpbro
Senior Member Joined: 29 Mar 11 Status: Offline Points: 77 |
Post Options
Thanks(0)
|
Glad to have been of some help Andy, and hopefully our exploration might help others who need the same functionality in the future!
|
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
For all those interested, when I have chance I will create a sample VB6 app and supporting pdf using jp's excellent code and the required functions and post it in the sample code section.
So, in short, you can programatically populate rich text form fields with formatted text and save those pdf's with read only fields to create professional looking letters etc from within your app. |
|
jpbro
Senior Member Joined: 29 Mar 11 Status: Offline Points: 77 |
Post Options
Thanks(0)
|
Great Andy, I look forward to your extended example!
|
|
AndyD
Senior Member Joined: 30 Apr 13 Location: UK Status: Offline Points: 54 |
Post Options
Thanks(0)
|
Final Update:
With jpbro's help we have solved this problem and I have put together a sample VB6 app demonstrating how to do it. Full details can be found here: One final change was to restrict the use of the '&' symbol as this prevents the RTF2XML converter from functioning. If anyone has any feedback or suggestions it would be greatly received.
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |
Copyright © 2017 Debenu. Debenu Quick PDF Library is a PDF SDK. All rights reserved. About — Contact — Blog — Support — Online Store