-
Notifications
You must be signed in to change notification settings - Fork 1
/
as_pdf3_4.sql
executable file
·3987 lines (3980 loc) · 133 KB
/
as_pdf3_4.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
CREATE OR REPLACE package as_pdf3
-- Think about who you give execute to if you comment this out. They
-- will have the ability to inject code that executes as your schema owner
-- through callback facility. If you make this a definer rights package,
-- they also are writing to directories only your schema has write permission on,
-- not their own.
AUTHID CURRENT_USER
is
/**********************************************
**
** Author: Anton Scheffer
** Date: 11-04-2012
** Website: http://technology.amis.nl
** See also: http://technology.amis.nl/?p=17718
**
** Changelog:
** Date: 13-08-2012
** added two procedure for Andreas Weiden
** see https://sourceforge.net/projects/pljrxml2pdf/
** Date: 16-04-2012
** changed code for parse_png
** Date: 15-04-2012
** only dbms_lob.freetemporary for temporary blobs
** Date: 11-04-2012
** Initial release of as_pdf3
**
** Date: 07-17-2021 Lee Lindley
** added c_get_page_count and return of same from function get()
** If you want to modify your own version, search for c_get_page_count
** in this source. It is only 2 lines. Otherwise identical to the original.
******************************************************************************
******************************************************************************
Copyright (C) 2012 by Anton Scheffer
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
******************************************************************************
******************************************** */
--
c_get_page_width constant pls_integer := 0;
c_get_page_height constant pls_integer := 1;
c_get_margin_top constant pls_integer := 2;
c_get_margin_right constant pls_integer := 3;
c_get_margin_bottom constant pls_integer := 4;
c_get_margin_left constant pls_integer := 5;
c_get_x constant pls_integer := 6;
c_get_y constant pls_integer := 7;
c_get_fontsize constant pls_integer := 8;
c_get_current_font constant pls_integer := 9;
-- added ltl for GetPdf wrapper package 20210717
c_get_page_count constant pls_integer := 10;
--
function file2blob( p_dir varchar2, p_file_name varchar2 )
return blob;
--
function conv2uu( p_value number, p_unit varchar2 )
return number;
--
procedure set_page_size
( p_width number
, p_height number
, p_unit varchar2 := 'cm'
);
--
procedure set_page_format( p_format varchar2 := 'A4' );
--
procedure set_page_orientation( p_orientation varchar2 := 'PORTRAIT' );
--
procedure set_margins
( p_top number := null
, p_left number := null
, p_bottom number := null
, p_right number := null
, p_unit varchar2 := 'cm'
);
--
procedure set_info
( p_title varchar2 := null
, p_author varchar2 := null
, p_subject varchar2 := null
, p_keywords varchar2 := null
);
--
procedure init;
--
function get_pdf
return blob;
--
procedure save_pdf
( p_dir varchar2 := 'MY_DIR'
, p_filename varchar2 := 'my.pdf'
, p_freeblob boolean := true
);
--
procedure txt2page( p_txt varchar2 );
--
procedure put_txt( p_x number, p_y number, p_txt varchar2, p_degrees_rotation number := null );
--
function str_len( p_txt varchar2 )
return number;
--
procedure write
( p_txt in varchar2
, p_x in number := null
, p_y in number := null
, p_line_height in number := null
, p_start in number := null -- left side of the available text box
, p_width in number := null -- width of the available text box
, p_alignment in varchar2 := null
);
--
procedure set_font
( p_index pls_integer
, p_fontsize_pt number
, p_output_to_doc boolean := true
);
--
function set_font
( p_fontname varchar2
, p_fontsize_pt number
, p_output_to_doc boolean := true
)
return pls_integer;
--
procedure set_font
( p_fontname varchar2
, p_fontsize_pt number
, p_output_to_doc boolean := true
);
--
function set_font
( p_family varchar2
, p_style varchar2 := 'N'
, p_fontsize_pt number := null
, p_output_to_doc boolean := true
)
return pls_integer;
--
procedure set_font
( p_family varchar2
, p_style varchar2 := 'N'
, p_fontsize_pt number := null
, p_output_to_doc boolean := true
);
--
procedure new_page;
--
function load_ttf_font
( p_font blob
, p_encoding varchar2 := 'WINDOWS-1252'
, p_embed boolean := false
, p_compress boolean := true
, p_offset number := 1
)
return pls_integer;
--
procedure load_ttf_font
( p_font blob
, p_encoding varchar2 := 'WINDOWS-1252'
, p_embed boolean := false
, p_compress boolean := true
, p_offset number := 1
);
--
function load_ttf_font
( p_dir varchar2 := 'MY_FONTS'
, p_filename varchar2 := 'BAUHS93.TTF'
, p_encoding varchar2 := 'WINDOWS-1252'
, p_embed boolean := false
, p_compress boolean := true
)
return pls_integer;
--
procedure load_ttf_font
( p_dir varchar2 := 'MY_FONTS'
, p_filename varchar2 := 'BAUHS93.TTF'
, p_encoding varchar2 := 'WINDOWS-1252'
, p_embed boolean := false
, p_compress boolean := true
);
--
procedure load_ttc_fonts
( p_ttc blob
, p_encoding varchar2 := 'WINDOWS-1252'
, p_embed boolean := false
, p_compress boolean := true
);
--
procedure load_ttc_fonts
( p_dir varchar2 := 'MY_FONTS'
, p_filename varchar2 := 'CAMBRIA.TTC'
, p_encoding varchar2 := 'WINDOWS-1252'
, p_embed boolean := false
, p_compress boolean := true
);
--
procedure set_color( p_rgb varchar2 := '000000' );
--
procedure set_color
( p_red number := 0
, p_green number := 0
, p_blue number := 0
);
--
procedure set_bk_color( p_rgb varchar2 := 'ffffff' );
--
procedure set_bk_color
( p_red number := 0
, p_green number := 0
, p_blue number := 0
);
--
procedure horizontal_line
( p_x in number
, p_y in number
, p_width in number
, p_line_width in number := 0.5
, p_line_color in varchar2 := '000000'
);
--
procedure vertical_line
( p_x in number
, p_y in number
, p_height in number
, p_line_width in number := 0.5
, p_line_color in varchar2 := '000000'
);
--
procedure rect
( p_x in number
, p_y in number
, p_width in number
, p_height in number
, p_line_color in varchar2 := null
, p_fill_color in varchar2 := null
, p_line_width in number := 0.5
);
--
function get( p_what in pls_integer )
return number;
--
procedure put_image
( p_img blob
, p_x number
, p_y number
, p_width number := null
, p_height number := null
, p_align varchar2 := 'center'
, p_valign varchar2 := 'top'
);
--
procedure put_image
( p_dir varchar2
, p_file_name varchar2
, p_x number
, p_y number
, p_width number := null
, p_height number := null
, p_align varchar2 := 'center'
, p_valign varchar2 := 'top'
);
--
procedure put_image
( p_url varchar2
, p_x number
, p_y number
, p_width number := null
, p_height number := null
, p_align varchar2 := 'center'
, p_valign varchar2 := 'top'
);
--
procedure set_page_proc( p_src clob );
--
type tp_col_widths is table of number;
type tp_headers is table of varchar2(32767);
--
procedure query2table
( p_query varchar2
, p_widths tp_col_widths := null
, p_headers tp_headers := null
);
--
$IF not DBMS_DB_VERSION.VER_LE_10 $THEN
procedure refcursor2table
( p_rc sys_refcursor
, p_widths tp_col_widths := null
, p_headers tp_headers := null
);
--
$END
--
procedure pr_goto_page( i_npage number );
--
procedure pr_goto_current_page;
/*
begin
as_pdf3.init;
as_pdf3.write( 'Minimal usage' );
as_pdf3.save_pdf;
end;
--
begin
as_pdf3.init;
as_pdf3.write( 'Some text with a newline-character included at this "
" place.' );
as_pdf3.write( 'Normally text written with as_pdf3.write() is appended after the previous text. But the text wraps automaticly to a new line.' );
as_pdf3.write( 'But you can place your text at any place', -1, 700 );
as_pdf3.write( 'you want', 100, 650 );
as_pdf3.write( 'You can even align it, left, right, or centered', p_y => 600, p_alignment => 'right' );
as_pdf3.save_pdf;
end;
--
begin
as_pdf3.init;
as_pdf3.write( 'The 14 standard PDF-fonts and the WINDOWS-1252 encoding.' );
as_pdf3.set_font( 'helvetica' );
as_pdf3.write( 'helvetica, normal: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, 700 );
as_pdf3.set_font( 'helvetica', 'I' );
as_pdf3.write( 'helvetica, italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'helvetica', 'b' );
as_pdf3.write( 'helvetica, bold: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'helvetica', 'BI' );
as_pdf3.write( 'helvetica, bold italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'times' );
as_pdf3.write( 'times, normal: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, 625 );
as_pdf3.set_font( 'times', 'I' );
as_pdf3.write( 'times, italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'times', 'b' );
as_pdf3.write( 'times, bold: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'times', 'BI' );
as_pdf3.write( 'times, bold italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'courier' );
as_pdf3.write( 'courier, normal: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, 550 );
as_pdf3.set_font( 'courier', 'I' );
as_pdf3.write( 'courier, italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'courier', 'b' );
as_pdf3.write( 'courier, bold: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'courier', 'BI' );
as_pdf3.write( 'courier, bold italic: ' || 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
--
as_pdf3.set_font( 'courier' );
as_pdf3.write( 'symbol:', -1, 475 );
as_pdf3.set_font( 'symbol' );
as_pdf3.write( 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
as_pdf3.set_font( 'courier' );
as_pdf3.write( 'zapfdingbats:', -1, -1 );
as_pdf3.set_font( 'zapfdingbats' );
as_pdf3.write( 'The quick brown fox jumps over the lazy dog. 1234567890', -1, -1 );
--
as_pdf3.set_font( 'times', 'N', 20 );
as_pdf3.write( 'times, normal with fontsize 20pt', -1, 400 );
as_pdf3.set_font( 'times', 'N', 6 );
as_pdf3.write( 'times, normal with fontsize 5pt', -1, -1 );
as_pdf3.save_pdf;
end;
--
declare
x pls_integer;
begin
as_pdf3.init;
as_pdf3.write( 'But others fonts and encodings are possible using TrueType fontfiles.' );
x := as_pdf3.load_ttf_font( 'MY_FONTS', 'refsan.ttf', 'CID', p_compress => false );
as_pdf3.set_font( x, 12 );
as_pdf3.write( 'The Windows MSReference SansSerif font contains a lot of encodings, for instance', -1, 700 );
as_pdf3.set_font( x, 15 );
as_pdf3.write( 'Albanian: Kush mund të lexoni këtë diçka si kjo', -1, -1 );
as_pdf3.write( 'Croatic: Tko moe citati to neto poput ovoga', -1, -1 );
as_pdf3.write( 'Russian: ??? ????? ????????? ??? ???-?? ????? ?????', -1, -1);
as_pdf3.write( 'Greek: ????? µp??e? ?a d?aß?se? a?t? t? ??t? sa? a?t?', -1, -1 );
--
as_pdf3.set_font( 'helvetica', 12 );
as_pdf3.write( 'Or by using a TrueType collection file (ttc).', -1, 600 );
as_pdf3.load_ttc_fonts( 'MY_FONTS', 'cambria.ttc', p_embed => true, p_compress => false );
as_pdf3.set_font( 'cambria', 15 ); -- font family
as_pdf3.write( 'Anton, testing 1,2,3 with Cambria', -1, -1 );
as_pdf3.set_font( 'CambriaMT', 15 ); -- fontname
as_pdf3.write( 'Anton, testing 1,2,3 with CambriaMath', -1, -1 );
as_pdf3.save_pdf;
end;
--
begin
as_pdf3.init;
for i in 1 .. 10
loop
as_pdf3.horizontal_line( 30, 700 - i * 15, 100, i );
end loop;
for i in 1 .. 10
loop
as_pdf3.vertical_line( 150 + i * 15, 700, 100, i );
end loop;
for i in 0 .. 255
loop
as_pdf3.horizontal_line( 330, 700 - i, 100, 2, p_line_color => to_char( i, 'fm0x' ) || to_char( i, 'fm0x' ) || to_char( i, 'fm0x' ) );
end loop;
as_pdf3.save_pdf;
end;
--
declare
t_logo varchar2(32767) :=
'/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkS' ||
'Ew8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDA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OyNTzx178/pWyY0ZdrIpHoRQsaISVRQT6ChJinUhJO0bDqKKKoxCiiigAooooAKK' ||
'KKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD//Z';
begin
as_pdf3.init;
as_pdf3.put_image( to_blob( utl_encode.base64_decode( utl_raw.cast_to_raw( t_logo ) ) )
, 0
, as_pdf3.get( as_pdf3.C_GET_PAGE_HEIGHT ) - 260
, as_pdf3.get( as_pdf3.C_GET_PAGE_WIDTH )
);
as_pdf3.write( 'jpg, gif and png images are supported.' );
as_pdf3.write( 'And because PDF 1.3 (thats the format I use) doesn''t support alpha channels, neither does AS_PDF.', -1, -1 );
as_pdf3.save_pdf;
end;
--
declare
t_rc sys_refcursor;
t_query varchar2(1000);
begin
as_pdf3.init;
as_pdf3.load_ttf_font( 'MY_FONTS', 'COLONNA.TTF', 'CID' );
as_pdf3.set_page_proc( q'~
begin
as_pdf3.set_font( 'helvetica', 8 );
as_pdf3.put_txt( 10, 15, 'Page #PAGE_NR# of "PAGE_COUNT#' );
as_pdf3.set_font( 'helvetica', 12 );
as_pdf3.put_txt( 350, 15, 'This is a footer text' );
as_pdf3.set_font( 'helvetica', 'B', 15 );
as_pdf3.put_txt( 200, 780, 'This is a header text' );
as_pdf3.put_image( 'MY_DIR', 'amis.jpg', 500, 15 );
end;~' );
as_pdf3.set_page_proc( q'~
begin
as_pdf3.set_font( 'Colonna MT', 'N', 50 );
as_pdf3.put_txt( 150, 200, 'Watermark Watermark Watermark', 60 );
end;~' );
t_query := 'select rownum, sysdate + level, ''example'' || level from dual connect by level <= 50';
as_pdf3.query2table( t_query );
open t_rc for t_query;
as_pdf3.refcursor2table( t_rc );
as_pdf3.save_pdf;
end;
*/
end;
/
CREATE OR REPLACE package body as_pdf3
is
--
type tp_pls_tab is table of pls_integer index by pls_integer;
type tp_objects_tab is table of number(10) index by pls_integer;
type tp_pages_tab is table of blob index by pls_integer;
type tp_settings is record
( page_width number
, page_height number
, margin_left number
, margin_right number
, margin_top number
, margin_bottom number
);
type tp_font is record
( standard boolean
, family varchar2(100)
, style varchar2(2) -- N Normal
-- I Italic
-- B Bold
-- BI Bold Italic
, subtype varchar2(15)
, name varchar2(100)
, fontname varchar2(100)
, char_width_tab tp_pls_tab
, encoding varchar2(100) , charset varchar2(1000)
, compress_font boolean := true
, fontsize number
, unit_norm number
, bb_xmin pls_integer
, bb_ymin pls_integer
, bb_xmax pls_integer
, bb_ymax pls_integer
, flags pls_integer
, first_char pls_integer
, last_char pls_integer
, italic_angle number
, ascent pls_integer
, descent pls_integer
, capheight pls_integer
, stemv pls_integer
, diff varchar2(32767)
, cid boolean := false
, fontfile2 blob
, ttf_offset pls_integer
, used_chars tp_pls_tab
, numGlyphs pls_integer
, indexToLocFormat pls_integer
, loca tp_pls_tab
, code2glyph tp_pls_tab
, hmetrics tp_pls_tab
);
type tp_font_tab is table of tp_font index by pls_integer;
type tp_img is record
( adler32 varchar2(8)
, width pls_integer
, height pls_integer
, color_res pls_integer
, color_tab raw(768)
, greyscale boolean
, pixels blob
, type varchar2(5)
, nr_colors pls_integer
, transparancy_index pls_integer
);
type tp_img_tab is table of tp_img index by pls_integer;
type tp_info is record
( title varchar2(1024)
, author varchar2(1024)
, subject varchar2(1024)
, keywords varchar2(32767)
);
type tp_page_prcs is table of clob index by pls_integer;
--
-- globals
g_pdf_doc blob; -- the PDF-document being constructed
g_objects tp_objects_tab;
g_pages tp_pages_tab;
g_settings tp_settings;
g_fonts tp_font_tab;
g_used_fonts tp_pls_tab;
g_current_font pls_integer;
g_images tp_img_tab;
g_x number; -- current x-location of the "cursor"
g_y number; -- current y-location of the "cursor"
g_info tp_info;
g_page_nr pls_integer;
g_page_prcs tp_page_prcs;
--
-- constants
c_nl constant varchar2(2) := chr(13) || chr(10);
--
function num2raw( p_value number )
return raw
is
begin
return hextoraw( to_char( p_value, 'FM0XXXXXXX' ) );
end;
--
function raw2num( p_value raw )
return number
is
begin
return to_number( rawtohex( p_value ), 'XXXXXXXX' );
end;
--
function raw2num( p_value raw, p_pos pls_integer, p_len pls_integer )
return pls_integer
is
begin
return to_number( rawtohex( utl_raw.substr( p_value, p_pos, p_len ) ), 'XXXXXXXX' );
end;
--
function to_short( p_val raw, p_factor number := 1 )
return number
is
t_rv number;
begin
t_rv := to_number( rawtohex( p_val ), 'XXXXXXXXXX' );
if t_rv > 32767
then
t_rv := t_rv - 65536;
end if;
return t_rv * p_factor;
end;
--
function blob2num( p_blob blob, p_len integer, p_pos integer )
return number
is
begin
return to_number( rawtohex( dbms_lob.substr( p_blob, p_len, p_pos ) ), 'xxxxxxxx' );
end;
--
function file2blob( p_dir varchar2, p_file_name varchar2 )
return blob
is
t_raw raw(32767);
t_blob blob;
fh utl_file.file_type;
begin
fh := utl_file.fopen( p_dir, p_file_name, 'rb' );
dbms_lob.createtemporary( t_blob, true );
loop
begin
utl_file.get_raw( fh, t_raw );
dbms_lob.append( t_blob, t_raw );
exception
when no_data_found
then
exit;
end;
end loop;
utl_file.fclose( fh );
return t_blob;
exception
when others
then
if utl_file.is_open( fh )
then
utl_file.fclose( fh );
end if;
raise;
end;
--
procedure init_core_fonts
is
function uncompress_withs( p_compressed_tab varchar2 )
return tp_pls_tab
is
t_rv tp_pls_tab;
t_tmp raw(32767);
begin
if p_compressed_tab is not null
then
t_tmp := utl_compress.lz_uncompress
( utl_encode.base64_decode( utl_raw.cast_to_raw( p_compressed_tab ) ) );
for i in 0 .. 255
loop
t_rv( i ) := to_number( utl_raw.substr( t_tmp, i * 4 + 1, 4 ), '0xxxxxxx' );
end loop;
end if;
return t_rv;
end;
--
procedure init_core_font
( p_ind pls_integer
, p_family varchar2
, p_style varchar2
, p_name varchar2
, p_compressed_tab varchar2
)
is
begin
g_fonts( p_ind ).family := p_family;
g_fonts( p_ind ).style := p_style;
g_fonts( p_ind ).name := p_name;
g_fonts( p_ind ).fontname := p_name;
g_fonts( p_ind ).standard := true;
g_fonts( p_ind ).encoding := 'WE8MSWIN1252';
g_fonts( p_ind ).charset := sys_context( 'userenv', 'LANGUAGE' );
g_fonts( p_ind ).charset := substr( g_fonts( p_ind ).charset
, 1
, instr( g_fonts( p_ind ).charset, '.' )
) || g_fonts( p_ind ).encoding;
g_fonts( p_ind ).char_width_tab := uncompress_withs( p_compressed_tab );
end;
begin
init_core_font( 1, 'helvetica', 'N', 'Helvetica'
, 'H4sIAAAAAAAAC81Tuw3CMBC94FQMgMQOLAGVGzNCGtc0dAxAT+8lsgE7RKJFomOA'
|| 'SLT4frHjBEFJ8XSX87372C8A1Qr+Ax5gsWGYU7QBAK4x7gTnGLOS6xJPOd8w5NsM'
|| '2OvFvQidAP04j1nyN3F7iSNny3E6DylPeeqbNqvti31vMpfLZuzH86oPdwaeo6X+'
|| '5X6Oz5VHtTqJKfYRNVu6y0ZyG66rdcxzXJe+Q/KJ59kql+bTt5K6lKucXvxWeHKf'
|| '+p6Tfersfh7RHuXMZjHsdUkxBeWtM60gDjLTLoHeKsyDdu6m8VK3qhnUQAmca9BG'
|| 'Dq3nP+sV/4FcD6WOf9K/ne+hdav+DTuNLeYABAAA' );
--
init_core_font( 2, 'helvetica', 'I', 'Helvetica-Oblique'
, 'H4sIAAAAAAAAC81Tuw3CMBC94FQMgMQOLAGVGzNCGtc0dAxAT+8lsgE7RKJFomOA'
|| 'SLT4frHjBEFJ8XSX87372C8A1Qr+Ax5gsWGYU7QBAK4x7gTnGLOS6xJPOd8w5NsM'
|| '2OvFvQidAP04j1nyN3F7iSNny3E6DylPeeqbNqvti31vMpfLZuzH86oPdwaeo6X+'
|| '5X6Oz5VHtTqJKfYRNVu6y0ZyG66rdcxzXJe+Q/KJ59kql+bTt5K6lKucXvxWeHKf'
|| '+p6Tfersfh7RHuXMZjHsdUkxBeWtM60gDjLTLoHeKsyDdu6m8VK3qhnUQAmca9BG'
|| 'Dq3nP+sV/4FcD6WOf9K/ne+hdav+DTuNLeYABAAA' );
--
init_core_font( 3, 'helvetica', 'B', 'Helvetica-Bold'
, 'H4sIAAAAAAAAC8VSsRHCMAx0SJcBcgyRJaBKkxXSqKahYwB6+iyRTbhLSUdHRZUB'
|| 'sOWXLF8SKCn+ZL/0kizZuaJ2/0fn8XBu10SUF28n59wbvoCr51oTD61ofkHyhBwK'
|| '8rXusVaGAb4q3rXOBP4Qz+wfUpzo5FyO4MBr39IH+uLclFvmCTrz1mB5PpSD52N1'
|| 'DfqS988xptibWfbw9Sa/jytf+dz4PqQz6wi63uxxBpCXY7uUj88jNDNy1mYGdl97'
|| '856nt2f4WsOFed4SpzumNCvlT+jpmKC7WgH3PJn9DaZfA42vlgh96d+wkHy0/V95'
|| 'xyv8oj59QbvBN2I/iAuqEAAEAAA=' );
--
init_core_font( 4, 'helvetica', 'BI', 'Helvetica-BoldOblique'
, 'H4sIAAAAAAAAC8VSsRHCMAx0SJcBcgyRJaBKkxXSqKahYwB6+iyRTbhLSUdHRZUB'
|| 'sOWXLF8SKCn+ZL/0kizZuaJ2/0fn8XBu10SUF28n59wbvoCr51oTD61ofkHyhBwK'
|| '8rXusVaGAb4q3rXOBP4Qz+wfUpzo5FyO4MBr39IH+uLclFvmCTrz1mB5PpSD52N1'
|| 'DfqS988xptibWfbw9Sa/jytf+dz4PqQz6wi63uxxBpCXY7uUj88jNDNy1mYGdl97'
|| '856nt2f4WsOFed4SpzumNCvlT+jpmKC7WgH3PJn9DaZfA42vlgh96d+wkHy0/V95'
|| 'xyv8oj59QbvBN2I/iAuqEAAEAAA=' );
--
init_core_font( 5, 'times', 'N', 'Times-Roman'
, 'H4sIAAAAAAAAC8WSKxLCQAyG+3Bopo4bVHbwHGCvUNNT9AB4JEwvgUBimUF3wCNR'
|| 'qAoGRZL9twlQikR8kzTvZBtF0SP6O7Ej1kTnSRfEhHw7+Jy3J4XGi8w05yeZh2sE'
|| '4j312ZDeEg1gvSJy6C36L9WX1urr4xrolfrSrYmrUCeDPGMu5+cQ3Ur3OXvQ+TYf'
|| '+2FGexOZvTM1L3S3o5fJjGQJX2n68U2ur3X5m3cTvfbxsk9pcsMee60rdTjnhNkc'
|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BnCfPktkAKagzgCRIqWi'
|| 'oso9fr+Qo5RB+nT2ve+wMWYzf+fgjKmOJFelPhENnS0xANJXHfwHSBtjfoI8nMMj'
|| 'tXo63xKW/Cx9ONRn3US6C/wWvYeYNr+LH2IY6cHGPkJfvsc5kX7mFjF+Vqs9iT6d'
|| 'zwEL26y1Qz62nWlvD5VSf4R9zPuon/ne+C45+XxXf5lnTGLTOZCXPx8v9Qfdjdid'
|| '5vD/f/+/pE/Ur14kG+xjTHRc84pZWsC2Hjk2+Hgbx78j4Z8W4DlL+rBnEN5Bie6L'
|| 'fsL+1u/InuYCdsdaeAs+RxftKfGdfQDlDF/kAAQAAA==' );
--
init_core_font( 9, 'courier', 'N', 'Courier', null );
for i in 0 .. 255
loop
g_fonts( 9 ).char_width_tab( i ) := 600;
end loop;
--
init_core_font( 10, 'courier', 'I', 'Courier-Oblique', null );
g_fonts( 10 ).char_width_tab := g_fonts( 9 ).char_width_tab;
--
init_core_font( 11, 'courier', 'B', 'Courier-Bold', null );
g_fonts( 11 ).char_width_tab := g_fonts( 9 ).char_width_tab;
--
init_core_font( 12, 'courier', 'BI', 'Courier-BoldOblique', null );
g_fonts( 12 ).char_width_tab := g_fonts( 9 ).char_width_tab;
--
init_core_font( 13, 'symbol', 'N', 'Symbol'
, 'H4sIAAAAAAAAC82SIU8DQRCFZ28xIE+cqcbha4tENKk/gQCJJ6AweIK9H1CHqKnp'
|| 'D2gTFBaDIcFwCQkJSTG83fem7SU0qYNLvry5nZ25t7NnZkv7c8LQrFhAP6GHZvEY'
|| 'HOB9ylxGubTfNVRc34mKpFonzBQ/gUZ6Ds7AN6i5lv1dKv8Ab1eKQYSV4hUcgZFq'
|| 'J/Sec7fQHtdTn3iqfvdrb7m3e2pZW+xDG3oIJ/Li3gfMr949rlU74DyT1/AuTX1f'
|| 'YGhOzTP8B0/RggsEX/I03vgXPrrslZjfM8/pGu40t2ZjHgud97F7337mXP/GO4h9'
|| '3WmPPaOJ/jrOs9yC52MlrtUzfWupfTX51X/L+13Vl/J/s4W2S3pSfSh5DmeXerMf'
|| '+LXhWQAEAAA=' );
--
init_core_font( 14, 'zapfdingbats', 'N', 'ZapfDingbats'
, 'H4sIAAAAAAAAC83ROy9EQRjG8TkzjdJl163SSHR0EpdsVkSi2UahFhUljUKUIgoq'
|| 'CrvJCtFQyG6EbSSERGxhC0ofQAQFxbIi8T/7PoUPIOEkvzxzzsycdy7O/fUTtToX'
|| 'bnCuvHPOV8gk4r423ovkGQ5od5OTWMeesmBz/RuZIWv4wCAY4z/xjipeqflC9qAD'
|| 'aRwxrxkJievSFzrRh36tZ1zttL6nkGX+A27xrLnttE/IBji9x7UvcIl9nPJ9AL36'
|| 'd1L9hyihoDW10L62cwhNyhntryZVExYl3kMj+zym+CrJv6M8VozPmfr5L8uwJORL'
|| 'tox7NFHG/Obj79FlwhqZ1X292xn6CbAXP/fjjv6rJYyBtUdl1vxEO6fcRB7bMmJ3'
|| 'GYZsTN0GdrDL/Ao5j1GZNr5kwqydX5z1syoiYEq5gCtlSrXi+mVbi3PfVAuhoQAE'
|| 'AAA=' );
--
end;
--
function to_char_round
( p_value number
, p_precision pls_integer := 2
)
return varchar2
is
begin
return to_char( round( p_value, p_precision ), 'TM9', 'NLS_NUMERIC_CHARACTERS=.,' );
end;
--
procedure raw2pdfdoc( p_raw blob )
is
begin
dbms_lob.append( g_pdf_doc, p_raw );
end;
--
procedure txt2pdfdoc( p_txt varchar2 )
is
begin
raw2pdfdoc( utl_raw.cast_to_raw( p_txt || c_nl ) );
end;
--
function add_object( p_txt varchar2 := null )
return number
is
t_self number(10);
begin
t_self := g_objects.count( );
g_objects( t_self ) := dbms_lob.getlength( g_pdf_doc );
--
if p_txt is null
then
txt2pdfdoc( t_self || ' 0 obj' );
else
txt2pdfdoc( t_self || ' 0 obj' || c_nl || '<<' || p_txt || '>>' || c_nl || 'endobj' );
end if;
--
return t_self;
end;
--
procedure add_object( p_txt varchar2 := null )
is
t_dummy number(10) := add_object( p_txt );
begin
null;
end;
--
function adler32( p_src in blob )
return varchar2
is
s1 pls_integer := 1;
s2 pls_integer := 0;
n pls_integer;
step_size number;
tmp varchar2(32766);
c65521 constant pls_integer := 65521;
begin
step_size := trunc( 16383 / dbms_lob.getchunksize( p_src ) ) * dbms_lob.getchunksize( p_src );
for j in 0 .. trunc( ( dbms_lob.getlength( p_src ) - 1 ) / step_size )
loop
tmp := rawtohex( dbms_lob.substr( p_src, step_size, j * step_size + 1 ) );
for i in 1 .. length( tmp ) / 2
loop
n := to_number( substr( tmp, i * 2 - 1, 2 ), 'xx' );
s1 := s1 + n;
if s1 >= c65521
then
s1 := s1 - c65521;
end if;
s2 := s2 + s1;
if s2 >= c65521
then
s2 := s2 - c65521;
end if;
end loop;
end loop;
return to_char( s2, 'fm0XXX' ) || to_char( s1, 'fm0XXX' );
end;
--
function flate_encode( p_val blob )
return blob
is
t_blob blob;
begin
t_blob := hextoraw( '789C' );
dbms_lob.copy( t_blob
, utl_compress.lz_compress( p_val )
, dbms_lob.lobmaxsize
, 3
, 11
);
dbms_lob.trim( t_blob, dbms_lob.getlength( t_blob ) - 8 );
dbms_lob.append( t_blob, hextoraw( adler32( p_val ) ) );
return t_blob;
end;
--
procedure put_stream
( p_stream blob
, p_compress boolean := true
, p_extra varchar2 := ''
, p_tag boolean := true
)
is
t_blob blob;
t_compress boolean := false;
begin
if p_compress and nvl( dbms_lob.getlength( p_stream ), 0 ) > 0
then
t_compress := true;
t_blob := flate_encode( p_stream );
else
t_blob := p_stream;
end if;
txt2pdfdoc( case when p_tag then '<<' end
|| case when t_compress then '/Filter /FlateDecode ' end
|| '/Length ' || nvl( length( t_blob ), 0 )
|| p_extra
|| '>>' );
txt2pdfdoc( 'stream' );
raw2pdfdoc( t_blob );
txt2pdfdoc( 'endstream' );
if dbms_lob.istemporary( t_blob ) = 1
then
dbms_lob.freetemporary( t_blob );
end if;
end;
--
function add_stream
( p_stream blob
, p_extra varchar2 := ''
, p_compress boolean := true
)
return number
is
t_self number(10);
begin
t_self := add_object;
put_stream( p_stream
, p_compress
, p_extra
);
txt2pdfdoc( 'endobj' );
return t_self;
end;
--
function subset_font( p_index pls_integer )
return blob
is
t_tmp blob;
t_header blob;
t_tables blob;