Skip to content

Commit

Permalink
Version 1.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
vfr committed Jun 18, 2011
1 parent 6326bdc commit 9a0d90d
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 10 deletions.
1 change: 1 addition & 0 deletions Classes/PDFViewTiled.h
Expand Up @@ -28,6 +28,7 @@
CGPDFPageRef _PDFPageRef;
}

@property (nonatomic, retain, readonly) NSURL *fileURL;
@property (nonatomic, assign, readonly) NSInteger pageCount;
@property (nonatomic, assign, readonly) NSInteger currentPage;

Expand Down
5 changes: 3 additions & 2 deletions Classes/PDFViewTiled.m
Expand Up @@ -20,6 +20,7 @@ @implementation PDFViewTiled

#pragma mark Properties

@synthesize fileURL = _fileURL;
@synthesize pageCount = _pageCount;
@synthesize currentPage = _currentPage;

Expand Down Expand Up @@ -323,8 +324,8 @@ - (void)drawLayer:(CATiledLayer *)layer inContext:(CGContextRef)context

y_offset = (boundsHeight - y_offset); // Co-ordinate system adjust

CGFloat x_translate = (x_offset - effectiveRect.origin.x);
CGFloat y_translate = (y_offset + effectiveRect.origin.y);
CGFloat x_translate = (x_offset - (effectiveRect.origin.x * scale));
CGFloat y_translate = (y_offset + (effectiveRect.origin.y * scale));

CGContextTranslateCTM(context, x_translate, y_translate);

Expand Down
2 changes: 2 additions & 0 deletions Classes/ReaderViewController.h
Expand Up @@ -30,6 +30,8 @@

UIScrollView *theScrollView;
PDFViewTiled *thePDFView;

UIPrintInteractionController *printInteraction;
}

@property (nonatomic, retain, readwrite) NSURL *openURL;
Expand Down
70 changes: 65 additions & 5 deletions Classes/ReaderViewController.m
Expand Up @@ -127,30 +127,41 @@ - (void)viewDidLoad

thePDFView = [[PDFViewTiled alloc] initWithURL:fileURL page:page password:nil frame:theScrollView.bounds];

[theScrollView addSubview:thePDFView];
[theScrollView addSubview:thePDFView]; // Add the PDF view to the scroll view

theToolbar = [UIToolbar new]; // Create the application toolbar

theToolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth;
theToolbar.barStyle = UIBarStyleBlack; theToolbar.translucent = YES;

NSMutableArray *buttonArray = [NSMutableArray new]; // Toolbar button item array

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; [infoButton sizeToFit];

[infoButton addTarget:self action:@selector(infoButtonTapped:) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem *barInfoButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton]; // Use the UIButton view

UIBarButtonItem *flexiSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];
[buttonArray addObject:barInfoButton]; [barInfoButton release]; // Add the info button to the button item array

Class printInteractionController = NSClassFromString(@"UIPrintInteractionController"); // Only in iOS 4.2 and up

if ((printInteractionController != nil) && [printInteractionController isPrintingAvailable]) // Check for printing support
{
UIBarButtonItem *flexiSpace = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:NULL];

UIBarButtonItem *printButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"Icon-Print.png"] style:UIBarButtonItemStylePlain target:self action:@selector(printButtonTapped:)];

theToolbar.items = [NSArray arrayWithObjects:flexiSpace, barInfoButton, nil];
[buttonArray addObject:flexiSpace]; [buttonArray addObject:printButton]; [flexiSpace release]; [printButton release]; // Add print button
}

[barInfoButton release]; [flexiSpace release]; // Cleanup
theToolbar.items = buttonArray; [buttonArray release];

[self.view addSubview:theToolbar]; [theToolbar sizeToFit];

frame = theToolbar.bounds;
frame.origin.y += 4.0f; frame.size.height -= 8.0f;
frame.origin.x += 8.0f; frame.size.width -= 48.0f;
frame.origin.x += 48.0f; frame.size.width -= 96.0f;

theLabel = [[UILabel alloc] initWithFrame:frame];

Expand Down Expand Up @@ -282,6 +293,11 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie
// NSLog(@"ReaderViewController.m -willRotateToInterfaceOrientation: [%d]", toInterfaceOrientation);
// NSLog(@" -> self.view.bounds = %@", NSStringFromCGRect(self.view.bounds));
#endif

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // iPad only
{
if (printInteraction != nil) [printInteraction dismissAnimated:NO];
}
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration
Expand Down Expand Up @@ -487,6 +503,50 @@ - (void)infoButtonTapped:(UIBarButtonItem *)item
[theAlert show]; [theAlert release];
}

- (void)printButtonTapped:(UIBarButtonItem *)item
{
Class printInteractionController = NSClassFromString(@"UIPrintInteractionController");

if ((printInteractionController != nil) && [printInteractionController isPrintingAvailable])
{
NSURL *fileURL = thePDFView.fileURL; // Document file URL

printInteraction = [printInteractionController sharedPrintController];

if ([printInteractionController canPrintURL:fileURL] == YES) // Check
{
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // iPad only
{
[toolbarFader stopFadeOutTimer]; // Stop toolbar fade timer
}

UIPrintInfo *printInfo = [NSClassFromString(@"UIPrintInfo") printInfo];

printInfo.duplex = UIPrintInfoDuplexLongEdge;
printInfo.outputType = UIPrintInfoOutputGeneral;
printInfo.jobName = [fileURL lastPathComponent];

printInteraction.printInfo = printInfo;
printInteraction.printingItem = fileURL;
printInteraction.showsPageRange = YES;

[printInteraction presentFromBarButtonItem:item animated:YES completionHandler:
^(UIPrintInteractionController *pic, BOOL completed, NSError *error)
{
#ifdef DEBUG
if ((completed == NO) && (error != nil)) NSLog(@"%s %@", __FUNCTION__, error);
#endif

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) // iPad only
{
[toolbarFader startFadeOutTimer]; // Start toolbar fade timer
}
}
];
}
}
}

#pragma mark UISlider action methods

- (void)sliderTouchDown:(UISlider *)slider
Expand Down
Binary file added Graphics/Icon-Print.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Graphics/Icon-Print@2x.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions README
Expand Up @@ -148,7 +148,7 @@ Properties

currentPage

The PDF view objects current page number value (read-only).
The PDF view object's current page number value (read-only).

@property (nonatomic, assign, readonly) NSInteger currentPage

Expand All @@ -157,7 +157,7 @@ change method calls. Contains 0 if -initWithURL: failed.

pageCount

The PDF view objects number of pages in PDF value (read-only).
The PDF view object's number of pages in PDF value (read-only).

@property (nonatomic, assign, readonly) NSInteger pageCount

Expand All @@ -181,6 +181,10 @@ HISTORY
and UIScrollView contentSize updates to fix device
rotation handling once and for all.

2011-05-22: Version 1.2.0 - Added printing support (iOS 4.2 and newer only).

2011-06-06: Version 1.2.1 - Bug fix in -drawLayer:inContext: in PDFViewTiled.m

CONTACT INFO

Questions, feedback and iOS development work welcome:
Expand Down
2 changes: 1 addition & 1 deletion Reader-Info.plist
Expand Up @@ -25,7 +25,7 @@
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1.1.0</string>
<string>1.2.1</string>
<key>LSRequiresIPhoneOS</key>
<true/>
<key>UIPrerenderedIcon</key>
Expand Down
8 changes: 8 additions & 0 deletions Reader.xcodeproj/project.pbxproj
Expand Up @@ -19,6 +19,8 @@
450A674111D286CB00014BF5 /* ReaderViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 450A674011D286CB00014BF5 /* ReaderViewController.m */; };
4534A869125F658F001F3415 /* LICENSE in Resources */ = {isa = PBXBuildFile; fileRef = 4534A868125F658F001F3415 /* LICENSE */; };
4541A9D8122EA716001A5E60 /* Localizable.strings in Resources */ = {isa = PBXBuildFile; fileRef = 4541A9D7122EA716001A5E60 /* Localizable.strings */; };
45832D261389823800D72031 /* Icon-Print.png in Resources */ = {isa = PBXBuildFile; fileRef = 45832D241389823800D72031 /* Icon-Print.png */; };
45832D271389823800D72031 /* Icon-Print@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 45832D251389823800D72031 /* Icon-Print@2x.png */; };
45A4AD5312395BE6005D5625 /* Document.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 45A4AD5212395BE6005D5625 /* Document.pdf */; };
45B550DB12326A5500DAE92E /* CGPDFDocument.m in Sources */ = {isa = PBXBuildFile; fileRef = 45B550DA12326A5500DAE92E /* CGPDFDocument.m */; };
45BF2DEA12329FA500544AC1 /* AppIcon-PDF.png in Resources */ = {isa = PBXBuildFile; fileRef = 45BF2DE912329FA500544AC1 /* AppIcon-PDF.png */; };
Expand All @@ -45,6 +47,8 @@
450A674011D286CB00014BF5 /* ReaderViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ReaderViewController.m; sourceTree = "<group>"; };
4534A868125F658F001F3415 /* LICENSE */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = LICENSE; sourceTree = "<group>"; };
4541A9D5122EA686001A5E60 /* en */ = {isa = PBXFileReference; fileEncoding = 10; lastKnownFileType = text.plist.strings; name = en; path = Resources/en.lproj/Localizable.strings; sourceTree = "<group>"; };
45832D241389823800D72031 /* Icon-Print.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Print.png"; path = "Graphics/Icon-Print.png"; sourceTree = "<group>"; };
45832D251389823800D72031 /* Icon-Print@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; name = "Icon-Print@2x.png"; path = "Graphics/Icon-Print@2x.png"; sourceTree = "<group>"; };
45A4AD5212395BE6005D5625 /* Document.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; name = Document.pdf; path = Resources/Document.pdf; sourceTree = "<group>"; };
45B550D912326A5500DAE92E /* CGPDFDocument.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CGPDFDocument.h; path = Sources/CGPDFDocument.h; sourceTree = "<group>"; };
45B550DA12326A5500DAE92E /* CGPDFDocument.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CGPDFDocument.m; path = Sources/CGPDFDocument.m; sourceTree = "<group>"; };
Expand Down Expand Up @@ -147,6 +151,8 @@
450A66D911D27B5800014BF5 /* Graphics */ = {
isa = PBXGroup;
children = (
45832D241389823800D72031 /* Icon-Print.png */,
45832D251389823800D72031 /* Icon-Print@2x.png */,
450A670E11D27BCD00014BF5 /* AppIcon-114.png */,
450A670D11D27BCD00014BF5 /* AppIcon-072.png */,
450A670C11D27BCD00014BF5 /* AppIcon-057.png */,
Expand Down Expand Up @@ -223,6 +229,8 @@
45EFD9761236D8EA00AAE9B3 /* README in Resources */,
45A4AD5312395BE6005D5625 /* Document.pdf in Resources */,
4534A869125F658F001F3415 /* LICENSE in Resources */,
45832D261389823800D72031 /* Icon-Print.png in Resources */,
45832D271389823800D72031 /* Icon-Print@2x.png in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down

0 comments on commit 9a0d90d

Please sign in to comment.