Convert PDF form version 1.1 to 1.4(or higher)

Question: How can I convert PDF files from version 1.1 to 1.4 (or higher)? Actually I need some sort of command line tool for batch converting or some API to be able to convert dynamically sever all documents.

Answer:PDF 1.1 is forward compatible with PDF 1.4. Everything in PDF 1.1 will work with PDF 1.4 - it's guaranteed by the spec. Let's assume that you've got some justifiable reason why this is not good enough for you (let's assume, for example, that you have a non-spec compliant tool that consumes PDF and explodes on any file version less that 1.4).We can focus on the main syntactic differences between versions. All PDF files have a header somewhere in the first 1024 bytes. In most cases, it's the very first line, but that's not guaranteed (I'm looking at you Ghost Script!). The header looks like this in PDF 1.1:  %PDF-1.1 In PDF 1.4,
it looks like this: %PDF-1.4 So in theory, all you need is a tool that will look in the first 1024 bytes for a file for "%PDF-1.1" and change it to "%PDF-1.4". You could use sed, perl, etc to do something like that for you. You could write it in C and you would be tempted to do something like this:

#define PDFHEADERSIZE 1024
bool ChangeFileToNewPdfVersion(char *file)
    char *replacePoint = NULL;
    FILE *fp = fopen(file, "rw");
    char buf[PDFHEADERSIZE + 1];
    buf[PDFHEADERSIZE] = '\0';
    if (fread(buf, 1, PDFHEADERSIZE, fp) != PDFHEADERSIZE) { fclose(fp); return false; }
    fseek(fp, 0, SEEK_SET);
    if ((replacePoint = strstr(buf, "%PDF-1.1")) == NULL) { fclose(fp); return false; }
    replacePoint[7] = '4';
    if (fwrite(buf, 1, PDFHEADERSIZE, fp) != PDFHEADERSIZE) { fclose(fp); return false; }

which will work in most sane cases. It will not work if the file starts, for example, with 0 bytes, which would serve as null terminators in the block of data. A better choice (really) would be to cobble up a simple state machine to find %PDF-1. by reading 1 byte at a time until it either finds it or passes 1017 (1024 less the header length), then reads the next byte, if it's a '1', it seeks back a byte and writes a '4'. The only other thing you would need to worry about is that PDF 1.4 suggests that the document catalog should contain a Version key with the file version. Since this is defined as optional in the spec, you are
safe to ignore it. Actually if you feel this is a little complicated, you can use software VeryPDF PDF Editor can help you change PDF version directly through software interface. Please check details from the following snapshot.

change PDF version

   If you need to use the command line version, please choose the PDF Editor OCX Control (ActiveX). During the using, if you have any question, please contact us as soon as possible.

VN:F [1.9.20_1166]
Rating: 0.0/10 (0 votes cast)
VN:F [1.9.20_1166]
Rating: 0 (from 0 votes)

Random Posts

This entry was posted in VeryPDF Blog. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

Verify Code   If you cannot see the CheckCode image,please refresh the page again!