最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

pdf - iText7 MergeToPdf from XFDF not supporting <value-richtext> tag - Stack Overflow

programmeradmin1浏览0评论

We used iTextSharp to Merge XFDF into PDF.

iTextSharp recognized the <value-richtext> tag and did things like BOLD the text.

iText7 does not support applying the <value-richtext> tag when calling MergeToPdf()

We need this in order to BOLD the field Value.

Here is an example:

<field name="_001_STATEMENT_LINE_ITEM_DESCRIPTION">
  <value-richtext>
    <body xmlns="; xmlns:xfa=".0/" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1">
      <p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;text-valign:middle;font-family:Helvetica;font-size:8pt;font-weight:bold">Donald Duck</p> 
    </body>
  </value-richtext>
</field>

The <value-richtext> tag is something Adobe allows and performs inherently.

Setting the bold property for the field directly in the PDF is NOT an option as the need to bold is dynamic.

Hoping to get this supported or can anyone think of a workaround?

We used iTextSharp to Merge XFDF into PDF.

iTextSharp recognized the <value-richtext> tag and did things like BOLD the text.

iText7 does not support applying the <value-richtext> tag when calling MergeToPdf()

We need this in order to BOLD the field Value.

Here is an example:

<field name="_001_STATEMENT_LINE_ITEM_DESCRIPTION">
  <value-richtext>
    <body xmlns="http://www.w3./1999/xhtml" xmlns:xfa="http://www.xfa./schema/xfa-data/1.0/" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1">
      <p dir="ltr" style="margin-top:0pt;margin-bottom:0pt;text-valign:middle;font-family:Helvetica;font-size:8pt;font-weight:bold">Donald Duck</p> 
    </body>
  </value-richtext>
</field>

The <value-richtext> tag is something Adobe allows and performs inherently.

Setting the bold property for the field directly in the PDF is NOT an option as the need to bold is dynamic.

Hoping to get this supported or can anyone think of a workaround?

Share Improve this question asked Feb 21 at 6:02 user29716522user29716522 11 bronze badge 0
Add a comment  | 

1 Answer 1

Reset to default 0

When you double click or open an XFDF it will load the pre-paired JetForm/AcroForm Duck.PDF with fields primed and loaded ready for action.

So let us assume we have a PDF already open. Then it is very easy to test by repeatedly drop the XFDF on the field. After a few attempts at different styles you know it is working even if not necessarily valid.

Thus here is your minimal example Rich Text PDF for you to test your plain text XFDF.

%PDF-1.7
1 0 obj <</Type/Catalog/AcroForm 2 0 R/Pages 3 0 R>> endobj
2 0 obj <</Fields[4 0 R]>> endobj
3 0 obj <</Type/Pages/Count 1/Kids[5 0 R]>> endobj
4 0 obj <</Type/Annot/Subtype/Widget/AP<</N 6 0 R>>/DA(0 g /Helv 0 Tf)/F 4/Ff 33554432/FT/Tx/MK<</BC[0 0 0]>>/P 5 0 R/Rect[25 39 175 61]/T(_001_STATEMENT_LINE_ITEM_DESCRIPTION)>> endobj
5 0 obj <</Type/Page/Annots[4 0 R]/MediaBox[0 0 200 100]/Parent 3 0 R/Resources<<>>/Contents 7 0 R>> endobj
6 0 obj <</Type/XObject/Subtype/Form/BBox[0 0 150 22]/Length 42/Resources<<>>>>
stream
1 1 1 RG 1 w .5 .5 149 21 re S /Tx BMC EMC
endstream
endobj
7 0 obj
<</Length 0>>
stream
endstream
endobj
xref
0 8
0000000000 65535 f 
0000000009 00000 n 
0000000069 00000 n 
0000000103 00000 n 
0000000154 00000 n 
0000000340 00000 n 
0000000448 00000 n 
0000000595 00000 n 
trailer
<</Size 8/Root 1 0 R/ID[<66D604FE3981C7EAECAB8E10D7DA6864><D3C177FA8503A6A7BFD555C4608DC77F>]>>
startxref
641
%%EOF

NOW we have a suitable simple static XFA receiver we need to reverse out your desired BOLD data, so we can re-import it a billion times over.

<?xml version="1.0" encoding="UTF-8"?>
<xfdf xmlns="http://ns.adobe/xfdf/" xml:space="preserve">
    <f href="duckb.pdf"/>
    <ids original="66D604FE3981C7EAECAB8E10D7DA6864" modified="5754EB63EEC8BB4EA60C1D84AC6D6DC7"/>
    <fields>
        <field name="_001_STATEMENT_LINE_ITEM_DESCRIPTION">
            <value>Donald Duck</value>
            <value-richtext><body xmlns="http://www.w3./1999/xhtml" xmlns:xfa="http://www.xfa./schema/xfa-data/1.0/" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1" style="text-align:left;font-family:Arial;font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:#000000;text-valign:middle;"><p style="font-family:Helvetica;font-size:8pt;font-weight:bold;"><span>Donald Duck</span></p></body></value-richtext>
        </field>
    </fields>
</xfdf>

Answer

To prove it is working send the XFDF to Acrobat Reader.

Ensure it is trusted, and check the result is BOLD.

What the XFDF merging does, is trigger the Reader to enrich the PDF to nearly three times bigger. By requiring additional supportive fonts and other metadata, so as to draw the Rich Text appearance visually.

%PDF-1.7
1 0 obj <</ModDate(D:20250222000000Z)>> endobj
2 0 obj <</AcroForm 3 0 R/Pages 4 0 R/Type/Catalog>> endobj
3 0 obj <</Fields[5 0 R]>> endobj
4 0 obj <</Count 1/Kids[6 0 R]/Type/Pages>> endobj
5 0 obj <</AP<</N 7 0 R>>/DA(0 g /Helv 0 Tf)/F 4/Ff 33554432/FT/Tx/MK<</BC[0 0 0]>>/P 6 0 R/Rect[25 39 175 61]/RV(<body xmlns="http://www.w3./1999/xhtml" xmlns:xfa="http://www.xfa./schema/xfa-data/1.0/" xfa:APIVersion="Acroform:2.7.0.0" xfa:spec="2.1" style="text-align:left;font-family:Arial;font-size:10pt;font-weight:normal;font-style:normal;text-decoration:none;color:#000000;text-valign:middle;"><p style="font-family:Helvetica;font-size:8pt;font-weight:bold;"><span>Donald Duck</span></p></body>)/Subtype/Widget/T(_001_STATEMENT_LINE_ITEM_DESCRIPTION)/Type/Annot/V(Donald Duck)>> endobj
6 0 obj <</Annots[5 0 R]/Contents 8 0 R/MediaBox[0 0 200 100]/Parent 4 0 R/Resources<<>>/Type/Page>> endobj
7 0 obj <</BBox[0 0 150 22]/Type/XObject/Length 131/Resources<</Font<</F0 9 0 R>>>>/Subtype/Form>>
stream
0 0 0 RG 1 w .5 .5 149 21 re S /Tx BMC
q 1 1 148 20 re W n BT 0 g 0 Tc 0 Tw 100 Tz 0 Tr/F0 8 Tf 2 8.228 Td (Donald Duck)Tj ET Q
EMC
endstream
endobj
8 0 obj
<</Length 0>>
stream
endstream
endobj
9 0 obj <</BaseFont/Arial,Bold/Encoding/WinAnsiEncoding/FirstChar 32/FontDescriptor 10 0 R/LastChar 117/Subtype/TrueType/Type/Font/Widths[278 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 722 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 556 0 556 611 0 0 0 0 0 0 556 278 0 611 611 0 0 0 0 0 611]>> endobj
10 0 obj <</Ascent 905/CapHeight 716/Descent -212/Flags 32/FontBBox[-628 -376 2000 1056]/FontFamily(Arial)/FontName/Arial,Bold/FontWeight 700/ItalicAngle 0/StemV 0/Type/FontDescriptor>> endobj
xref
0 11
0000000000 65536 f 
0000000009 00000 n 
0000000056 00000 n 
0000000116 00000 n 
0000000150 00000 n 
0000000201 00000 n 
0000000800 00000 n 
0000000908 00000 n 
0000001163 00000 n 
0000001209 00000 n 
0000001549 00000 n 
trailer
<</Size 11/Info 1 0 R/Root 2 0 R/ID[<66D604FE3981C7EAECAB8E10D7DA6864><6869C9ADF3A3901385EC5668FE9C60DA>]>>
startxref
1742
%%EOF

As you can see it is a total rewite of the PDF structure and best to have all the fonts embeded beforehand.

Luckily for iText users (just like many other systems) there is a single line command to directly inject the XFDF:

java -jar target/xfdf-merge-<VERSION>-jar-with-dependencies.jar input.pdf input.xfdf output.pdf [transform]

See https://github/itext/xfdf-merger

发布评论

评论列表(0)

  1. 暂无评论