Sign in to follow this  
Followers 0
renzi

Edit/replace First Line of PDF file

2 posts in this topic

I am trying to copy a PDF file, open the PDF copy, read in the first line, alter it, then write it back as the first line of the same PDF file.

I can get it all to work, but the file is altered in some undesirable way and looses most of its size (from 26k original down to 1k post-run) and obviously the ability to view using acrobat.

Here is what I have so far - I must be missing something simple?!? Perhaps I just don't understand enough about PDF file construct?

#Include <File.au3>

$Test_PDF = "E:\DIR00\D0000001.PDF"

$New_PDF = "\\S3W04855\K$\_DATA_MIGRATION_PROCESSING\_NORMALIZED_\JBH_200805_STMT_01_of_02_20080605173901\DIR00\D0000001.PDF"

FileCopy ($Test_PDF, $New_PDF, 9)

FileSetAttrib ($New_PDF, "-R")

$PDF_H = FileOpen ($New_PDF, 0)

$PDF_Line01 = FileReadLine( $PDF_H, 1)

MsgBox( 4096, "This is the origonal line", $PDF_Line01)

$PDF_Line_NEW = ("%PDF" & StringRight ( $PDF_Line01, 5))

MsgBox( 4096, "PDF Line New = ", $PDF_Line_NEW)

FileClose ($PDF_H)

$PDF_H = FileOpen ($New_PDF, 1)

$FRTL = _FileWriteToLine ( $New_PDF, 1, $PDF_Line_NEW, 1)

If $FRTL = 0 Then

MsgBox(0, "Error", "Unable to write line to file: ", $New_PDF )

Exit

EndIf

FileClose ($PDF_H)

PDF file line one:

3N$FKJLK$940$MND-1.2

Desired line one:

%PDF-1.2

Share this post


Link to post
Share on other sites



FileReadLine is for TextFiles. You'll have a tough time getting it to work on other files types. You'll probably want to use FileRead with the file opened in binary mode .

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0