Signin/Signup with: 
Welcome, Guest
Username: Password: Remember me
Questions about iOS development and PDF

TOPIC:

HTTP Streaming 9 years 9 months ago #6543

  • rhill
  • rhill's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 21
  • Thank you received: 0
Hi, please can you tell me how the HTTP stream is supposed to work? I was hoping it would open a remote PDF and allow the user to scroll through while the PDF was being downloaded from the remote location - however it appears to just download the entire file in a synchronous manner before displaying the first page?

Is there going to be an update which allows HTTP streaming to work while the user is viewing the PDF - i.e. load the pages on demand from the remote location as the user scrolls to them?

thanks

Please Log in or Create an account to join the conversation.

HTTP Streaming 9 years 9 months ago #6556

  • rhill
  • rhill's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 21
  • Thank you received: 0
I've looked into this a little more and the way this works is a little odd. There is a temporary file created that matches the size of the full PDF, then the PDF library seems to download the entire file from the remote location in a synchronous fashion (blocking the UI thread).

The first page or two of the PDF are shown in the PDF viewer - at this point if you open the temporary file it has created in Preview (on Mac) then you see the first couple of pages have been downloaded and written to the file but the remainder of the PDF is empty - there are placeholders for images etc it would seem.

If you then scroll the PDF viewer one or two pages and then re-open the temporary file ALL the PDF is now present. It would seem as if the entire PDF was in memory but has been suddenly flushed to the temporary file.

The actual behaviour we want when using the new PDFHTTPStream class is for it to open the remote file immediately and display the first pages, scrolling the PDF causes further requests to be made to the server (with Range headers) in order to get more pages of the document. These should be cached to the temporary file as needed.

Can you tell me how to achieve this with the library?

thanks

Please Log in or Create an account to join the conversation.

HTTP Streaming 9 years 9 months ago #6575

  • radaee
  • radaee's Avatar
  • Offline
  • Moderator
  • Moderator
  • Posts: 1123
  • Thank you received: 73
these codes takes much time:
	[urlRequest setHTTPMethod:@"HEAD"];
	[NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&lenResponse error:nil];
		NSLog(@"%@",[lenResponse allHeaderFields]);
we don't know why yet.

Please Log in or Create an account to join the conversation.

HTTP Streaming 9 years 9 months ago #6578

  • rhill
  • rhill's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 21
  • Thank you received: 0
Hi, I agree that the HEAD request was taking a long time, in our case we know the file size before hand, so I modified the PDFHttpStream "open" method to accept the file length. If this was passed, it was used in place of making the HEAD request call. This removed that issue.
However this is not the main issue - the issue is that the call to Document_openStream in PDFObjc.m causes ALL the remote PDF file to be downloaded.
The source for "Document_openStream" is not available so I cannot see what is happening in there, but I suspect your code must be causing the entire file to be fetched, possibly to obtain the total page count.
-(int)openStream:(id<PDFStream>)stream : (NSString *)password
{
PDF_ERR err;
if( !password )
m_doc = Document_openStream(stream, NULL, &err);
else
{
const char *pwd = [password UTF8String];
m_doc = Document_openStream(stream, pwd, &err);
}
return err;
}

If I put NSLog messages in the PDFHttpStream download_blocks method, I can see that once the following line is executed:
m_doc = Document_openStream(stream, pwd, &err);

There are many, many calls to the PDFHttpStream download_blocks method:
-(bool)download_blocks :(int) start :(int)end

Each call asks for a different range of blocks. This continues until the entire file has been downloaded as mentioned above.

Please can you look into this because at the moment, the behaviour seems wrong.
Thanks

Please Log in or Create an account to join the conversation.

Last edit: by Raj123.

HTTP Streaming 9 years 9 months ago #6592

  • rhill
  • rhill's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
  • Posts: 21
  • Thank you received: 0
Hi guys, any news on this?

Please Log in or Create an account to join the conversation.

HTTP Streaming 9 years 9 months ago #6606

  • stronglee
  • stronglee's Avatar
  • Offline
  • Premium Member
  • Premium Member
  • Posts: 93
  • Thank you received: 2
Hi,
Sorry for lately reply.If you know file length before.you can modify
PDFHttpStream init_length method as follow
-(void)init_length :(long long )fileLength
{
m_total = fileLength;
if( len > 0 )
{
m_file = fopen([m_cache_path UTF8String], "wb+");//read-write cached file.
unsigned char tmp[4096];
memset( tmp, 0, 4096 );
int cur = 0;
while( cur < m_total - 4095 )
{
fwrite( tmp, 1, 4096, m_file );
cur += 4096;
}
fwrite( tmp, 1, m_total - cur, m_file );
m_block_cnt = (m_total + BLOCK_SIZE - 1)/BLOCK_SIZE;
m_block_flags = (unsigned char *)malloc(m_block_cnt * sizeof(unsigned char));
memset( m_block_flags, 0, m_block_cnt * sizeof(unsigned char) );//init all flags.
}
}

Have a try.

Please Log in or Create an account to join the conversation.

Powered by Kunena Forum