Bug 150076 - PDF used as background in Draw is exported as low resolution image (but PDF inserted as image is exported as vector)
Summary: PDF used as background in Draw is exported as low resolution image (but PDF i...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Printing and PDF export (show other bugs)
Version:
(earliest affected)
7.3.4.2 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: filter:pdf
Depends on:
Blocks: Slide-Background PDF-Insert
  Show dependency treegraph
 
Reported: 2022-07-20 15:15 UTC by Callegar
Modified: 2024-03-20 15:12 UTC (History)
8 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Callegar 2022-07-20 15:15:44 UTC
Description:
When a PDF image is used for the background of a draw document and the document is then exported as PDF, the background is included in the PDF document as a low resolution bitmap, rather than as a vector image.

This is very much undesirable:
- the possibility to cut/copy text is lost
- the resolution is poor (96dpi)
- the vector quality of the image is lost
- in some cases the resulting PDF file gets larger than it could (this is limited by the very poor resolution of the bitmap, though)

Note that using PDF images as background represents a frequently adopted workflow for filling in forms that have been made available in PDF, but not as PDF forms.

Steps to Reproduce:
1. Open libreoffice draw
2. Insert as the background image a PDF file
3. Export to PDF
4. Open the resulting PDF file with a viewer or use some utility such as pdfimages to export the bitmaps that are present in the PDF file

Actual Results:
The background image is present in the PDF file as a 96dpi bitmap

Expected Results:
The background image should be maintained in vector format if it is in vector format to start with.


Reproducible: Always


User Profile Reset: No



Additional Info:
[Information automatically included from LibreOffice]
Locale: en-US
Module: StartModule
[Information guessed from browser]
OS: Linux (All)
OS is 64bit: yes

Version: 7.3.4.2 / LibreOffice Community
Build ID: 30(Build:2)
CPU threads: 8; OS: Linux 5.18; UI render: default; VCL: kf5 (cairo+xcb)
Locale: it-IT (en_US.UTF-8); UI: en-US
7.3.4-2
Calc: threaded
Comment 1 V Stuart Foote 2022-07-21 06:37:46 UTC
IMHO not a bug, rather a limitation of the pdfium based "insert as image" filter import. Something different, e.g. using the graphic objects PDF vector data rather than the raster output, would be an enhancement.

Undocumented, but for 7.2 builds you *can* control the pdfium based insert filter by setting env variable:

PDFIMPORT_RESOLUTION_DPI

default is the 96dpi noted, but you can take the resolution as high as is needed for work on the canvas and for 7.3 was further reworked for export/printing at the higher resolution set.

helpful when working at full page scaling for the image, i.e. as page background.

=-ref-=
[1] https://gerrit.libreoffice.org/c/core/+/113223
[2] https://gerrit.libreoffice.org/c/core/+/121087
Comment 2 V Stuart Foote 2022-07-21 06:46:25 UTC
The Wiki has info on setting env variable including PDFIMPORT_RESOLUTION_DPI, but not much about its function.

@Seth? Something needed for Help, or maybe in the Draw guide or Getting started guide...
Comment 3 Callegar 2022-07-21 07:24:33 UTC
If you use `insert → image` from the menu, and you insert the PDF image in the page rather than as the background of the page, then the PDF export works properly maintaining the vector nature of the image. Hence, the behavior for the background image is at best not consistent and from a user point of view it is really quite confusing why `Page → Set image as background` should use pdfium in a different way from `insert → image`.

Furthermore, if you insert an SVG image as the background, then the PDF export also works properly. So again there is an inconsistency in how LibO treats two different vector formats.

Because SVG support is in some cases better than PDF support (maybe in part due to the pdfium migration, that brought much more faithful conversion of PDF files to bitmaps but otherwise weakened the treatment of PDF files as a vector format) I would like to take the occasion to suggest readers who may stumble in this same issue or in other issues with PDF import to consider conversion to SVG before the import (there are many fine open source tools for that, from `dvisvgm` to `inkscape`).

Is there a [META] bug for PDF image management? I see 113122. Would that be appropriate as a tracking bug for this?
Comment 4 Stéphane Guillou (stragu) 2024-03-20 13:23:33 UTC
(In reply to Callegar from comment #3)
> If you use `insert → image` from the menu, and you insert the PDF image in
> the page rather than as the background of the page, then the PDF export
> works properly maintaining the vector nature of the image. Hence, the
> behavior for the background image is at best not consistent and from a user
> point of view it is really quite confusing why `Page → Set image as
> background` should use pdfium in a different way from `insert → image`.
> 
> Furthermore, if you insert an SVG image as the background, then the PDF
> export also works properly. So again there is an inconsistency in how LibO
> treats two different vector formats.
Reproduced as described. Right click > Page > Background > PDF results in bad bitmap resolution when exported, whereas Insert > Image > PDF keeps it as vector.

Interestingly, when trying to create a sample document, I also noticed that if I insert the PDF as a page background first, and then on another page insert the same PDF as an image, I get bad resolution on _both_ in the PDF export.
So to compare image insert vs page background, work on two files separately.

Version: 24.8.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 53c5d570cab036b23f4969b858a648c8f0c24f93
CPU threads: 8; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US
Calc: CL threaded
Comment 5 V Stuart Foote 2024-03-20 15:12:38 UTC
(In reply to Stéphane Guillou (stragu) from comment #4)

And if you set the PDFIMPORT_RESOLUTION_DPI environment variable?