@@ -9,6 +9,8 @@ import * as dom_util from "/src/util/dom";
99// <script src="../../pdfInject.js"></script>
1010// <script type="module" src="../../doq/doq.js"></script>
1111// validateFileURL(file);
12+ var isPdfSpaceInserted = false ;
13+ var waitCount = [ 1000 , 5000 , 10000 , 15000 , 20000 , 30000 , 60000 ] ; //ms
1214
1315initPdf ( ) ;
1416
@@ -18,10 +20,13 @@ async function initPdf() {
1820 checkLocalFileUrl ( ) ; // warn no permission if file url
1921 checkLocalFileType ( ) ;
2022 addCustomKeystroke ( ) ;
23+
2124 //make line break for spaced text
2225 addCallbackForPdfTextLoad ( addSpaceBetweenPdfText ) ;
23- await delay ( 1000 ) ; //wait pdf load // run again if text rendered not called
24- addSpaceBetweenPdfText ( ) ;
26+ for ( const wait of waitCount ) {
27+ await delay ( wait ) ;
28+ addSpaceBetweenPdfText ( ) ;
29+ }
2530 // initButton();
2631}
2732
@@ -84,16 +89,36 @@ function waitUntilPdfLoad() {
8489 } ) ;
8590}
8691
92+
8793// change space system for tooltip
8894async function addSpaceBetweenPdfText ( ) {
95+
96+ if ( isPdfSpaceInserted ) {
97+ console . log ( "PDF space already inserted" ) ;
98+ return ;
99+ } else {
100+ console . log ( "Inserting PDF space" ) ;
101+ }
102+
103+ // remove all br
104+ var brCount = $ ( "br" ) . length ;
105+ if ( brCount == 0 ) {
106+ console . log ( "No removing <br> elements" ) ;
107+ return ;
108+ }
109+ console . log ( "Removed " + brCount + " <br> elements" ) ;
110+ isPdfSpaceInserted = true ;
111+ $ ( "br" ) . remove ( ) ;
112+
113+ insertLineBreak ( ) ;
114+ }
115+
116+ function insertLineBreak ( ) {
89117 var prevY ;
90118 var prevLine ;
91119 var newLineScale = 1.3 ; // if line gap more than 1.3 times font size, add new line
92120 var spaceScale = 1.0 ; // if line gap more than 1.0 times font size, add space
93121
94- // remove all br
95- $ ( "br" ) . remove ( ) ;
96-
97122 // add new line for split text
98123 //only select leaf element, not item has child
99124 $ ( ".page span:not(:has(*))" ) . each ( function ( index , line ) {
@@ -127,9 +152,10 @@ async function addSpaceBetweenPdfText() {
127152 } catch ( error ) {
128153 console . log ( error ) ;
129154 }
130- } ) ;
155+ } ) ;
131156}
132157
158+
133159function addCustomKeystroke ( ) {
134160 document . addEventListener ( "keydown" , function onPress ( evt ) {
135161 //skip if text input running
0 commit comments