king514jy / purepdf

Automatically exported from code.google.com/p/purepdf
0 stars 0 forks source link

PRTokeniser.checkPdfHeader() throws error with any PDF file #16

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Insert this code into Flex4/AIR application
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                       xmlns:s="library://ns.adobe.com/flex/spark" 
                       xmlns:mx="library://ns.adobe.com/flex/mx" creationComplete="windowedapplication1_creationCompleteHandler(event)">
    <fx:Script>
        <![CDATA[
            import mx.events.FlexEvent;

            import org.purepdf.pdf.PdfDocument;
            import org.purepdf.pdf.PdfReader;
            import org.purepdf.pdf.PdfStream;
            public var reader:PdfReader;
            protected function windowedapplication1_creationCompleteHandler(event:FlexEvent):void{
                var stream:FileStream = new FileStream();
                stream.open(File.applicationDirectory.resolvePath('test.pdf'), FileMode.READ);
                var bytes:ByteArray = new ByteArray();
                stream.readBytes(bytes);
                stream.close();
                trace(bytes.readUTFBytes(8));
                bytes.position = 0;
                reader = new PdfReader(bytes);
                reader.addEventListener( Event.COMPLETE, onReadComplete );
                reader.addEventListener( ProgressEvent.PROGRESS, onReadProgress );
                reader.addEventListener( ErrorEvent.ERROR, onReadError );
                reader.readPdf();
            }

            protected function onReadError( event: ErrorEvent ): void
            {
                trace(event);
            }

            protected function onReadProgress( event: ProgressEvent ): void
            {
                trace( reader.currentStep + " of " + reader.totalSteps, int((event.bytesLoaded/event.bytesTotal)*100) )
            }

            protected function onReadComplete( event: Event ): void
            {
                trace('complete');
            }
        ]]>
    </fx:Script>
    <fx:Declarations>
        <!-- Place non-visual elements (e.g., services, value objects) here -->
    </fx:Declarations>
    <s:layout>
        <s:VerticalLayout/>
    </s:layout>
</s:WindowedApplication>

2. Place in "src" folder attached PDF file
3. Run debug

What is the expected output?

Expected output is correct PDF header "%PDF-1.4"

What do you see instead?
I see correct header and PdfReader error 
Error: pdf header not found
    at org.purepdf.pdf::PRTokeniser/checkPdfHeader()[Z:\home\localhost\www\tests\PatchPDFTest\src\org\purepdf\pdf\PRTokeniser.as:109]
    at org.purepdf.pdf::PdfReader/readPdf()[Z:\home\localhost\www\tests\PatchPDFTest\src\org\purepdf\pdf\PdfReader.as:309]
    at PatchPDFTest/windowedapplication1_creationCompleteHandler()[Z:\home\localhost\www\tests\PatchPDFTest\src\PatchPDFTest.mxml:25]

What version of the product are you using? On what operating system?
Latest version, from SVN.

Please provide any additional information below.
PRTokeniser incorrectly reads header and throws error.

Original issue reported on code.google.com by burd...@gmail.com on 24 Feb 2011 at 6:27

Attachments:

GoogleCodeExporter commented 8 years ago
This is because the PRTokeniser reads integers from the file. This reads 4 
bytes while  its supposed to be just 1 byte. Replacing the file.readInt() with 
file.readByte() would fix this problem.

Original comment by abd.alla...@gmail.com on 4 Mar 2012 at 3:19

GoogleCodeExporter commented 8 years ago
tried to change and still not working.
It makes the entire pdfReader feature unusable :(

Original comment by sebastie...@talos-solutions.com on 10 Sep 2013 at 8:36