Re: paste html using API

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello

Thanks for your help but it won't really help me

it's doesn't matter the language,  I could translate in python.

The main problem is to start from a variable (a html string)

Var1="<h2>Lorem Ipsum?</h2><p>Le <strong>Lorem Ipsum</strong> est simplement du faux texte employé dans la composition et la mise en page avant impression. Le Lorem Ipsum </p>"

and you want to paste it in a odt and keep the format

If I want to use only headless mode, i must find a solution without using the SystemClipboard because the clipboard does not seem to be accessible




Le 26/03/2023 à 19:33, Andrew Pitonyak a écrit :
I have no idea if this will be of any use to you or not, but...

I do not generally use the API using Python so I cannot comment on using Python. 

I have also not used headless mode so I cannot comment on what is and is not available other than knowing that dispatches are not available. 

Finally, I have done almost nothing using the clipboard, but... 

First note that the clipboard should have content of different varieties. I assume that you are aware of this because you have a line as follows: 

 copy_with_format(value, 'text/html')
 
 And if I look at the clipboard I see this as an available type
 
   Dim sClipName As String
  Dim oClip As Object
  Dim oFlavors As Variant
  Dim oFlavor As Variant
  Dim i as Integer
  Dim s as String
  
  sClipName = "com.sun.star.datatransfer.clipboard.SystemClipboard"
  oClip = createUnoService(sClipName)
  oFlavors = oClip.getContents().getTransferDataFlavors()
  s = ""
  For i = LBound(oFlavors) To UBound(oFlavors)
    oFlavor = oFlavors(i)
    s = s & i & " : " & oFlavor.MimeType
    s = s & CHR$(10)
  Next
  MsgBox s
  
  
  I see that method defined in this code here: 
  
  https://github.com/Probesys/lotemplate/blob/html_formatting/lotemplate/utils.py
  
  I see that you open a pipe. 
  
  I did some experiments and I am extracting the actual HTML. I assume that this is not really what you want, but this is how I extract it and display it. I was simply playing around with it out of curiousity.
  
    Dim sClipName As String
  Dim oClip As Object
  Dim oFlavors As Variant
  Dim oFlavor As Variant
  Dim i as Integer
  Dim idx as Integer
  Dim s as String
  
  sClipName = "com.sun.star.datatransfer.clipboard.SystemClipboard"
  oClip = createUnoService(sClipName)
  oFlavors = oClip.getContents().getTransferDataFlavors()
  s = ""
  idx = -1
  For i = LBound(oFlavors) To UBound(oFlavors)
    oFlavor = oFlavors(i)
    s = s & i & " : " & oFlavor.MimeType
    If oFlavor.MimeType = "text/html" Then
      idx = i
    End If
    s = s & CHR$(10)
  Next
  'MsgBox s
  
  If idx < 0 Then
    Print "text/html mime type not found"
    Exit Sub
   End If
  
  ' Now print the actual HMTL as a string!
  Dim oData As Variant
  oData = oClip.getContents().getTransferData(oFlavors(idx))
  s = ""
  For i = LBound(oData) To UBound(oData)
    s = s & CHR$(oData(i))
  Next
  MsgBox s

If I kept going, then I would attempt to then use the transferable content directly, which is obtained from oClip.getContents() I believe. But, one of the real questions is.... Does the clipboard have the contents shown in the correct format? I assume it does. 

So, perhaps this helps a little anyway. 

Andrew Pitonyak


On Sunday, March 26, 2023 06:06 EDT, Zorg <zorg@xxxxxxxxxxxx> wrote:
 
 

Hello

Hope some can help me here

Here is my  problem


We are developing our software using the uno api python

We re trying to to copy a string formatted in html in a libreoffice odt

We manage to do it but using dispatcher
The problem is that dispatcher not working in headless mode so il force us to use a xserver (xvfb) et Xclip.

It work but it's far from being optimized.

here is the code https://github.com/Probesys/lotemplate/blob/html_formatting/lotemplate/classes.py line 349-355

We have try using XTransferable but without any success.

Thanks in advance for your help

Sorg

 
 
 


 

[Index of Archives]     [LARTC]     [Bugtraq]     [Yosemite Forum]     [Photo]

  Powered by Linux