PDF4QT/Pdf4QtLib/sources/pdfdocumentwriter.h

78 lines
2.8 KiB
C
Raw Normal View History

2020-03-22 15:30:34 +01:00
// Copyright (C) 2020 Jakub Melka
//
2020-12-20 19:03:58 +01:00
// This file is part of Pdf4Qt.
2020-03-22 15:30:34 +01:00
//
2020-12-20 19:03:58 +01:00
// Pdf4Qt is free software: you can redistribute it and/or modify
2020-03-22 15:30:34 +01:00
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
2020-12-20 19:03:58 +01:00
// Pdf4Qt is distributed in the hope that it will be useful,
2020-03-22 15:30:34 +01:00
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
2020-12-20 19:03:58 +01:00
// along with Pdf4Qt. If not, see <https://www.gnu.org/licenses/>.
2020-03-22 15:30:34 +01:00
#ifndef PDFDOCUMENTWRITER_H
#define PDFDOCUMENTWRITER_H
#include "pdfdocument.h"
#include "pdfprogress.h"
#include "pdfutils.h"
#include <QIODevice>
namespace pdf
{
/// Class used for writing PDF documents to the desired target device (or file,
/// buffer, etc.). If writing is not successful, then error message is returned.
2020-12-20 19:03:58 +01:00
class Pdf4QtLIBSHARED_EXPORT PDFDocumentWriter
2020-03-22 15:30:34 +01:00
{
Q_DECLARE_TR_FUNCTIONS(pdf::PDFDocumentWriter)
public:
explicit inline PDFDocumentWriter(PDFProgress* progress) :
m_progress(progress)
{
}
2020-06-07 17:46:49 +02:00
/// Writes document to the file. If \p safeWrite is true, then document is first
/// written to the temporary file, and then renamed to original file name atomically,
/// so no data can be lost on, for example, power failure. If it is not possible to
/// create temporary file, then writing operation will attempt to write to the file
/// directly.
/// \param fileName File name
/// \param document Document
/// \param safeWrite Write document to the temporary file and then rename
PDFOperationResult write(const QString& fileName, const PDFDocument* document, bool safeWrite);
/// Write document to the output device. Device must be writable (i.e. opened
/// for writing).
/// \param device Output device
/// \param document Document
2020-03-22 15:30:34 +01:00
PDFOperationResult write(QIODevice* device, const PDFDocument* document);
2020-05-31 18:31:59 +02:00
/// Calculates document file size, as if it is written to the disk.
/// No file is accessed by this function; document is written
/// to fake stream, which counts operations. If error occurs, and
/// size can't be determined, then -1 is returned.
/// \param document Document
static qint64 getDocumentFileSize(const PDFDocument* document);
2020-03-22 15:30:34 +01:00
private:
void writeCRLF(QIODevice* device);
void writeObjectHeader(QIODevice* device, PDFObjectReference reference);
void writeObjectFooter(QIODevice* device);
/// Progress indicator
PDFProgress* m_progress;
};
} // namespace pdf
#endif // PDFDOCUMENTWRITER_H