| 1 |
/** |
| 2 |
* SPDX-FileCopyrightText: (C) 2007 Pierre Marchand <[email protected]> |
| 3 |
* SPDX-License-Identifier: GPL-2.0-or-later |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef PDFTRANSLATOR_H |
| 7 |
#define PDFTRANSLATOR_H |
| 8 |
|
| 9 |
#include <podofo/podofo.h> |
| 10 |
#include "impositionplan.h" |
| 11 |
|
| 12 |
#include <string> |
| 13 |
#include <map> |
| 14 |
#include <set> |
| 15 |
#include <vector> |
| 16 |
#include <sstream> |
| 17 |
#include <istream> |
| 18 |
#include <string> |
| 19 |
|
| 20 |
namespace PoDoFo::Impose |
| 21 |
{ |
| 22 |
/** |
| 23 |
PdfTranslator create a new PDF file which is the imposed version, following the imposition |
| 24 |
plan provided by the user, of the source PDF file. |
| 25 |
Pdftranslate does not really create a new PDF doc, it rather works on source doc, getting all page contents |
| 26 |
as XObjects and put these XObjects on new pages. At the end, it removes original pages from the doc, but since |
| 27 |
PoDoFo keeps them --- just removing from the pages tree ---, if it happens that you have a lot of content |
| 28 |
in content stream rather than in resources, you'll get a huge file. |
| 29 |
Usage is something like : |
| 30 |
p = new PdfTranslator; |
| 31 |
p->setSource("mydoc.pdf"); |
| 32 |
p->setTarget("myimposeddoc.pdf"); |
| 33 |
p->loadPlan("in4-32p.plan"); |
| 34 |
p->impose(); |
| 35 |
p->mailItToMyPrinterShop("[email protected]");//Would be great, doesn't it ? |
| 36 |
*/ |
| 37 |
class PdfTranslator |
| 38 |
{ |
| 39 |
public: |
| 40 |
PdfTranslator(); |
| 41 |
|
| 42 |
~PdfTranslator() { } |
| 43 |
|
| 44 |
PdfMemDocument* sourceDoc; |
| 45 |
PdfMemDocument* targetDoc; |
| 46 |
|
| 47 |
/** |
| 48 |
Set the source document(s) to be imposed. |
| 49 |
Argument source is the path of the PDF file, or the path of a file containing a list of paths of PDF files... |
| 50 |
*/ |
| 51 |
void setSource(const std::string& source); |
| 52 |
|
| 53 |
/** |
| 54 |
Another way to set many files as source document. |
| 55 |
Note that a source must be set before you call addToSource(). |
| 56 |
*/ |
| 57 |
void addToSource(const std::string& source); |
| 58 |
|
| 59 |
/** |
| 60 |
Set the path of the file where the imposed PDF doc will be save. |
| 61 |
*/ |
| 62 |
void setTarget(const std::string& target); |
| 63 |
|
| 64 |
/** |
| 65 |
Load an imposition plan file of form: |
| 66 |
widthOfSheet heightOfSheet |
| 67 |
sourcePage destPage rotation translationX translationY |
| 68 |
... ... ... ... ... |
| 69 |
*/ |
| 70 |
void loadPlan(const std::string& planFile, PoDoFo::Impose::PlanReader loader); |
| 71 |
|
| 72 |
/** |
| 73 |
When all is prepared, call it to do the job. |
| 74 |
*/ |
| 75 |
void impose(); |
| 76 |
|
| 77 |
private: |
| 78 |
std::string inFilePath; |
| 79 |
std::string outFilePath; |
| 80 |
|
| 81 |
PdfReference globalResRef; |
| 82 |
|
| 83 |
ImpositionPlan* planImposition; |
| 84 |
|
| 85 |
std::map<int, PdfXObjectForm*> xobjects; |
| 86 |
std::map<int, PdfObject*> resources; |
| 87 |
std::map<int, Rect> cropRect; |
| 88 |
std::map<int, Rect> bleedRect; |
| 89 |
std::map<int, Rect> trimRect; |
| 90 |
std::map<int, Rect> artRect; |
| 91 |
std::map<int, PdfDictionary*> pDict; |
| 92 |
std::map<int, int> virtualMap; |
| 93 |
// int maxPageDest; |
| 94 |
int duplicate; |
| 95 |
|
| 96 |
bool checkIsPDF(std::string path); |
| 97 |
PdfObject* getInheritedResources(PdfPage& page); |
| 98 |
void mergeResKey(PdfObject* base, PdfName key, PdfObject* tomerge); |
| 99 |
PdfObject* migrateResource(PdfObject* obj); |
| 100 |
void drawLine(double x, double y, double xx, double yy, std::ostringstream& a); |
| 101 |
void signature(double x, double y, int sheet, const std::vector<int>& pages, std::ostringstream& a); |
| 102 |
|
| 103 |
// An attempt to allow nested loops |
| 104 |
// returns new position in records list. |
| 105 |
int sortLoop(std::vector<std::string>& memfile, int numline); |
| 106 |
|
| 107 |
std::string useFont; |
| 108 |
PdfReference useFontRef; |
| 109 |
double extraSpace; |
| 110 |
|
| 111 |
std::vector<std::string> multiSource; |
| 112 |
|
| 113 |
std::map<std::string, PdfObject*> migrateMap; |
| 114 |
std::set<PdfObject*> setMigrationPending; |
| 115 |
|
| 116 |
std::vector<double> transformMatrix; |
| 117 |
void transform(double a, double b, double c, double d, double e, double f); |
| 118 |
void translate(double dx, double dy); |
| 119 |
void scale(double sx, double sy); |
| 120 |
void rotate(double theta); |
| 121 |
void rotate_and_translate(double theta, double dx, double dy); |
| 122 |
public: |
| 123 |
unsigned pageCount; |
| 124 |
double sourceWidth; |
| 125 |
double sourceHeight; |
| 126 |
double destWidth; |
| 127 |
double destHeight; |
| 128 |
double scaleFactor; |
| 129 |
std::string boundingBox; |
| 130 |
}; |
| 131 |
|
| 132 |
} |
| 133 |
|
| 134 |
#endif // PDFTRANSLATOR_H |