Neriderc / GVExport

Repository for GVExport module for Webtrees
GNU General Public License v2.0
15 stars 6 forks source link

size of exported pdf #466

Closed arbor95 closed 5 months ago

arbor95 commented 6 months ago

The size of the exported pdf is very big. What is the reason? How to shrink after export?

schuco commented 6 months ago

See #420 Main reason for exploding size of diagrams with output type pdf is the size of embedded jpg-photos. In the advanced settings you can set the quality of jpg photos to low and in addition allow photos to be converted to jpg. In my experience this is without visual loss of quality. In addition you might reduce Diagram dpi settings in the advanced settings of section appearance.

Please note, that my experience is from an installation with Grapviz on the server.

Proceeding as described above may still result in (too) big pdf-files. Then it is very effective to use a PDF-editor (PDF-Architect in my case) to compress the pdf-file. Sometimes this reduces files almost 10-fold.

arbor95 commented 6 months ago

I am without Graphviz. Using Combined diagram type. I can not see a setting for quality. (resolution is 100%, size is 100%, but sure not from the original jpg what is for all my photos 240x320 pixel)

Having a look into the generated pdf: Seems to me as if : The complete content consists of image stripes.

Neriderc commented 6 months ago

The quality options don't apply if you don't have Graphviz installed on the server, as in this case the output is generated entirely in the browser. And unlike when you have Graphviz on the server, the images you use don't matter as they are not embedded in the document.

There is definitely something funny happening with PDF.

PDF generation uses a JavaScript library to generate the PDF based on a PNG image (basically, it takes the PNG output then feeds this into the PDF creator).

For some reason, if I create a PNG of a large diagram I get a normal file size (for my test diagram about 7MB), but if I generate a PDF of the same diagram it is 260MB!

I'm not sure of the reason, I'll have to do some digging.

Neriderc commented 5 months ago

After a lot of digging and trying out things, in the end the issue was that jsPDF by default doesn't compress the file. It was as simple as setting a setting to compress the file.

I've pushed this into the main branch, so anyone keen can download from that branch and start using this right away (let me know if you need help with this), but please note that the main branch has an updated Graphviz renderer and still has at least one minor display issue, #465. These are the only unreleased changes so far.

Another option is to go into the extension directory, open the Data.js file in resources/javascript/MainPage, and find this line (line 207): const doc = new window.jspdf.jsPDF({orientation: orientation, format: [widthInches, heightInches], unit: 'in'});

And replace it with: const doc = new window.jspdf.jsPDF({orientation: orientation, format: [widthInches, heightInches], unit: 'in', compress: true});