Author Topic: DOC into PDF  (Read 10423 times)

0 Members and 1 Guest are viewing this topic.

LukeV

  • Newbie
  • *
  • Posts: 30
DOC into PDF
« on: March 23, 2012, 01:40:24 AM »
Hi Rui,

Not sure if this is at all possible, put a great feature would be turning DOC files into PDF's, like you have for the JPG files.
I imagine it is probably not possible, as pictures can just be embedded in but DOC's would almost need to be printed to a PDF.

RTT

  • Administrator
  • *****
  • Posts: 907
Re: DOC into PDF
« Reply #1 on: March 23, 2012, 07:53:09 PM »
Hi Luke,
Such a tool is by itself a big project.
A direct Doc to PDF can only be done by a tool that fully understand, and correctly renders, the format, so the best approach is definitively the print to PDF solution. Such tools usually automate (or require user intervention) the MS Word or Word Previewer, to print to the postscript format (using a postscript printer driver), and then use a postscript to PDF converter, such as the AFL-GhostScript. Even the Adobe Acrobat tools use this method, complemented by additional processing to add hyperlinks, bookmarks, etc..
I could use such methods in PDF-ShellTools, but using third party solutions is not the spirit of the tools, so that's something not workable right now.

The Open Office Writer is able to do a direct conversion, so you can use it to open a .doc and then export it to a PDF. And this tool can be automated, so I suppose you can easily create a script and add it to the Shell context menu. ;)


LukeV

  • Newbie
  • *
  • Posts: 30
Re: DOC into PDF
« Reply #2 on: March 25, 2012, 11:30:33 PM »
Thanks for the response. I thought this might be the case, but thought I'd ask just in case there was a way.

I'll have a look into the Open Office Writer idea though ;) Thanks!

LukeV

  • Newbie
  • *
  • Posts: 30
Re: DOC into PDF
« Reply #3 on: March 29, 2012, 01:02:20 AM »
So I took your advise.
I went with LibreOffice and came up with the following in a batch file, which I have in my Send To folder:

ECHO off
cd %~p1
soffice -headless -convert-to PDF %1


I'm now just trying to get it to be able to run on multiple selected files. Unfortunately, you can't use "/folder/*.doc" as the -convert-to doesn't allow wildcards in Windows :(
The only way I can see would be a loop in the batch, with a pause to wait for each conversion to take place.

RTT

  • Administrator
  • *****
  • Posts: 907
Re: DOC into PDF
« Reply #4 on: March 29, 2012, 03:54:49 PM »
Can't make that command line work here, so can't test possible solutions to accomplish that.
But I was talking about the more powerful COM Automation.
I digged a bit about this subject, and I coded this little script in VBScript.
Code: [Select]
Option Explicit

Sub SaveAsPDF(filename)
' ********************************
' Save an existing document as PDF
' ********************************
Dim oDoc
Dim OpenParam(0)
Dim SaveParam(0)
Dim sUrl

Set OpenParam(0) = MakePropertyValue("Hidden", True)  ' Open the file hidden
sURL = "file:///" & Replace(filename, "\" , "/")
Set oDoc = oDesk.loadComponentFromURL(sURL, "_blank", 0, OpenParam)

set SaveParam(0) = MakePropertyValue("FilterName", "writer_pdf_Export")
sURL = left(sURL,InStrRev(sURL,"."))+"pdf"
Call oDoc.storeToURL(sURL, SaveParam)

oDoc.close(true)
Set oDoc = Nothing
End Sub

Public Function MakePropertyValue(cName, uValue)
Dim oStruct
    Set oStruct = oSM.Bridge_GetStruct("com.sun.star.beans.PropertyValue")
    oStruct.Name = cName
    oStruct.Value = uValue
    Set MakePropertyValue = oStruct
End Function

Dim oSM, oDesk
Set oSM = CreateObject("com.sun.star.ServiceManager")
Set oDesk = oSM.createInstance("com.sun.star.frame.Desktop")

Dim i
for i=0 to WScript.Arguments.count-1               
SaveAsPDF(WScript.Arguments.Item(i))
Next
oDesk.Terminate()

Just place it in a .vbs file, in the "send to" folder, and you have now a powerful toPDF converter, that's able to convert any of the file formats the OOo Writer can read, into the PDF format ;)
This uses the OOo ActiveX control, so make sure you install it when installing the OpenOffice.
I just tested it with the OpenOffice.org, so I have no idea if it also works with LibreOffice.

LukeV

  • Newbie
  • *
  • Posts: 30
Re: DOC into PDF
« Reply #5 on: April 04, 2012, 01:20:59 AM »
I can't my script working now either :P
I did have it working last week. Seems my method of getting the file path isn't working now. You also had to set the folder with soffice in it in your PATH.

In any case, your script is a much better approach and makes my attempt seem feeble  :-[

On my PC it opens up with LibreOffice and works, even though I have OpenOffice and LibreOffice installed.
Apparently LibreOffice converts the files with a bit more accuracy.

Is there any way of running OO/LO in headless mode via the script, so it doesn't show up on the toolbar?



RTT

  • Administrator
  • *****
  • Posts: 907
Re: DOC into PDF
« Reply #6 on: April 04, 2012, 07:38:29 PM »
Quote
Is there any way of running OO/LO in headless mode via the script, so it doesn't show up on the toolbar?
That's what the next line is supposed to do.
      Set OpenParam(0) = MakePropertyValue("Hidden", True)  ' Open the file hidden
In here, with OOo, it's working. The conversion is made without you even realize, except for the disk activity, any program has been called. Completely hidden.
Maybe the LO changed something related to this. You have the two installed, so try to use the OOo instead. You probably need to change the path at this registry key

      32-bit Windows
      HKEY_CLASSES_ROOT\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\LocalServer32
      64-bit Windows
      HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{82154420-0FBF-11d4-8313-005004526AB4}\LocalServer32

to point to where you have the related OOo file installed.

LukeV

  • Newbie
  • *
  • Posts: 30
Re: DOC into PDF
« Reply #7 on: April 05, 2012, 12:24:22 AM »
You are correct as normal. OpenOffice is running hidden while LibreOffice doesn't.

gavind

  • Newbie
  • *
  • Posts: 1
Re: DOC into PDF
« Reply #8 on: June 06, 2012, 11:20:43 PM »
I agree. I use Openoffice.
Two for the Money