11

In Libreoffice Draw when using File → Export and choosing an image format, notably when using EPS to preserve the vector character of the figure, there is a checkbox "selection" which causes the exported image to be cropped automatically to the contents of the image.

I want to use the vector grapgics primarily with PDFLaTeX and would therefore prefer to export directly to PDF. However, when exporting to pdf by either File → Export or File → Export as PDF no cropping is performed, regardless of settings.

Is there some viable workaround to get an auto-cropped PDF directly from Draw?

My current unsatisfying workarounds are

  • exporting as EPS and leaving PDF conversion to the pdftoeps latex package. Downside: Unnecessary file clutter.
  • manually changing page size. Downside: I don't know a method to automatically crop the page. Also this solution is not appropriate when having multiple sheets with figures of different size.

3 Answers 3

8

Did some experiments, and seems to me that LibreOffice will always put your graphics on your page format (and I'm not sure that this is a wrong choice, anyways).
But I found that if you use File → Export as PDF you can check Selectionin Range section to make it export only selected elements, however it will always put them on your original page format.

But after you created your PDF file you can automatically crop away blank areas using cli tools like pdfcrop, as described here: https://askubuntu.com/questions/124692/command-line-tool-to-crop-pdf-files

For example, you can crop illustration.pdf leaving a 5 pt margin with:

pdfcrop --margin 5 illustration.pdf

There are also GUI applications that can crop PDF files, such Briss. For similar tools see also https://stackoverflow.com/a/17406976/793641

On Mac OSX you can even use Preview.app to crop PDF files. Just use the rectangular selection tool from menus, select the area you need and then use the crop tool from the same menu.

3
  • 1
    While it is automatic in the sense that I don't have to manually change page borders, it still requires an additional, manual step. So I'd still prefer the "export as EPS, let pdflatex convert it to pdf when compiling" version. When working on a latex document I typically work with a feedback cycle of "edit image, export, recompile" which can occur dozens of times before the graphic is finished, so adding extra manual steps doesn't improve the workflow.
    – kdb
    Feb 7, 2015 at 11:11
  • You can setup a simple Makefile and setup a rule to crop your PDF files as a requirement for make all. This way you could just crop illustrations and compile the whole document in one step. See for example: danielkaes.wordpress.com/2009/03/14/…
    – gerlos
    Feb 10, 2015 at 18:09
  • As of today, there is still no option in the pdf export options of LibreOffice to do that… As a consequence, unoconv also have the same limitation. Ps: Related
    – Clément
    Jan 3, 2017 at 17:13
1

on ubuntu, this works for me:

1) ctrl+a to select your drawing only
2) export as SVG into FOLDER, while the selection box is ticked
2) run this bash script to convert all SVG files in FOLDER to PDF:

#!/bin/bash
for f in *.svg; do
rsvg-convert -f pdf -o "${f%.*}.pdf" "$f" 
done

NOTE: you need to install rsvg-convert
NOTE: same works for libre office impress

1
  • Sadly, this has the same downsides as the EPS method, and requires more work from the user. (Though it probably avoids issues with transparecy and similar.)
    – kdb
    May 4, 2018 at 13:49
-1

You can change the page settings to a custom size instead of A4, it's still annoying that you need to define it in some way but at least you only need to do it ones and not for every new change you make. (as long as your image size doesn't change in the edits).

Page settings

2
  • That's mentioned in the original question though.
    – kdb
    Apr 5, 2022 at 12:21
  • Ooh seems I misunderstood it, I thought he was talking about resizing the pdf page size after the draw to pdf conversion. Apr 11, 2022 at 13:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .