Adobe PDF规范中是否存在文本字符串变量类型? [英] Is there a text string variable type in Adobe PDF specification?

查看:148
本文介绍了Adobe PDF规范中是否存在文本字符串变量类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在以下示例中(来自 gnupdf.org/Introduction_to_PDF ;还与以下内容相关:

In the below example (from gnupdf.org/Introduction_to_PDF; also related: How to generate plain-text source-code PDF examples that work in a document viewer?), text is written verbatim using:

(Hello, world!) Tj

有没有办法存储这个你好,世界!"在变量(字典?)中说/MyStringVar,然后使用类似以下内容将其输出到多个位置:

Is there a way I could store this "Hello, world!" in a variable (dictionary?), say /MyStringVar, and then output it multiple places using something like:

(/MyStringVar) Tj

(我已经尝试了上面的方法,但无法正常工作; /MyStringVar被逐字解释)

(I've tried the above, couldn't get it to work; /MyStringVar is interpreted verbatim)

这是代码,hello.pdf:

%PDF-1.4

1 0 obj  % entry point
<<
  /Type /Catalog
  /Pages 2 0 R
>>
endobj

2 0 obj
<<
  /Type /Pages
  /MediaBox [ 0 0 200 200 ]
  /Count 1
  /Kids [ 3 0 R ]
>>
endobj

3 0 obj
<<
  /Type /Page
  /Parent 2 0 R
  /Resources <<
    /Font <<
      /F1 4 0 R
    >>
  >>
  /Contents 5 0 R
>>
endobj

4 0 obj
<<
  /Type /Font
  /Subtype /Type1
  /BaseFont /Times-Roman
>>
endobj

5 0 obj  % page content
<<
  /Length 44
>>
stream
BT
70 50 TD
/F1 12 Tf
(Hello, world!) Tj
ET
endstream
endobj

xref
0 6
0000000000 65535 f
0000000010 00000 n
0000000079 00000 n
0000000173 00000 n
0000000301 00000 n
0000000380 00000 n
trailer
<<
  /Size 6
  /Root 1 0 R
>>
startxref
492
%%EOF

推荐答案

PDF中没有类似PostScript的变量.可能会接近您想要达到的目标(在多个位置输出相同的文本)是XObject表单.就像页面一样,它具有包含诸如(Hello, world!) Tj之类的图形对象的内容流,并且可以通过图形Do运算符将其绘制在页面(或另一个XObject)上.其操作数对应于页面资源字典中XObject字典中的键. PDF看起来像这样. (请注意,流长度,交叉引用表和预告片或不再有效,因此请考虑使用此伪PDF.)

The PDF does not have something like a variable like PostScript does. What may come close to what you are trying to achieve (output the same text multiple places) is a form XObject. Just like a page it has a content stream with graphics objects such as (Hello, world!) Tj, and it can be be drawn on a page (or another XObject) through the graphics Do operator. Its operand corresponds to a key in the XObject dictionary in the Resources dictionary of the page. The PDF would look something like this. (Note that stream lengths, the cross references table and the trailer or no longer valid so consider this pseudo-PDF.)

%PDF-1.4

1 0 obj  % entry point
<<
  /Type /Catalog
  /Pages 2 0 R
>>
endobj

2 0 obj
<<
  /Type /Pages
  /MediaBox [ 0 0 200 200 ]
  /Count 1
  /Kids [ 3 0 R ]
>>
endobj

3 0 obj
<<
  /Type /Page
  /Parent 2 0 R
  /Resources <<
    /Font <<
          /F1 4 0 R
    >>
    /XObject  <<
              /A 6 0 R  % XObject /A is obj 6 0
    >>
  >>                    % /Resources must close here
  /Contents 5 0 R
>>
endobj

4 0 obj
<<
  /Type /Font
  /Subtype /Type1
  /BaseFont /Times-Roman
>>
endobj

5 0 obj  % page content
<<
  /Length 44
>>
stream
BT
70 50 TD    % this has no effect on `/A Do` - only on the "manual" `Tj`
/A Do       % do the drawing of XObject A
/F1 12 Tf   % without this line: "Error: No font in show;"
% if without TD, then the next text is just appended
%-10 50 TD
0 0 TD      % "Td/TD move to the start of next line"; but here like \r
(Hello, world - manual!) Tj
ET
endstream
endobj

6 0 obj
  << /Type /XObject
     /Subtype /Form
     /FormType 1
     /BBox [ 0 0 1000 1000 ]
     /Matrix [ 1 0 0 1 0 0 ]
     /Resources << /ProcSet [ /PDF ] >>
     /Length 58
  >>
stream
  %70 50 TD     % without this `TD` setting, `/A Do` places this in 0,0 - bottom left corner
  /F1 12 Tf
  (Hello, world!) Tj
endstream
endobj

xref
0 7
0000000000 65535 f
0000000010 00000 n
0000000079 00000 n
0000000173 00000 n
0000000301 00000 n
0000000380 00000 n
0000000450 00000 n
trailer
<<
  /Size 7
  /Root 1 0 R
>>
startxref
600
%%EOF

evince中的输出:

编辑,因为当前转换矩阵等于显示字符串操作时的单位矩阵,所以XObject形式的文本显示在左下角. XObject形式的初始CTM等于[调用Do时父流中的CTM]和[XObject字典形式中的Matrix条目]的串联.在这种情况下,这就是身份.文本矩阵不会从父流传播到XObject形式.

EDIT The text in the form XObject appears at the lower left corner because the current transformation matrix equals the identity matrix at the time of the show string operation. The initial CTM of the form XObject equals the concatenation of [the CTM in the parent stream when Do is invoked] and [the Matrix entry in the form XObject dictionary]. Which is identity in this case. The text matrix is not propagated from the parent stream to the form XObject.

这篇关于Adobe PDF规范中是否存在文本字符串变量类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆