×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

CGI 错误 指定的 CGI 应用程序因为没有返回完整的 HTTP 标题而运行不正常。它返回的标题是:

本文发表在 rolia.net 枫下论坛运行了Adobe的html form to PDF form sample, 可有如下错误,请大虾帮忙

CGI 错误
指定的 CGI 应用程序因为没有返回完整的 HTTP 标题而运行不正常。它返回的标题是:

/*
* HTMLtoPDF.cpp
*
ADOBE SYSTEMS INCORPORATED
Copyright [1999] - [2001] Adobe Systems Incorporated
All Rights Reserved

NOTICE: Adobe permits you to use, modify, and distribute
this file in accordance with the terms of the Adobe license
agreement accompanying it. If you have received this file
from a source other than Adobe, then your use, modification,
or distribution of it requires the prior written permission of Adobe.

Installation:

1) Compile the HTMLToPDF.cpp file. Install the resulting
HTMLToPDF.cgi file in a server directory with execute
permissions.

This sample assumes that directory is localhost/Scripts/.

2) Install the html support file into the root directory of
your server.

3) Install the PDF support file into a directory called PDFs
at the root of your web server.

4) Open the HTMLToPDF.html file in your browser.
*/


#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#include "FdfTk.h"

/* fetch this pdf file from fdf. Path should be fully specified url */
#define HRDEMO_PDF "http://localhost/PDFs/HTMLToPDF.pdf"

/*
These definitions are needed only on Unix, for multithreading
*/
#ifdef SOLARIS
#define INITIALIZE_FDF_THREADSAFE { \
static mutex_t mutexObj; \
mutex_init( &mutexObj, NULL, NULL ); \
FDFRegisterThreadsafeCallbacks( \
(ThreadsafeCallback)mutex_lock, \
(ThreadsafeCallback)mutex_unlock, \
(ThreadsafeCallback)mutex_destroy, &mutexObj ); }
#endif

#ifndef INITIALIZE_FDF_THREADSAFE
#define INITIALIZE_FDF_THREADSAFE
#endif

/*
The error handling strategy we use in this example is to return to the client
an indication of which call into the FDF API failed, and what the error code
was. This is probably a good approach during the debugging phase, but not for
production systems!
*/
static void HandleError(FDFErc theErc, const char* funcName, const char* parameter,
FDFDoc inFDF, FDFDoc outFDF)
{
if (theErc != FDFErcOK) {

if (inFDF) FDFClose(inFDF);
if (outFDF) FDFClose(outFDF);
printf("Content-type: text/plain\n\n");
printf("Error %d in call to %s. Parameter: %s\n", theErc, funcName,
parameter);

exit(1);
}
}
/*
This cgi-bin program parses submitted forms data from an HTML form and writes
it out an FDF with same fields & values. The FDF points to another PDF Form
that has the same fields as in the HTML form. The end result is a PDF Form
that has the same fields and values as the originating HTML form.
*/


void main(int argc, char *argv[], char *envp[])
{
int i;
char c;
char cv[3];
char* tmp;
FDFDoc outFDF = NULL;
FDFErc theErc;
char name[256];
char value[512];

long howMany;
char* ptr;

#ifdef UNIX_ENV
/*
On Unix only, need to define the platform-dependent functions used for
threading.
This particular example does not use threading, but we still wanted
to show how the FDFRegisterThreadsafeCallbacks() API is used.
*/
INITIALIZE_FDF_THREADSAFE;
/*
This example assumes a cgi-bin environment, where each invocation of
the program spawns a new process. In a multi-threaded environment,
FDFInitialize() should only be called once, by the first thread in the
application. Once again, this is Unix only. On Win32 the initialization
and multithreading stuff is taken care of automatically by the FdfTk.dll
*/
FDFInitialize();
#endif

howMany = atoi(getenv("CONTENT_LENGTH"));
ptr = (char*)malloc(sizeof(char) * (howMany+1));
howMany = fread(ptr, sizeof(char), howMany, stdin);
ptr[howMany] = 0;
tmp = ptr;

/* Create a new FDF to send the response to the client */
theErc = FDFCreate(&outFDF);
HandleError(theErc, "FDFCreate", "none", NULL, outFDF);

/* read the from stdin, submitted data is of form name1=value1&name2=value2 */
while (*ptr) {
/* parse field name */
i = 0;
while ((c = *ptr++) && c != '=') {
name[i++] = c;
}
if (!c)
break;
name[i] = 0;

/* parse field value. URL-encoded data */
i = 0;
while ((c = *ptr++) && c != '&') {
if (c == '+')
c = ' '; /* convert + to white space */
if (c == '%') {
cv[0] = *ptr++;
cv[1] = *ptr++;
cv[2] = 0;
sscanf(cv, "%x", &c); /* convert (%)chars to their URL encoding */
}
value[i++] = c;
}
if (!c)
break;
value[i] = 0;

theErc = FDFSetValue(outFDF, name, value, false);
HandleError(theErc, "FDFSetValue", name, NULL, outFDF);

}
free(tmp);

/*
The FDF gives (as the value of the /F key) the name of the AcroForm that
needs to be fetched in order to import the FDF data into it.
*/
theErc = FDFSetFile(outFDF, HRDEMO_PDF);
HandleError(theErc, "FDFSetFile", HRDEMO_PDF, NULL, outFDF);
/*
Don't forget to emit the correct HTTP header for the MIME type.
By the way, remember when setting the URL of a SubmitForm action, to end
it in #FDF. For example, the URL used in CatEnglish.pdf and CatFrench.pdf
to submit to this cgi-bin program is:
http:/cgi-bin/catalog.cgi#FDF
*/
printf("Content-type: application/vnd.fdf\n\n");
fflush(stdout); /* Emit the HTTP header now! */

FDFSave(outFDF, "-"); /* Now send the FDF to stdout */

FDFClose(outFDF);

#ifdef UNIX_ENV
/*
This example assumes a cgi-bin environment, where each invocation of
the program spawns a new process. In a multi-threaded environment,
FDFFinalize() should only be called once, by the last thread in the
application. Once again, this is Unix only. On Win32 the initialization
and multithreading stuff is taken care of automatically by the FdfTk.dll
*/
FDFFinalize();
#endif

exit(0);
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
Report