Skip to content

Commit

Permalink
Merge pull request #326 from Fdawgs/feat/win32-21.10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fdawgs committed Oct 12, 2021
2 parents e54c041 + f2cfabe commit be3199a
Show file tree
Hide file tree
Showing 485 changed files with 236 additions and 67 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Poppler {
__dirname,
"lib",
"win32",
"poppler-21.09.0",
"poppler-21.10.0",
"Library",
"bin"
);
Expand Down
43 changes: 42 additions & 1 deletion src/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ switch (platform) {
__dirname,
"lib",
"win32",
"poppler-21.09.0",
"poppler-21.10.0",
"Library",
"bin"
);
Expand Down Expand Up @@ -732,6 +732,47 @@ describe("Node-Poppler Module", () => {
});
});

describe("PDF-to-TIFF Option", () => {
test("Should convert PDF file to TIFF file", async () => {
const poppler = new Poppler(testBinaryPath);
const options = {
tiffFile: true,
};
const outputFile = `${testDirectory}pdf_1.3_NHS_Constitution`;

const res = await poppler.pdfToCairo(file, outputFile, options);

expect(typeof res).toBe("string");
expect(
fs.existsSync(
`${testDirectory}pdf_1.3_NHS_Constitution-01.tif`
)
).toBe(true);
});

test("Should convert PDF file as Buffer to TIFF file", async () => {
const poppler = new Poppler(testBinaryPath);
const attachmentFile = fs.readFileSync(file);
const options = {
tiffFile: true,
};
const outputFile = `${testDirectory}pdf_1.3_NHS_Constitution`;

const res = await poppler.pdfToCairo(
attachmentFile,
outputFile,
options
);

expect(typeof res).toBe("string");
expect(
fs.existsSync(
`${testDirectory}pdf_1.3_NHS_Constitution-01.tif`
)
).toBe(true);
});
});

test("Should accept options and only process 2 pages of PDF file", async () => {
const poppler = new Poppler(testBinaryPath);
const options = {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
12 changes: 0 additions & 12 deletions src/lib/win32/poppler-21.09.0/Library/lib/pkgconfig/poppler-cpp.pc

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions src/lib/win32/poppler-21.09.0/Library/lib/pkgconfig/poppler.pc

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
// Copyright (C) 2020 Thorsten Behrens <Thorsten.Behrens@CIB.de>
// Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>.
// Copyright (C) 2021 Zachary Travis <ztravis@everlaw.com>
// Copyright (C) 2021 Mahmoud Ahmed Khalil <mahmoudkhalil11@gmail.com>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
Expand All @@ -53,6 +54,7 @@
#include <mutex>
#include <vector>

#include "AnnotStampImageHelper.h"
#include "Object.h"
#include "poppler_private_export.h"

Expand Down Expand Up @@ -375,7 +377,7 @@ class POPPLER_PRIVATE_EXPORT AnnotColor
class POPPLER_PRIVATE_EXPORT DefaultAppearance
{
public:
DefaultAppearance(Object &&fontNameA, double fontPtSizeA, std::unique_ptr<AnnotColor> fontColorA);
DefaultAppearance(Object &&fontNameA, double fontPtSizeA, std::unique_ptr<AnnotColor> &&fontColorA);
explicit DefaultAppearance(const GooString *da);
void setFontName(Object &&fontNameA);
const Object &getFontName() const { return fontName; }
Expand Down Expand Up @@ -731,6 +733,8 @@ class POPPLER_PRIVATE_EXPORT Annot
const GooString *getName() const { return name.get(); }
const GooString *getModified() const { return modified.get(); }
unsigned int getFlags() const { return flags; }
Object getAppearance() const;
void setNewAppearance(Object &&newAppearance);
AnnotAppearance *getAppearStreams() const { return appearStreams.get(); }
const GooString *getAppearState() const { return appearState.get(); }
AnnotBorder *getBorder() const { return border.get(); }
Expand All @@ -754,8 +758,8 @@ class POPPLER_PRIVATE_EXPORT Annot
protected:
virtual ~Annot();
virtual void removeReferencedObjects(); // Called by Page::removeAnnot
Object createForm(const GooString *appearBuf, double *bbox, bool transparencyGroup, Dict *resDict);
Object createForm(const GooString *appearBuf, double *bbox, bool transparencyGroup, Object &&resDictObject); // overload to support incRef/decRef
Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Dict *resDict);
Object createForm(const GooString *appearBuf, const double *bbox, bool transparencyGroup, Object &&resDictObject); // overload to support incRef/decRef
Dict *createResourcesDict(const char *formName, Object &&formStream, const char *stateName, double opacity, const char *blendMode);
bool isVisible(bool printing);
int getRotation() const;
Expand Down Expand Up @@ -1195,15 +1199,25 @@ class POPPLER_PRIVATE_EXPORT AnnotStamp : public AnnotMarkup
AnnotStamp(PDFDoc *docA, Object &&dictObject, const Object *obj);
~AnnotStamp() override;

void draw(Gfx *gfx, bool printing) override;

void setIcon(GooString *new_icon);

void setCustomImage(AnnotStampImageHelper *stampImageHelperA);

void clearCustomImage();

// getters
const GooString *getIcon() const { return icon.get(); }

private:
void initialize(PDFDoc *docA, Dict *dict);
void generateStampDefaultAppearance();
void generateStampCustomAppearance();

std::unique_ptr<GooString> icon; // Name (Default Draft)
AnnotStampImageHelper *stampImageHelper;
Ref updatedAppearanceStream;
};

//------------------------------------------------------------------------
Expand Down Expand Up @@ -1436,7 +1450,6 @@ class POPPLER_PRIVATE_EXPORT AnnotWidget : public Annot
std::unique_ptr<LinkAction> getAdditionalAction(AdditionalActionsType type);
std::unique_ptr<LinkAction> getFormAdditionalAction(FormAdditionalActionsType type);
Dict *getParent() { return parent; }
void setNewAppearance(Object &&newAppearance);

bool setFormAdditionalAction(FormAdditionalActionsType type, const GooString &js);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//========================================================================
//
// AnnotStampImageHelper.h
//
// Copyright (C) 2021 Mahmoud Ahmed Khalil <mahmoudkhalil11@gmail.com>
// Copyright (C) 2021 Albert Astals Cid <aacid@kde.org>
//
// Licensed under GPLv2 or later
//
//========================================================================

#ifndef ANNOTSTAMPIMAGEHELPER_H
#define ANNOTSTAMPIMAGEHELPER_H

#include "Object.h"

class PDFDoc;

enum ColorSpace
{
DeviceGray,
DeviceRGB,
DeviceCMYK
};

/**
* This class is used only to load Image XObjects into stamp annotations. It takes in
* the image parameters in its constructors and creates a new Image XObject that gets
* added to the XRef table, so that the annotations that would like to use it be able
* to get its ref number.
*
* To have transparency in the image, you should first try to create the soft
* mask of the image, by creating a AnnotStampImageHelper object giving it the soft
* image data normally. You would then need to pass in the created soft mask Image XObject
* ref to the actual image you'd like to be created by this helper class.
*/
class POPPLER_PRIVATE_EXPORT AnnotStampImageHelper
{
public:
AnnotStampImageHelper(PDFDoc *docA, int widthA, int heightA, ColorSpace colorSpace, int bitsPerComponent, char *data, int dataLength);
AnnotStampImageHelper(PDFDoc *docA, int widthA, int heightA, ColorSpace colorSpace, int bitsPerComponent, char *data, int dataLength, Ref softMaskRef);
~AnnotStampImageHelper() { }

// Returns the ref to the created Image XObject
Ref getRef() const { return ref; }

// Returns the width of the image
int getWidth() const { return width; }
// Returns the height of the image
int getHeight() const { return height; }

// Removes the created Image XObject as well as its soft mask from the XRef Table
void removeAnnotStampImageObject();

private:
void initialize(PDFDoc *docA, int widthA, int heightA, ColorSpace colorSpace, int bitsPerComponent, char *data, int dataLength);

PDFDoc *doc;

Object imgObj;
Ref ref;
Ref sMaskRef;

int width;
int height;
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class POPPLER_PRIVATE_EXPORT Catalog

// Return the contents of the metadata stream, or NULL if there is
// no metadata.
GooString *readMetadata();
std::unique_ptr<GooString> readMetadata();

// Return the structure tree root object.
StructTreeRoot *getStructTreeRoot();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Copyright (C) 2009 Pino Toscano <pino@kde.org>
// Copyright (C) 2012 Adrian Johnson <ajohnson@redneon.com>
// Copyright (C) 2013 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2019 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2019, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2019 Adam Reichold <adam.reichold@t-online.de>
//
// To see a description of the changes please see the Changelog file that
Expand Down Expand Up @@ -66,7 +66,7 @@ class POPPLER_PRIVATE_EXPORT FontInfo
const GooString *getName() const { return name; };
const GooString *getSubstituteName() const { return substituteName; };
const GooString *getFile() const { return file; };
const GooString *getEncoding() const { return encoding; };
const std::string &getEncoding() const { return encoding; };
Type getType() const { return type; };
bool getEmbedded() const { return emb; };
bool getSubset() const { return subset; };
Expand All @@ -78,7 +78,7 @@ class POPPLER_PRIVATE_EXPORT FontInfo
GooString *name;
GooString *substituteName;
GooString *file;
GooString *encoding;
std::string encoding;
Type type;
bool emb;
bool subset;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
// Copyright 2020 Marek Kasik <mkasik@redhat.com>
// Copyright 2020 Thorsten Behrens <Thorsten.Behrens@CIB.de>
// Copyright 2020 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by Technische Universität Dresden
// Copyright 2021 Georgiy Sgibnev <georgiy@sgibnev.com>. Work sponsored by lab50.net.
// Copyright 2021 Theofilos Intzoglou <int.teo@gmail.com>
//
//========================================================================

Expand Down Expand Up @@ -295,19 +297,20 @@ class POPPLER_PRIVATE_EXPORT FormWidgetSignature : public FormWidget
void setSignatureType(FormSignatureType fst);

// Use -1 for now as validationTime
SignatureInfo *validateSignature(bool doVerifyCert, bool forceRevalidation, time_t validationTime);
SignatureInfo *validateSignature(bool doVerifyCert, bool forceRevalidation, time_t validationTime, bool ocspRevocationCheck, bool enableAIA);

// returns a list with the boundaries of the signed ranges
// the elements of the list are of type Goffset
std::vector<Goffset> getSignedRangeBounds() const;

// creates or replaces the dictionary name "V" in the signature dictionary and
// Creates or replaces the dictionary name "V" in the signature dictionary and
// fills it with the fields of the signature; the field "Contents" is the signature
// in PKCS#7 format, which is calculated over the byte range encompassing the whole
// document except for the signature itself; this byte range is specified in the
// field "ByteRange" in the dictionary "V"
// return success
bool signDocument(const char *filename, const char *certNickname, const char *digestName, const char *password, const char *reason = nullptr);
// field "ByteRange" in the dictionary "V".
// Arguments reason and location are UTF-16 big endian strings with BOM. An empty string and nullptr are acceptable too.
// Returns success.
bool signDocument(const char *filename, const char *certNickname, const char *digestName, const char *password, const GooString *reason = nullptr, const GooString *location = nullptr);

// checks the length encoding of the signature and returns the hex encoded signature
// if the check passed (and the checked file size as output parameter in checkedFileSize)
Expand All @@ -317,7 +320,7 @@ class POPPLER_PRIVATE_EXPORT FormWidgetSignature : public FormWidget
const GooString *getSignature() const;

private:
bool createSignature(Object &vObj, Ref vRef, const GooString &name, const GooString &reason, const GooString *signature);
bool createSignature(Object &vObj, Ref vRef, const GooString &name, const GooString *signature, const GooString *reason = nullptr, const GooString *location = nullptr);
bool getObjectStartEnd(GooString *filename, int objNum, Goffset *objStart, Goffset *objEnd);
bool updateOffsets(FILE *f, Goffset objStart, Goffset objEnd, Goffset *sigStart, Goffset *sigEnd, Goffset *fileSize);

Expand Down Expand Up @@ -594,7 +597,7 @@ class POPPLER_PRIVATE_EXPORT FormFieldSignature : public FormField
FormFieldSignature(PDFDoc *docA, Object &&dict, const Ref ref, FormField *parent, std::set<int> *usedParents);

// Use -1 for now as validationTime
SignatureInfo *validateSignature(bool doVerifyCert, bool forceRevalidation, time_t validationTime);
SignatureInfo *validateSignature(bool doVerifyCert, bool forceRevalidation, time_t validationTime, bool ocspRevocationCheck, bool enableAIA);

// returns a list with the boundaries of the signed ranges
// the elements of the list are of type Goffset
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
// Copyright (C) 2015, 2018 Jason Crain <jason@aquaticape.us>
// Copyright (C) 2015 Thomas Freitag <Thomas.Freitag@alfa.de>
// Copyright (C) 2018 Klarälvdalens Datakonsult AB, a KDAB Group company, <info@kdab.com>. Work sponsored by the LiMux project of the city of Munich
// Copyright (C) 2021 Oliver Sander <oliver.sander@tu-dresden.de>
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
Expand Down Expand Up @@ -291,7 +292,7 @@ class POPPLER_PRIVATE_EXPORT GfxFont
bool hasToUnicodeCMap() const { return hasToUnicode; }

// Return the name of the encoding
GooString *getEncodingName() const { return encodingName; }
const std::string &getEncodingName() const { return encodingName; }

// Return AGLFN names of ligatures in the Standard and Expert encodings
// for use with fonts that are not compatible with the Standard 14 fonts.
Expand Down Expand Up @@ -326,7 +327,7 @@ class POPPLER_PRIVATE_EXPORT GfxFont
int refCnt;
bool ok;
bool hasToUnicode;
GooString *encodingName;
std::string encodingName;
};

//------------------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
// Copyright (C) 2020, 2021 Oliver Sander <oliver.sander@tu-dresden.de>
// Copyright (C) 2020 Nelson Benítez León <nbenitezl@gmail.com>
// Copyright (C) 2021 Mahmoud Khalil <mahmoudkhalil11@gmail.com>
// Copyright (C) 2021 Georgiy Sgibnev <georgiy@sgibnev.com>. Work sponsored by lab50.net.
//
// To see a description of the changes please see the Changelog file that
// came with your tarball or type make ChangeLog if you are building from git
Expand Down Expand Up @@ -183,7 +184,7 @@ class POPPLER_PRIVATE_EXPORT PDFDoc

// Return the contents of the metadata stream, or nullptr if there is
// no metadata.
const GooString *readMetadata() const { return catalog->readMetadata(); }
std::unique_ptr<GooString> readMetadata() const { return catalog->readMetadata(); }

// Return the structure tree root object.
const StructTreeRoot *getStructTreeRoot() const { return catalog->getStructTreeRoot(); }
Expand Down Expand Up @@ -329,6 +330,11 @@ class POPPLER_PRIVATE_EXPORT PDFDoc
// scans the PDF and returns whether it contains any javascript
bool hasJavascript();

// Arguments signatureText and signatureTextLeft are UTF-16 big endian strings with BOM.
// Arguments reason and location are UTF-16 big endian strings with BOM. An empty string and nullptr are acceptable too.
bool sign(const char *saveFilename, const char *certNickname, const char *password, GooString *partialFieldName, int page, const PDFRectangle &rect, const GooString &signatureText, const GooString &signatureTextLeft, double fontSize,
std::unique_ptr<AnnotColor> &&fontColor, double borderWidth, std::unique_ptr<AnnotColor> &&borderColor, std::unique_ptr<AnnotColor> &&backgroundColor, const GooString *reason = nullptr, const GooString *location = nullptr);

private:
// insert referenced objects in XRef
void markDictionnary(Dict *dict, XRef *xRef, XRef *countRef, unsigned int numOffset, int oldRefNum, int newRefNum, std::set<Dict *> *alreadyMarkedDicts);
Expand Down
Loading

0 comments on commit be3199a

Please sign in to comment.