diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2022-10-18 16:14:37 +0530 |
---|---|---|
committer | Dennis Francis <dennis.francis@collabora.com> | 2022-10-27 07:54:59 +0200 |
commit | 3f9e8ac6172f5b1dfd2869ee1c6aea4f24d3f480 (patch) | |
tree | 6ae6d6bda239a001b3cc4827935d4215bc0156ac /vcl/inc | |
parent | bdb76c9ff1832041fa7a9bda30e8d4d7d937ff94 (diff) |
vcl: re-exporting broken pdfs -> empty pages
Certain pdf documents when loaded in LO_IMPORT_USE_PDFIUM=1 mode even if
pdf-version < v1.6 sometimes has missing objects referred by other
objects for determing its stream length for instance. As a result
parsing fails and results in a pdf with empty pages. A round trip
through pdfium and exporting to v1.6 seems to cure the issue. Possibly
it does some repairing work to determine the length of the stream in a
independent pass through the file.
Conflicts:
vcl/source/filter/ipdf/pdfread.cxx
Change-Id: Id09f67eddab4163ed12a3a3f3a73baf92e2912aa
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141856
Tested-by: Jenkins
Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
Diffstat (limited to 'vcl/inc')
-rw-r--r-- | vcl/inc/pdf/ExternalPDFStreams.hxx | 2 | ||||
-rw-r--r-- | vcl/inc/pdf/pdfcompat.hxx | 42 |
2 files changed, 43 insertions, 1 deletions
diff --git a/vcl/inc/pdf/ExternalPDFStreams.hxx b/vcl/inc/pdf/ExternalPDFStreams.hxx index 7840217630c8..45b15f7a74bc 100644 --- a/vcl/inc/pdf/ExternalPDFStreams.hxx +++ b/vcl/inc/pdf/ExternalPDFStreams.hxx @@ -42,7 +42,7 @@ struct VCL_DLLPUBLIC ExternalPDFStream aPDFStream.WriteBytes(maDataContainer.getData(), maDataContainer.getSize()); aPDFStream.Seek(0); auto pPDFDocument = std::make_shared<filter::PDFDocument>(); - if (!pPDFDocument->Read(aPDFStream)) + if (!pPDFDocument->ReadWithPossibleFixup(aPDFStream)) { SAL_WARN("vcl.pdfwriter", "PDFWriterImpl::writeReferenceXObject: reading the PDF document failed"); diff --git a/vcl/inc/pdf/pdfcompat.hxx b/vcl/inc/pdf/pdfcompat.hxx new file mode 100644 index 000000000000..8f629b3bc8ee --- /dev/null +++ b/vcl/inc/pdf/pdfcompat.hxx @@ -0,0 +1,42 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#pragma once + +#include <config_features.h> +#include <tools/gen.hxx> +#include <tools/stream.hxx> +#include <tools/UnitConversion.hxx> +#include <vcl/graph.hxx> + +namespace vcl::pdf +{ +/// Convert to inch, then assume 96 DPI. +inline double pointToPixel(const double fPoint, const double fResolutionDPI) +{ + return o3tl::convert(fPoint, o3tl::Length::pt, o3tl::Length::in) * fResolutionDPI; +} + +/// Decide if PDF data is old enough to be compatible. +bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize); + +/// Converts to highest supported format version (currently 1.6). +/// Usually used to deal with missing referenced objects in the +/// source pdf stream. +bool convertToHighestSupported(SvStream& rInStream, SvStream& rOutStream); + +/// Takes care of transparently downgrading the version of the PDF stream in +/// case it's too new for our PDF export. +bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream); + +BinaryDataContainer createBinaryDataContainer(SvStream& rStream); + +} // end of vcl::filter::ipdf namespace + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |