Forum


Replies: 10   Views: 966
Tranformdocument docx to pdf/a
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by dev-info  · 27-02-2023 - 10:35

hello, i need to convert docx to pdf in pdf/A format.
I transform word documents into pdf, but even with the pdfa option of libreOffice, the pdf is not in PDF/A
What to do? how to do ?

my code test :

 $docx->transformDocument($racine.$name.'.docx', $racine.$name.'.pdf' , array('pdfa1'=> true));

 $docx->transformDocument($racine.$name.'.docx', $racine.$name.'.pdf' ,'libreoffice', array('pdfa1'=> true));

THANKS

Christopher

Posted by admin  · 27-02-2023 - 10:48

Hello,

Using phpdocx 10, please check the docs folder included in the package. phpdocx 11 renamed this folder to macros-libreoffice.

In this folder you can read the instructions and the macros to be used with the conversion plugin based on LibreOffice. To generate PDF/A-1 files, you need to add the Generate PDF A-1.txt macro to your LibreOffice installation (as explained in How to use macros.txt) and then call:

$docx->transformDocument('document.docx', 'document.pdf', 'libreoffice', array('pdfa1' => true));

We also recommend you use the latest version of LibreOffice.

Regards.

Posted by dev-info  · 27-02-2023 - 11:07

Thank you for your reply,
I am on version 10 phpdocx
I added the macro Sub SaveToPdfA1(cFile) ,

but it does not run on this line:

oPropertyValue.Name = "Hidden"

mentioned error:

BASIC syntax error.
Unexpected symbol: &.

My calling code is indeed the one you mentioned:
$docx->transformDocument('document.docx', 'document.pdf', 'libreoffice', array('pdfa1' => true));

and i have the latest version of libreoffice

What are my solutions?
THANKS

Posted by admin  · 27-02-2023 - 11:49

Hello,

All macros are fully tested and working. We have tested the Generate PDF A-1.txt macro included in phpdocx 10 and it's working correctly.

What OS are you using? How have you added the macro? Please note that as explained in the documentation, the macros included in the package must be added to the Module1.xba file of the user that runs LibreOffice, not using the LibreOffice GUI.

The following line is correct and valid in the Module1.xba:

oPropertyValue.Name = "Hidden"

If you are opening LibreOffice to add the macro using the GUI, then you may need to add:

oPropertyValue.Name = "Hidden"

Regards.

Posted by dev-info  · 27-02-2023 - 13:13

 

Thank you for your reply,

Indeed, on libreoffice on server linux, by terminal, installing the macro and generating a pdfa: that's works.

the problem is for my local windows environment with libreofficeGUI.

Do you have a version of SaveToPdfA1(cFile) for the libreoffice GUI windows10 module1?

Because I changed the quote by "",

now the error is on: cURL = convertToURL(cFile)

error message: BASIC runtime error. The argument is not optional

 

Thanking you for your help

 

Christophe

Posted by admin  · 27-02-2023 - 13:54

Hello,

All macros included in phpdocx to be used with LibreOffice must be added to the Module1.xba file, because they work using PHP methods such as:

$docx->transformDocument('document.docx', 'document.pdf', 'libreoffice', array('toc' => true));
$docx->transformDocument('document.docx', 'document.docx', 'libreoffice', array('comments' => true));

so they need one or more arguments to run.

These macros work will all OS where LibreOffice can be installed. Windows also has a Module1.xba file (the default path of this file is in the AppData\Roaming\LibreOfice folder of the user's profile).

Adding them using LibreOffice GUI requires removing parameters/URLs (they are not used by the LibreOffice GUI) and replacing protected characters. phpdocx supports adding them to the Module1.xba so they can be called from PHP. Sorry but we don't have macro versions to be added using the LibreOffice GUI. In this case, that is not used phpdocx, we recommend you check the documentation from LibreOffice:

https://books.libreoffice.org/en/GS70/GS7013-GettingStartedWithMacros.html#toc8

You can record a macro and the code we'll be generated automatically in the LibreOffice GUI.

Regards.

Posted by dev-info  · 27-02-2023 - 14:24

Thank you for your reply.

I added the macro to the file
C:\users\xxxx\Appdata\Roaming\LibreOffice\4\User\Basic\Standard\Module1.xba
I have no code error,
But no PDF file generates with this call:

$docx->transformDocument('doc.docx', 'doc.pdf','libreoffice' , array('pdfa1'=> true));


I have exhausted all my resources, and I tested all the solution you have offered me.
I don't understand where I make a mistake.
Without the pdfa option, the PDF gets good. 

:( 

Posted by admin  · 27-02-2023 - 14:52

Hello,

The macro is fully tested using Windows too. In any case, we have tested it again using Windows and LibreOffice with the macro included in phpdocx 10, and the PDF A-1 is generated correctly.

If the PDF is not being generated then the macro has not been added to the correct Module1.xba file (maybe in your installation you are using another path as HOME user folder) or there's some issue related to paths or permissions.

We recommend you open LibreOffice to check the exact macro file you need to change and also test the same using a terminal (PowerShell or CMD).

We have tested it following these simple steps and everything is working correctly:

  • Path to libreoffice in config/phpdocxconfig.ini:
; libreoffice, native, msword, openoffice
method = "libreoffice"

; libreoffice installation path, absolute path
path = '"C:\Program Files\LibreOffice\program\soffice"'
  • Macro into the Module1.xba file.
  • Run the following command:
$docx->transformDocument('document.docx', 'document.pdf', 'libreoffice', array('pdfa1' => true));

using PHP CLI:

> php sample_1.php

and the PDF A-1 is generated correctly.

Sorry, but we don't know the exact step you have not done correctly. We'd need to check your server.

Regards.

Posted by dev-info  · 27-02-2023 - 15:39

thank you to your answer.

In cmd line that works like wthis:

start soffice.exe --invisible "macro:///Standard.Module1.SaveToPdfA1("C:\wamp64\doc.docx")"

 

all files/folders are in all control to my user windows( and im admin)

so, sofficework, but not this command if its call by php with library phpdocx

hmm, very strange. 

do you have some ID?

 

Thank you

Posted by admin  · 27-02-2023 - 16:07

Hello,

The reason must be that the Module1.xba file used by the PHP user that calls LibreOffice is not the same than the user that runs LibreOffice directly or the PHP user doesn't have read access to the macro folder/file. We recommend you check this and add the macro to the Module1.xba file used by the PHP user that calls LibreOffice. And also test using PHP CLI and the web server.

Regards.

Posted by dev-info  · 28-02-2023 - 10:14

hello, 
I finally found the solution:
after several tries, by launching the command via cmd, it worked well,

calling without macro via php worked fine,


So the problem really came from the php call on soffice.exe with a macro

I went to the windows service, on the apache service of the wampserver, I changed the "local system" connection to an administrator account.

I restarted the apache service and it worked fine.

I think that previously, the apache server was installed on my user profile, without me being an administrator (I became admin later), so apache had permissions to run exe but no macro

Thank you again for your follow-up and your involvement.

Beautiful day to you(Modifié)Restaurer la traduction d'origine