summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKen Sharp <ken.sharp@artifex.com>2022-08-26 14:30:56 +0100
committerChris Liddell <chris.liddell@artifex.com>2022-09-02 15:59:06 +0100
commitfd03b047878db7ecba60a1f01e5ef1298c92cb53 (patch)
tree9eac08ff99ee2928c6730e531a70a0d6b56a2fb8
parent0eec2ad8420762215c01ad918b7b9c7f84032044 (diff)
downloadghostpdl-fd03b047878db7ecba60a1f01e5ef1298c92cb53.tar.gz
GhostPDF + GS - improve error handling
Arising from Bug #705784, if we hadn't built the PDF interpreter we would get typecheck errors which were somewhat misleading as to the source of the problem. This commit tidies up the error handling in the area of .PDFInit so that we not only detect the problem there but give a warning that it occurred. In addition, add a means to detect if the PDF interpreter is built in before we stat trying to process a PDF file and, if it is not, give a sensible error message. Tested with BUILD_PDF 0 and with NEWPDF true and false.
-rw-r--r--Resource/Init/pdf_main.ps56
-rw-r--r--psi/zpdfops.c19
2 files changed, 59 insertions, 16 deletions
diff --git a/Resource/Init/pdf_main.ps b/Resource/Init/pdf_main.ps
index 0399efffb..f5fcdd62f 100644
--- a/Resource/Init/pdf_main.ps
+++ b/Resource/Init/pdf_main.ps
@@ -258,6 +258,9 @@ systemdict /NEWPDF known not {/NEWPDF //true def} if
% Uses currentdict as an argument to pdfclose, which closes /PDFfile. Also
% executes restore and various cleanup activities.
%
+% pdfavailable - pdfavailable <bool>
+% Determines if there is a PDF interpreter available
+%
% Also Used by gsview 5
% =====================
% pdfopen <file> pdfopen <dict>
@@ -878,22 +881,27 @@ currentdict /PDFSwitches undef
/newpdf_runpdf
{
runpdfbegin % <file> runpdfbegin -
- PDFInfo /Collection known
+ PDFInfo type /dicttype eq
{
- PDFInfo /Collection get
- pdfclose
- dup length 1 sub 0 2 3 -1 roll
+ PDFInfo /Collection known
{
- 1 index exch get (r) file runpdf
- } for
- pop
- }
- {
- process_trailer_attrs % - process_trailer_attrs -
- runpdfpagerange % - runpdfpagerange <int> <int>
- dopdfpages % <int> <int> dopdfpages -
- runpdfend % - runpdfend -
- } ifelse
+ PDFInfo /Collection get
+ pdfclose
+ dup length 1 sub 0 2 3 -1 roll
+ {
+ 1 index exch get (r) file runpdf
+ } for
+ pop
+ }
+ {
+ process_trailer_attrs % - process_trailer_attrs -
+ runpdfpagerange % - runpdfpagerange <int> <int>
+ dopdfpages % <int> <int> dopdfpages -
+ runpdfend % - runpdfend -
+ } ifelse
+ } {
+ pop pop
+ }ifelse
} bind def
/newpdf_runpdfbegin
@@ -939,6 +947,7 @@ currentdict /PDFSwitches undef
{
{.PDFInit} stopped
{
+ ( **** Error: Failed to initialise PDF interpreter.\n) newpdf_pdfformaterror
/PDFFile //null def
/PDFInfo //null def
}
@@ -1094,6 +1103,11 @@ currentdict /PDFSwitches undef
}ifelse
} bind def
+/pdfavailable
+{
+ .PDFAvailable NEWPDF not or
+} bind def
+
% <int> <int> dopdfpages -
% First Page and then LastPage
% If PDFPageList array exists, the parameters are 1 pdfpagecount and are ignored.
@@ -1199,10 +1213,20 @@ currentdict /PDFSwitches undef
% stack: tempname tempfile
dup 0 setfileposition
dup
- runpdf
+ pdfavailable {
+ runpdf
+ }{
+ closefile
+ (%stderr) (w) file ( **** ERROR: No PDF interpreter available, unable to process PDF files as input.\n)writestring
+ } ifelse
closefile deletefile
} {
- runpdf
+ pdfavailable {
+ runpdf
+ }{
+ closefile
+ (%stderr) (w) file ( **** ERROR: No PDF interpreter available, unable to process PDF files as input.\n)writestring
+ } ifelse
} ifelse
} {
pop pop pop pop cvx .runps % (%!PS) found first
diff --git a/psi/zpdfops.c b/psi/zpdfops.c
index c20921d3f..e55267729 100644
--- a/psi/zpdfops.c
+++ b/psi/zpdfops.c
@@ -1601,6 +1601,11 @@ static int zPDFpageinfo(i_ctx_t *i_ctx_p)
return_error(gs_error_undefined);
}
+static int zPDFpageinfoExt(i_ctx_t *i_ctx_p)
+{
+ return_error(gs_error_undefined);
+}
+
static int zPDFmetadata(i_ctx_t *i_ctx_p)
{
return_error(gs_error_undefined);
@@ -1627,6 +1632,19 @@ static int zPDFparsePageList(i_ctx_t *i_ctx_p)
}
#endif
+static int zPDFAvailable(i_ctx_t *i_ctx_p)
+{
+ os_ptr op = osp;
+
+ push(1);
+#if defined(BUILD_PDF) && BUILD_PDF == 1
+ make_bool(op, true);
+#else
+ make_bool(op, false);
+#endif
+ return 0;
+}
+
/* ------ Initialization procedure ------ */
const op_def zpdfops_op_defs[] =
@@ -1645,6 +1663,7 @@ const op_def zpdfops_op_defs[] =
{"1.PDFDrawAnnots", zPDFdrawannots},
{"1.PDFInit", zPDFInit},
{"1.PDFparsePageList", zPDFparsePageList},
+ {"0.PDFAvailable", zPDFAvailable},
#ifdef HAVE_LIBIDN
{"1.saslprep", zsaslprep},
#endif