I am making an app where the user can load up a pdf and view it page by page and annotate it. The user can draw on the screen with different colors and also place textfields on the screen and place their text.
There is one view for the pdf and one view for the annotations. The created UITextViews are added as subviews of the annotation view (theDrawingView in the code). These text views show up fine within the application but when the pdf gets generated to include the annotations, the textviews do not show (all the other annotations do).
I tried to call the drawRect of the textView with both its own bounds and the bounds the other views are using, neither worked. The only subviews of the drawing view are textviews.
Here is where I do the drawing to generate the pdf:
for (int i = 0; i < numPages; i++) {
UIGraphicsBeginPDFPage();
//set the current pages of the views to get each page
[self nextPage];
[thePDFView drawRect:bounds];
[theDrawingView drawRect:bounds];
for(UITextView *txt in [theDrawingView subviews]){
[txt drawRect:txt.bounds];
}
}
UIGraphicsEndPDFContext();
Any ideas on how to get the text views to get drawn on the pdf context? Thanks
EDIT: Originally was using UITextFields but I had to switch to UITextViews instead to solve a different issue. The UITextViews also won’t show on a generated pdf.
Just to format that a little better, here is the code that makes a UITextView get rendered into the pdf as it is generated. This method seems to work for rendering any string object so I’m sure it would work fine for UILabels or UITextFields as well. I used UITextiews because they easily adapt to dynamic heights.