converting doc or docx file to pdf

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

converting doc or docx file to pdf

Post by suman114 »

Hello,

I am trying to convert a doc file to pdf with imagemagick.
The debug log shows that the doc file is successfully converted to pdf, but while moving it, it tries to find a doc that doesn't exists. Eg;

Code: Select all

convert -verbose apple.doc logo.png -gravity south -quality 100 -fill "rgba(180,180,180,0.80)" -pointsize 18 -weight bold -annotate +0+50 "Downloaded from Hart Energy's Alexandria Library" -compose multiply -layers composite output.pdf
Log:

Code: Select all

"soffice" --headless --convert-to pdf --outdir `dirname "apple.doc"` "apple.doc" 
2> "/tmp/magick-27774N2VanFQ6A6bn"; mv "apple.doc.pdf" "/tmp/magick-27774IwoX-tNyM0gj"
convert apple.doc -> apple.pdf using writer_pdf_Export
Overwriting: apple.pdf
mv: cannot stat ‘apple.doc.pdf’: No such file or directory
The above log is slightly modified. My question is why is it trying to move apple.doc.pdf instead of apple.pdf?

And how do I fix this?
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: converting doc or docx file to pdf

Post by Bonzo »

Your code options order looks a bit of a mess. I would start with something simple for instance compositing the two images and then build in the rest of your code. This would prove that part works as you have so many parts where it can go wrong.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting doc or docx file to pdf

Post by fmw42 »

Bonzo is correct. Just try converting the apple.doc to pdf. See if that works.

I see a couple of possible issues with your command.

First, you may need to use parenthesis about the logo.png and annotate to isolate it to just the logo. Your code may be trying to process both images with the annotate. See http://www.imagemagick.org/Usage/basics/#parenthesis

Second, I am not sure you can use a compose method with layers composite. Try just -compose multiplly -composite or -compose multiply -layers merge +repage. layers composite is typically used to merge animations. See
http://www.imagemagick.org/Usage/anim_mods/#composite
http://www.imagemagick.org/Usage/layers/#compose
http://www.imagemagick.org/Usage/layers ... _composite
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting doc or docx file to pdf

Post by snibgo »

Perhaps the OP wants to multiply logo.png with each image from apple.doc. If so, a "NULL:" is needed between them. I don't know what should be annotated.

In any case, I agree with Bonzo and Fred. Break down the problem into sub-problems, as as simple as possible, each one a "convert" command. Debug each one. Then, when it all works, optimise by combining the commands.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting doc or docx file to pdf

Post by fmw42 »

Good point snibgo. I was assuming he had one single page doc file and one logo. But I think you are probably right in that he wants to watermark each page of the doc file with the logo. -layers composite is then correct, but I do not think you can do -compose with that. But a NULL: is definitely needed between the two images when using -layers composite. If the user wants a less pronounce watermark that and overlay, then he should modify the logo's transparency.
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Re: converting doc or docx file to pdf

Post by suman114 »

The above code works well while converting pdf to watermarked pdf.
I am trying to convert doc file to watermarked pdf. And it gave that error. Why is it trying to find the apple.doc.pdf instead of converted apple.pdf?
The apple.pdf is actually created. Just gives the above mentioned error
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Re: converting doc or docx file to pdf

Post by suman114 »

Even simple converting doc shows the same error

Code: Select all

convert -verbose aaaaa.doc outputsss.pdf
"soffice" --headless --convert-to pdf --outdir `dirname "aaaaa.doc"` "aaaaa.doc" 2> "/tmp/magick-13123jDqOlCXpGDh8"; mv "aaaaa.doc.pdf" "/tmp/magick-13123_Eb6RP3Vcg46"
convert /home/suman/aaaaa.doc -> /home/suman//aaaaa.pdf using writer_pdf_Export
mv: cannot stat ‘aaaaa.doc.pdf’: No such file or directory
convert: delegate failed `"soffice" --headless --convert-to pdf --outdir `dirname "%i"` "%i" 2> "%Z"; mv "%i.pdf" "%o"' @ error/delegate.c/InvokeDelegate/1333.
convert: unable to open image `/tmp/magick-13123gXfKk44RNnuB': No such file or directory @ error/blob.c/OpenBlob/2702.
convert: unable to open file `/tmp/magick-13123gXfKk44RNnuB': No such file or directory @ error/constitute.c/ReadImage/540.
convert: no images defined `outputsss.pdf' @ error/convert.c/ConvertImageCommand/3252.
convert -version shows following delegates

Code: Select all

Delegates (built-in): bzlib djvu fftw fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff wmf x xml zlib
Do I need the doc, docx and other office file extension there as well?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting doc or docx file to pdf

Post by fmw42 »

We have been unsure of your purpose. Are you trying to convert a single page doc or a multipage doc? If the latter, are you trying to add the logo to each page or just one page? If you are trying to watermark each page, then you need a NULL: between the doc image and the logo image.

You may be getting one error message that is confusing, if IM detects a different issue such as a missing NULL: when using -layers composite.

Please try what we have suggested above or give us more information about your goals and data.
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Re: converting doc or docx file to pdf

Post by suman114 »

Please see my last post. All I am trying to do is convert a multipage doc to pdf file with

Code: Select all

convert aaaaa.doc outputsss.pdf
Disregard all other content. The above command throws me error

Code: Select all

"soffice" --headless --convert-to pdf --outdir `dirname "aaaaa.doc"` "aaaaa.doc" 2> "/tmp/magick-13123jDqOlCXpGDh8"; mv "aaaaa.doc.pdf" "/tmp/magick-13123_Eb6RP3Vcg46"
convert /home/suman/aaaaa.doc -> /home/suman//aaaaa.pdf using writer_pdf_Export
mv: cannot stat ‘aaaaa.doc.pdf’: No such file or directory
convert: delegate failed `"soffice" --headless --convert-to pdf --outdir `dirname "%i"` "%i" 2> "%Z"; mv "%i.pdf" "%o"' @ error/delegate.c/InvokeDelegate/1333.
convert: unable to open image `/tmp/magick-13123gXfKk44RNnuB': No such file or directory @ error/blob.c/OpenBlob/2702.
convert: unable to open file `/tmp/magick-13123gXfKk44RNnuB': No such file or directory @ error/constitute.c/ReadImage/540.
convert: no images defined `outputsss.pdf' @ error/convert.c/ConvertImageCommand/3252.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting doc or docx file to pdf

Post by fmw42 »

convert aaaaa.doc outputsss.pdf
Should work fine if you have the correct delegate program and the delegates.xml file points to the location of that delegate. Do you have Soffice in your delegates.xml file and is it pointing to the correct location for that file. If not, the put the full path to that delegate and make sure you have a current version of it on your system. Perhaps your should post a link to your aaaaa.doc file so one of the Windows users can test with it.
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Re: converting doc or docx file to pdf

Post by suman114 »

fmw42 wrote:
convert aaaaa.doc outputsss.pdf
Should work fine if you have the correct delegate program and the delegates.xml file points to the location of that delegate. Do you have Soffice in your delegates.xml file and is it pointing to the correct location for that file. If not, the put the full path to that delegate and make sure you have a current version of it on your system. Perhaps your should post a link to your aaaaa.doc file so one of the Windows users can test with it.
convert -version

Code: Select all

Delegates (built-in): bzlib djvu fftw fontconfig freetype gvc jbig jng jpeg lcms lqr lzma openexr pangocairo png tiff wmf x xml zlib
no soffice delegates seen here.

But

Code: Select all

 soffice --headless --convert-to pdf --outdir apps.pdf aaaaa.doc
works just fine.

My delegate.xml has following with other many delegates as well.

Code: Select all

<delegate decode="doc" command=""soffice" --headless --convert-to pdf --outdir `dirname "%i"` "%i" 2> "%Z"; mv "%i.pdf" "%o""/>
  <delegate decode="docx" command=""soffice" --headless --convert-to pdf --outdir `dirname "%i"` "%i" 2> "%Z"; mv "%i.pdf" "%o""/>
  
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: converting doc or docx file to pdf

Post by snibgo »

What is the platform? Not Windows, I hope. That delegate command won't work on Windows, because it doesn't have the bash back-tick mechanism.
snibgo's IM pages: im.snibgo.com
suman114
Posts: 13
Joined: 2016-04-17T23:51:39-07:00
Authentication code: 1151

Re: converting doc or docx file to pdf

Post by suman114 »

its linux/ ubuntu
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: converting doc or docx file to pdf

Post by fmw42 »

try adding the full path to soffice in

command=""path2/soffice"

In your delegate.xml file line you have above
Post Reply