• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

convert html string to formatted string in adobe acrobat DC

New Here ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Hey,

How to convert html string to formatted string in Adobe acrobat forms.

E.g. Input/ form field value is

<html>

     <body>

          <p>Hi</p>

          <b>Text1</b></br>

          <s>Text2</s>

          <p>end</p>

     </body>

</htm>

I want the output/display the form field value should be

Hi

Text1

Text2​ end

TOPICS
Acrobat SDK and JavaScript , Windows

Views

1.1K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Possible but very complicated. What you are looking for is Rich Text.  So, a PDF text field will accept an array of "Spans", where each span is a Rich Text object.  Spans are a very poor country cousin to HTML, so the options are limited.

Here's the reference entry.

Acrobat DC SDK Documentation

There are many more undocumented options.  Use Acrobat to enter formatted text in to a text field, then display the "spans" used to build it.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Thanks for your quick reply.

As i mentioned above my input is a formatted html string.

<p>Hi</p>

          <b>Text1</b></br>

          <s>Text2</s>

          <p>end</p>

In adobe java script i have to read each line and then convert into spans?. Let me know if my understanding is not correct.

If so is it possible to create spans for number formatted list and lists with bullet points?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

You are correct that the parser script has to read the HTML text and then convert it into spans.  However, like I said, the conversion options are limited. Read the reference entry!! 

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Okay. There are very few spans it supports. It wont support list formatting with bullets and number formatting too. I am not finding these in reference Doc.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Correct, but like I said earlier, there are several undocumented span options. If you set up a Rich Text field, you'll see there is a properties dialog that will display when text is selected. This dialog presents more options. use it to format text, then you can see how the underlying span objects are formed.

But before going too far down this path, what is it that you are trying to accomplish?  Maybe there is another way?

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

My requirement is, From my code i will get field values in html format. I have to parse and render them in pdf. Using Adobe acrobat DC i am using i am setting acrofields values but the values are in html format it is displaying as is instead parsing it because it is accepting the string as field values.

Like i said before,

my input will be html code(in string).

and output on the field value should be formatted string

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Does it need to be the exact format? Because that is not going to work for the standard solution.

However, there is another way if you restrict the solution to operating in Adobe Acrobat only.  You can use the Rich Media annotation to create an HTML window. I stopped working with this item nearly as soon as it came out because of compatibility and performance issues, so I don't know exactly how to achieve it. This object is programmed in Flash. I think there is a forum on it.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Yes i need it in exact format. And it should not be restricted to Adobe acrobat.

As you mentioned above

If you set up a Rich Text field, you'll see there is a properties dialog that will display when text is selected. This dialog presents more options. use it to format text, then you can see how the underlying span objects are formed.

Can you please give more details on this or please share if you have any examples. Because i am not finding anything like above. Please share where to find format text and then span objects in Adobe acrobat form fields.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

1) Add a text field to a PDF named "Text1"

2) In the text field properties, select the Options Tab

3) Check the "Allow Rich Text Formatting" check box

4) Get out of Prepare Form mode and Save file

5) Click into field to put focus on it

6)  Press Ctrl-E to display the Properties bar. The properties bar is slightly hidden.

Now, to see how the spans are organized,

1) Display Console Window.

2) Enter and run this code

     this.getField("Text1").richValue.toSource();

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

Remember you must parse according to the rules of HTML, it isn't in lines except by accident.

<htmL

><!--- some comment --><body><p

>Hi</p><b    >Text1 & 2</b>

and so on. A general HTML parser is a very ambitious project; browsers are years of work.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2019 Apr 03, 2019

Copy link to clipboard

Copied

Its true. Its complicated to convert that string into spans.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 03, 2019 Apr 03, 2019

Copy link to clipboard

Copied

Thank you.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

Hey Thom,

I tried the above steps which you have given to see the all span options. But still when i press Ctrl-E i am able to see the options which are there in documentation such as font, strike, underline ,.... But there is no option for number format and bullet format list. Can you please me exactly where can i see the list option.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 04, 2019 Apr 04, 2019

Copy link to clipboard

Copied

LATEST

If they are not on the Properties toolbar, then they probably don't exist. You can however create your own list formatting by using the span options that you know exist.

Thom Parker - Software Developer at PDFScripting
Use the Acrobat JavaScript Reference early and often

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 02, 2019 Apr 02, 2019

Copy link to clipboard

Copied

You will need to write your own HTML parser that generates Span objects.

It's not a simple task, at all.

On Tue, Apr 2, 2019, 20:44 bharanig38097311 <forums_noreply@adobe.com>

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines