WkHtmlToPdf DLL prototype

Not sure if it’s applicable to your requirements, but that’s the kind of thing I wrote my redirection class for on Clarionmag.

What is the output of fName.getValue()?
Might be useful to give an example how a filename looks like aka the whole img tag in html code.

1 Like

Hi Koen

Dirk’s earlier example was:

so based on that fName should hold ‘…/…/logo.jpg’

so after doing fName.replace(‘…/’,‘’) it should then hold just ‘logo.jpg’

To be more exact two examples

<img src=“…/…/…/…/Images/CC_LOG.JPG”
where the image is
C:\Clarion11|Images\CC_LOG.JPG

<img src=“…/…/…/MijnTaken/DATA_MYTASKS/RAPPORT/logo.jpg”
where the image is
C:\Clarion11\exes\MijnTaken\DATA_MYTASKS\RAPPORT\logo.jpg

So i need to replace / with \ (no problem) and then start from the root directory (where the html file is saved), count how many “…/” are found, remove them and then with the count# remove these subdirectories from the root to get the path to the image file. Any ideas?

I guess this api should help:
PathRelativePathToA function (shlwapi.h) - Win32 apps | Microsoft Learn

in DOS and Windows a parent directory is noted by two dots, so this might be worth a try:

fName.replace('…/','..\')
fName.replace('/','\')

and perhaps explicitly specify the path:

fName.replace('…/','..\')
fName.replace('/','\')
if fName.startsWith('..\')      ! two dots indicates parent directory
  fName.prepend(longPath() & '\')
elsif fName.startsWith('.\')    ! one dot indicates current directory
  fName.RemoveFromPosition(1,1) ! remove first character (or fName.top(1))
  fName.prepend(longPath())
end

or alternatively

fName.replace('…/','..\')
fName.replace('/','\')
if fName.startsWith('..\')        ! two dots indicates parent directory
  fName.prepend(longPath() & '\')
elsif fName.startsWith('.\')      ! one dot indicates current directory
  fName.replace('.',longPath(),1) ! replace initial dot
end

I think that should work and be easier than splitting fName on ‘\’ and deleting lines then joining again - but let us know how you go…

cheers

Geoff R

but if you did want to do that it shouldn’t be too hard. Something like:

x      long,auto
recs   long,auto
  code
  fName.replace('…/','..\')
  fName.replace('/','\')
  if fName.startsWith('..\')        ! two dots indicates parent directory
    fName.prepend(longPath() & '\')
  elsif fName.startsWith('.\')      ! one dot indicates current directory
    fName.replace('.',longPath(),1) ! replace initial dot
  end
  fName.split('\')
  recs = fName.records()
  loop x = 2 to recs
    if fName.getLine(x) = '..' and x > 1
      fName.deleteLine(x)
      fName.deleteLine(x-1)
      x -= 2
      recs -= 2
    end
  end
  fName.join('\')

as before, let us know how you go…

cheers

Geoff R

Why not just replace…

…/…/…/…/Images with C:\Clarion11|Images

and…

…/…/…/MijnTaken with C:\Clarion11\exes\MijnTaken

? If they are the only two paths?

is the 3 dots …/ correct? unix and dos/windows paths are 2 dots for the parent directory with *nix using a / as a seperator and dos a
So I would have thought …/…/file would have been the thing to use.

yes Geoff that is the question… I was giving a more general solution rather than “hard coding” in a path which may change down the track.

cheers

(the other) Geoff

no idea Sean - that is just what Dirk mentioned/specified.

I am replacing them with two dots to mean parent directory… as that is what Dirk’s examples implied.

fName.replace('…/','..\')

BTW stay safe from Cyclone Alfred heading your direction - hope it misses or peters out.

cheers

Geoff R

edit: I just realised the three dots on Dirk’s example is actually just one character (ellipsis ie. ‘<133>’) not three separate dot characters. Regardless, the replace statement above changes it to two dots.

1 Like

Hi all,

For some reason when i past …/ from html it is changed to …/ So i ment …/
The images can be inserted from any place from the local drive.

So i need something (pseudcode)

fName.replace('/','\')
if fName.startsWith('..\')
count#  '..\'
Loop Count#
   delete from right to left fname '\' to '\'
   delete from left to right fname '..\'
end 

fname=longpath()&'\'&fname  

If fname not exists
   Message('Local Image(s) will not show correctly when sending html E-mail, Change the image(s) to embed data in the html editor' ) 
end

3/5/25 Carl Edited post to change to CODE with ```

For some reason the two dots are changed to 3 but it’s about two dots and a backslash

Dirk, unless I have missed something I think you already have the code you need above - try it and see.

cheers

Geoff R

seems weird but there are options to tell it to not mess with the text

try “quoting” or “formatting” the code/text etc by putting three tildas or backticks before and after text. or you can try putting a > at the start of a single line

like this

for clarion code you can put three tildas (~) or backticks (`) followed by the word “clarion” ie. ```clarion.

for more info see

hth

As Geoff said wrap your code with 3 backticks ``` plus “clarion” and it will be CODE with color syntax highlighting for Clarion.

I edited your post. Below is screen cap of Editor on Left with markdown and Preview on Right that shows CODE:


Without that it looked like below:


One thing to consider in your file name work is you may have a Root Path like C:\

Thanks all,

It’s working now

good to hear that Dirk, glad you got it working and thanks for letting us know.

in case anyone with a similar requirement refers to this thread in the future, would you like to post your final working code?

cheers

Geoff R

Hi Geoff,

      fname.SetValue(filename)
      fName.replace('/','\')          
      fName.split('..\')          
      recs = fName.records()-1
      Rootfolder=glo:uncmap&'\HTML_MERGEFILES' ! here are the html files   
      loop recs times
        Rootfolder=removelastdir(Rootfolder)
      end        
      loop x = 1 to recs
        if fName.getLine(x) = '..\' and x > 1
          fName.deleteLine(x)
          fName.deleteLine(x-2)
          x -= 3
          recs -= 3                            
        end            
      end!loop
      fName.join('')
      if img.loadfile(rootfolder&'\'&fname.GetVal())
        if img.len() > 0
          img.base64Encode(st:noWrap)
          replaces=st.replace(tagContents[tagStart+1:tagEnd - 1],'data:image/'&fName.extensionOnly()&';base64,'&img.getValue())
        end  
      end
1 Like

thanks Dirk for posting your code and, as I said earlier, I am glad you have it working for you.

However, having said that, I do have some concerns about your code.

in order to get rid of the “..\” or “move up a level to parent directory” I earlier posted this split/join code:

  fName.split('\')
  recs = fName.records()
  loop x = 2 to recs
    if fName.getLine(x) = '..' and x > 1
      fName.deleteLine(x)
      fName.deleteLine(x-1)
      x -= 2
      recs -= 2
    end
  end
  fName.join('\')

in your code this is changed to:

      fName.split('..\')          
      recs = fName.records()-1
      Rootfolder=glo:uncmap&'\HTML_MERGEFILES' ! here are the html files   
      loop recs times
        Rootfolder=removelastdir(Rootfolder)
      end        
      loop x = 1 to recs
        if fName.getLine(x) = '..\' and x > 1
          fName.deleteLine(x)
          fName.deleteLine(x-2)
          x -= 3
          recs -= 3                            
        end            
      end!loop
      fName.join('')

initially I was concerned that you are deleting line (x-2) not (x-1) and then decrementing by 3 not 2 when you have deleted two lines.

then I noticed it was moot/academic as that code in the loop is never performed.

consider this:

st.setValue(‘1,2,3,4,5’)
st.split(‘,’)

there are now 5 lines in the lines queue:
1
2
3
4
5

there is no way in this example that a comma is in a line as that was used as the “boundary” to split on.

similary you have changed the split to be on ‘..\’ rather than ‘\’ and so:

if fName.getLine(x) = '..\' and x > 1

can never be true.

the unknown at the moment is the earlier loop

      loop recs times
        Rootfolder=removelastdir(Rootfolder)
      end

maybe that is doing the actual work???

can you please show the code for removelastdir() so we can understand what is going on?

thanks and cheers and hth

Geoff R