Skip to content

Commit c4f9312

Browse files
committed
removed restriction to process PDF-1.x files only
(closes #291)
1 parent 02d69ee commit c4f9312

File tree

2 files changed

+17
-7
lines changed

2 files changed

+17
-7
lines changed

src/PDFToSVG.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,21 @@ PDFToSVG::PDFToSVG (const string &fname, SVGOutputBase &out) : ImageToSVG(fname,
3535
}
3636
if (!_useGS)
3737
_pdfHandler.assignSVGTree(_svg);
38+
39+
ifstream ifs(filename());
40+
if (ifs) {
41+
string buf(5, 0);
42+
ifs.read(&buf[0], 5);
43+
if (buf == "%PDF-") {
44+
int major=0, minor=0;
45+
ifs >> major;
46+
if (ifs.get() == '.')
47+
ifs >> minor;
48+
else
49+
major = 0; // missing dot => invalid PDF version
50+
_pdfVersion = major*100 + minor;
51+
}
52+
}
3853
}
3954

4055

@@ -71,13 +86,7 @@ int PDFToSVG::totalPageCount () const {
7186

7287

7388
bool PDFToSVG::imageIsValid () const {
74-
ifstream ifs(filename());
75-
if (ifs) {
76-
char buf[16];
77-
ifs.getline(buf, 16);
78-
return std::strncmp(buf, "%PDF-1.", 7) == 0;
79-
}
80-
return false;
89+
return _pdfVersion > 0;
8190
}
8291

8392

src/PDFToSVG.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ class PDFToSVG : public ImageToSVG {
4444
mutable int _totalPageCount = -1;
4545
PDFHandler _pdfHandler;
4646
bool _useGS = true;
47+
int _pdfVersion = 0; // PDF version of file being processed (major*100 + minor)
4748
};
4849

4950
#endif

0 commit comments

Comments
 (0)