Hi Ryan,
I’m using the built in tools for the FreeText annotation, with some very minor unrelated changes, so the document locking is covered. I’ve been stepping through the code and making sure that the lock/unlock pairs are happening in the right order in both the tools code and my code to save the document.
- Cannot reproduce in CompleteReader, I have spent some time comparing its code and mine and cannot locate what I am doing differently that would be causing this issue.
- Occurs with any file.
- Text input does not affect things.
- Running on an iPad running iOS 9.3. Project is created using Objective C.
- Relevant code is shown below.
The user taps a button that calls the toggleFreeTextToolbar method to initiate creating a FreeText annotation.
`
- (IBAction)toggleFreeTextToolbar:(id)sender
{
if (![selectedTool isKindOfClass:[FreeTextCreate class]])
{
[self setSelectedTool:[[FreeTextCreate alloc] initWithPDFViewCtrl:pdfViewCtrl] withTextAnnotationTypeFlag:NO withBackToPanToolAfterUseFlag:NO];
}
PanToolToggleAction ptta = freeTextToolBar.isHidden ? e_ptta_none : e_ptta_show;
[self toggleToolbar:freeTextToolBar withToggleSideBarSwipeIn:NO withTogglePanTool:ptta withSaveDocument:YES withIsFillColorType:NO];
}
`
When the user is finished making the FreeText annotation the toggleToolbar method is called again and initiates the call to SaveDoc.
`
- (void)toggleToolbar:(UIToolbar *)toolbar withToggleSideBarSwipeIn:(BOOL)toggleSideBarSwipeIn withTogglePanTool:(PanToolToggleAction)togglePanTool withSaveDocument:(BOOL)saveDocument withIsFillColorType:(BOOL)isFillColorTypeFlag
{
// get the height of the toolbar
float delta = toolbar.frame.size.height;
// check if toolbar was visible or hidden before the animation
BOOL isHidden = [toolbar isHidden];
isFillColorType = isFillColorTypeFlag;
if (toggleSideBarSwipeIn)
{
[self toggleSidebarSwipeIn:!isHidden];
[[self sideBarTab] setHidden:isHidden];
[[self.navigationItem leftBarButtonItem] setEnabled:!isHidden];
}
if (togglePanTool == e_ptta_show)
{
[self setSelectedTool:[[PanTool alloc] initWithPDFViewCtrl:pdfViewCtrl] withTextAnnotationTypeFlag:NO withBackToPanToolAfterUseFlag:YES];
}
else if (togglePanTool == e_ptta_hide)
{
selectedTool = nil;
[[pdfViewCtrl toolDelegate] setTool:nil];
}
// if toolbar was visible set delta to negative value so that animation goes up not down
// and save document if required
if (!isHidden)
{
delta *= -1;
if (saveDocument)
{
[self saveDoc];
}
}
else
{
// if toolbar was hidden then make it visible and bring to front before animation begins
toolbar.hidden = NO;
[self.view bringSubviewToFront:toolbar];
}
// run animation with duration of 0.2 second with zero delay
[UIView animateWithDuration: 0.2
delay: 0.0
options: UIViewAnimationOptionTransitionNone
animations:^{
toolbar.frame = CGRectOffset(toolbar.frame, 0.0, delta);
}
completion:^(BOOL finished) {
if (!isHidden) {
toolbar.hidden = YES;
}
}];
}
`
`
- (void)saveDoc
{
BOOL isStartUpDocument = [[docPath lastPathComponent] isEqualToString:[NSString stringWithFormat:@"%@.pdf", StartupDocumentNamePortrait]] || [[docPath lastPathComponent] isEqualToString:[NSString stringWithFormat:@"%@.pdf", StartupDocumentNameLandscape]];
if (currentDoc.IsModified & !isStartUpDocument)
{
@try
{
if(![pdfViewCtrl IsFinishedRendering:NO])
{
[pdfViewCtrl CancelRendering];
}
[pdfViewCtrl DocLock: YES];
[currentDoc SaveToFile:docPath flags:e_ptlinearized];
}
@catch (NSException *exc)
{
[theAppDelegate logException:exc withMessage:[NSString stringWithFormat:@"%@ was not saved.", [docPath lastPathComponent]]];
}
@finally
{
[pdfViewCtrl DocUnlock];
}
// Reload the document - to avoid random errors
[self setAndConfigureDocument:NO];
}
}
`
As a matter of interest the same error happens if I initiate the FreeText annotation by long pressing and selecting “Text” on the pop-up toolbar.
Thanks,
David