2016-01-12 3 views
1

Итак, я хочу сгенерировать PDF-файл без с использованием любых библиотек. Я могу создать какой-то текст, но как добавить гиперссылку на него? Например, у меня есть этот блок:Добавление гиперссылки в PDF (pdf specefication)

14 0 obj 
<< 
/Length 15 0 R 
>> 
stream 
/DeviceRGB CS 
/DeviceRGB cs 
q 
1.0 1.0 1.0 scn 
1.0 1.0 1.0 SCN 
10.000000 974.900000 38.440000 11.160000 re B 
0.0 0.0 0.0 scn 
BT 
10.000000 977.690000 Td 
/Res0 10.000000 Tf 
(asdfas) Tj 
ET 
Q 
endstream 
endobj 

Res0 - имя ресурса шрифта. Что я должен добавить для создания гиперссылки?

+0

Заканчивать https://www.w3.org/TR/WCAG20-TECHS/PDF11.html Пример 4 может помочь – eazimmerman

+0

Посмотрите на [этот q uestion] (http://stackoverflow.com/q/34734669/1729265), он содержит очень простой пример ссылки в формате PDF с ручной кодировкой (хотя проблема с достоверностью, см. [мой ответ на этот вопрос] (http://stackoverflow.com/a/34740521/1729265)). – mkl

ответ

1

Из комментария link приведено ниже.

Следующая строка (записывается в виде HTML)

Here is some text <a href="http://www.w3.org/WAI/"> with a link </a> inside. 

может быть представлена ​​в формате PDF, как

/P <</MCID 0>>            %Marked Content Sequence 0 (paragraph) 
    BDC               %Begin marked content sequence 
    BT               %Begin text object 
    /F1 11.04 Tf            %set text font and size 
    1 0 0 1 72.024 709.54 Tm         %set text matrix 
    0 g              %set non stroking color to black 
    0 G              %set stroke color to black 
    [(H)3(ere)-4(is s)10(o)5(m)-4(e)9(t)-3(e)9(xt)-3()] TJ %Show text preceding the link" Here is some text" 
    ET               %end text object 
    EMC               %end marked content sequence 

/Span <</MCID 1>>            %Marked Content Sequence 1 (underlined link text) 
    BDC               %Begin marked content sequence 
    BT               %Begin text object 
    1 0 0 1 152.42 709.54 Tm         %set text matrix 
    0 0 1 rg             %set non-stroking color to blue 
    0 0 1 RG             %set stroke color to blue 
    [(with a)-2(li)3(n)14(k)] TJ        %Show link text " with a link" 
    ET               %end text object 
    0 0 1 rg             %set stroke color to blue 
    152.42 707.62 45.984 0.72 re        %rectangle operator - target area for the link 
    f*               %fill the path using the even-odd rule 
    EMC               %end marked content sequence 

/P <</MCID 2>>            %Marked Content Sequence 2 (paragraph) 
    BDC               %Begin marked content sequence 
    BT               %begin text object 
    1 0 0 1 198.41 709.54 Tm         %set text matrix            
    0 g              %set non stroking color to black 
    0 G              %set stroke color to black 
    [()] TJ             %empty text string showing white space 
    ET               %end text object 
    BT               %begin text object 
    1 0 0 1 200.93 709.54 Tm         %set text matrix 
    [(in)5(sid)5(e.)] TJ          %show text following the link "inside." 
    ET               %end text 
    BT               %begin text object 
    1 0 0 1 229.97 709.54 Tm         %set text matrix 
    [()] TJ             %empty text string showing white space 
    ET               %end text object 
    EMC               %end marked content sequence 

и добавить логику использования ссылок

11 0 obj            %Object ID 11, generation 0, obj keyword 
    <</K[1            %immediate child of the structure tree root 
    << 
    /Obj 26 0 R          %reference to Object 26 
    /Type/OBJR           %this object describes an indirect object reference 
    >>] 
    /P 12 0 R 
    /Pg 17 0 R 
    /S/Link 
    >> 
endobj 

26 0 obj            %object ID 26 which is referenced by the OBJR in Object 11 
    <</A 31 0 R 
    /BS 
    <</S/S 
    /Type/Border 
    /W 0 
    >> 
    /Border[0 0 0]          %a colorless border 
    /H/I 
    /Rect[150.128 694.558 200.551 720.0]    %the boundaries defining target area where link annotation is active 
    /StructParent 1 
    /Type/Annot           %Structure element is an annotation 
    /Subtype/Link 
    >>             %It is a link annotation             
endobj  
31 0 obj            %Object 31, gen 0, obj 
    <</S/URI            %Object type is URI action 
    /URI(http://www.w3.org/WAI)      %The Uniform resource identifier to resolve 
    >> 
endobj 
+0

Я тоже нашел этот пример, но я не понимаю, где объект 11 0 R должен упоминаться в других блоках, а что означает «/ P 12 0 R/Pg 17 0 R». –

+0

Я верю/P относится к родительскому и/Pg относится к странице. Как видно на странице 562 этого документа http://www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/PDF32000_2008.pdf – eazimmerman

+1

@ КонстантинСавельев & eazimmerman * Я не понимаю, где ... * & * Я считаю ... * - как насчет остановки догадки и начала изучения спецификации [ISO 32000-1] (http://www.adobe.com/content/dam/Adobe/en/devnet/acrobat/ PDFs/PDF32000_2008.pdf)? – mkl

Смежные вопросы