Returning a PDF from a java servlet to IE(Internet Explorer)

This one was a pita because no one had all the information in the right place plus ton's of articles were old. So I figured out a solution, taking into account my findings, which works in firefox, chrome and most importantly IE. Below is the code with my explanation.

 

byte[] pdfBytes = PDFBytes;

response.setContentType("application/pdf");

response.setHeader("Content-Disposition", "inline; filename=RANDOMFILENAME.pdf");

response.setContentLength(pdfBytes.length);

response.addHeader("Accept-Ranges", "bytes");

ServletOutputStream sos = response.getOutputStream();

sos.write(pdfBytes);

sos.flush();

 

Fixes for IE
First "Content-Disposition", I read this everyone had it and it worked on my local deployment, but not in a test environment so it solved one problem.

"Content-Length", every article had it you can find some info at this link http://www.javakb.com/Uwe/Forum.aspx/java-setup/2168/Serving-PDF-from-a-servlet-blank-screen-in-IE. The premise is IE needs to know the size of the pdf.

"Accept-Ranges: bytes", now this one is what did it for me. I don't know why it works, but I went to a website which displayed a pdf in the browser and saw that in its header. I also read in another website about letting IE know the range of where to find the information, I don't know how to do that, but I tried it and it worked.

 

Fixes for other browsers

What you will notice is I don't close the ServletOutputStream. I found when I did close it the pdf did not render in Chrome. To be honest I never had it there before, but troubleshooting the IE issue I added it which broke the pdf in Chrome.

 

All in all I hope I help someone with this. I would like to know why these things worked now that I solved the what.

Landscape Rotation of a MapView to fullscreen inside of a TabBar Application in iOS4

OK sorry for the long title, but I'm just trying to be as descriptive as possible. I am very proud of this tip. I worked very hard looking for a solution, but could not find someone who shared the code or had done it. Here's how the highlights of how to do it.

  • Subclass the UITabBarController.
    • Now I know your not supposed to do this, but I really like my solution. The reason Apple doesn't want you to subclass the UITabBarController is because you can override the shouldAutoRotate method and force autorotation on a tab which can cause some messy stuff. Here's what I did, I let the selected view controller decide on where to rotate or now. Also since my intention is to cover up the tab bar it isn't so bad.
  • Add the map to the UIWindow
    • Here's the sample code:


- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
UIWindow *appWindow = [[TabBarRotateMapFullScreenAppDelegate sharedDelegate] window];

if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
mapView.transform = CGAffineTransformIdentity;
mapView.transform = CGAffineTransformMakeRotation(degreesToRadians(-90));
[appWindow addSubview:mapView];
mapView.frame = appWindow.frame;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
mapView.transform = CGAffineTransformIdentity;
mapView.transform = CGAffineTransformMakeRotation(degreesToRadians(90));
[appWindow addSubview:mapView];
mapView.frame = appWindow.frame;
[[UIApplication sharedApplication] setStatusBarHidden:YES];
}
else {
[mapView removeFromSuperview];
mapView.transform = CGAffineTransformIdentity;
mapView.transform = CGAffineTransformMakeRotation(degreesToRadians(0));
[self.view addSubview:mapView];
mapView.frame = self.view.frame;
[[UIApplication sharedApplication] setStatusBarHidden:NO];
}

}

Once I can figure out how to upload the sample project I will upload the code.