Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
I have written an intro to PDF tutorial for those that are interested in PDF interactivity within your iPhone apps. This first tutorial, shows how to simply create a PDF that contains an image, some text and a border around the page.
Ok, on to the goods! There are two custom methods in the PDFViewController.m file that you will be looking at mostly. The first is CreatePDFFile. This method does exactly what it says - creates a PDF file. The second method is called createPDF, and is an IBAction method hooked to an UIButton in IB. Upon touching the button this method calls our CreatePDFFile method.
Important - there is no output after clicking the button, meaning you will not see the resulting PDF displayed on the phone. I can create a second tutorial for that purpose, but it seemed like most people were only interested in the creation of the file.
In order to view the resulting PDF go to: Users/YourUserName/Library/Application Support/iPhone Simulator/User/Applications
In this directory sort by Date Modified. If the example project here was the last app that you ran it will be at the top of this directory. Simply navigate to the documents directory of the PDF example app and you will be able to see the PDF it creates.
Let me know if you have any questions!
P.S. So it seems that the example project was larger than the allowed size for attachments. I will get the whole project up on the web for download soon, but in the meantime I have included the class files which is all you should need.
Very interested in this. I know you attached the class files, but, "explanation" is good too :-)
Also, once the PDF is created, is there a way to then send it to the email tool? Does Apple allow that?
Thanks!
You'd have to use the mailto: url scheme to open up mail.app, and, on non-jailbroken phones it is impossible to use the attachment paramter of mailto:, so you'l have to write an SMTP client.
You'd have to use the mailto: url scheme to open up mail.app, and, on non-jailbroken phones it is impossible to use the attachment paramter of mailto:, so you'l have to write an SMTP client.
There is open source code that allows you to send an email with attachment. You can either have the user set up the parameters, or you can just set up a mail account that handles the outgoing mail.
I found the source somewhere on this messageboard. It is available via SVN. I tried it and it works well. I looked for the thread and can't seem to find it. Maybe someone else has the link.
There is open source code that allows you to send an email with attachment. You can either have the user set up the parameters, or you can just set up a mail account that handles the outgoing mail.
I found the source somewhere on this messageboard. It is available via SVN. I tried it and it works well. I looked for the thread and can't seem to find it. Maybe someone else has the link.
Could you upload your copy of this code to sendspace or some other service?
Thanks - yes, found that out. The UIWebView automatically handles multi page pdf's as well (besides zooming, and it looks GOOD unlike the lower CGPDF stuff).
This is great, thank you, any more information regarding this subject would be greatly appeciated.
I have nearly finished the main section of my app, and need to display about 25 values on a pdf, this pdf needs to be viewable though the App, but does not need to be enlarged.
I am hoping that then i can take a screenshot of the page, and print it via HB's Photo printer app. Would this be viable, or would some other format be better for this type of thing?
I have a long string that I want to add to the pdf.
Any ideas on how to wrap the text? Thanks.
Sunny
The quickest way to do this is inside a for statement that takes a substring of your text for every x number of characters. This isn't a complete and robust text wrapping solution though. It's on my list of things to complete and I'll share my full solution when I'm done. :)
The quickest way to do this is inside a for statement that takes a substring of your text for every x number of characters. This isn't a complete and robust text wrapping solution though. It's on my list of things to complete and I'll share my full solution when I'm done. :)
Hi, I have around 30 fields to display in the PDF file one by one. So could you please tell me how I can insert a newline character in the content...
Hey, if anyone knows how to view a locally stored pdf in a webview, please contact me. Im thankful fore any help and a xcode project would be very appreciated.
Ok, here is the text wrapping solution that I am using. This is very basic and ensures that the wrap happens at a "space".
If you have any questions, feel free to ask.
Actually, it does not have to be that complicated. You can use:
[NSString drawInRect:]
to get what you want. Just use the PDF context you are drawing to, and you have to perform a coordinate conversion, but if you make the rect high enough (you can calc this using [NSString sizeWithFont], all wrapping is done for you.
Hey, if anyone knows how to view a locally stored pdf in a webview, please contact me. Im thankful fore any help and a xcode project would be very appreciated.
[email]chaseacton@gmail.com[/email]
Hey Chase,
There is another tutorial that I wrote that shows exactly how to do this. :) You'll find it a little further down in the tutorials section.
Actually, it does not have to be that complicated. You can use:
[NSString drawInRect:]
to get what you want. Just use the PDF context you are drawing to, and you have to perform a coordinate conversion, but if you make the rect high enough (you can calc this using [NSString sizeWithFont], all wrapping is done for you.
Hi decay,
Have you actually done what you are suggesting successfully or just basing your response on documentation provided by Apple? If you have, it would be greatly appreciated if you post your solution with a working example here and I will add it as a part of the tutorial with appropriate credit to you. :)
My experience with [NSString drawInRect:] in a PDFContext has been that it will not draw, citing an "invalid context". Had that not been the case I would have been using that all along.
Thanks, Dan
*EDIT* Figured out how to use this, refer to post #25.
Spent more time today exploring the [NSString drawInRect:] method to see if I could get it to work, and I now have a working solution. The key is that you have to push the graphics context onto the stack. Below is how it works:
So, the above code block pushes the context onto the stack, reverses the coordinates so that the text is drawn correctly, and then uses the drawInRect: withFont: method to draw the text, and finally calls the UIGraphicsPopContext() method.
It's important to note that each time you call UIGraphicsPushContext(context); you must also call the pop context method, otherwise you'll be left with nothing.
Thanks to decay for pushing me to investigate this more and enjoy everyone!
Replies
Also, once the PDF is created, is there a way to then send it to the email tool? Does Apple allow that?
Thanks!
24" iMac
8gb iPhone-Gen1
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI found the source somewhere on this messageboard. It is available via SVN. I tried it and it works well. I looked for the thread and can't seem to find it. Maybe someone else has the link.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI'd like to see this.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomehttp://www.iphonedevsdk.com/forum/iphone-sdk-development/9012-sending-attachments-email-iphone-app.html
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeUsing CGPDFPageGetDrawingTransform(page, kCGPDFCropBox, bounds, 0, true) - if you want to zoom in on large PDF it seems you are out of luck ?
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful 1Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI have nearly finished the main section of my app, and need to display about 25 values on a pdf, this pdf needs to be viewable though the App, but does not need to be enlarged.
I am hoping that then i can take a screenshot of the page, and print it via HB's Photo printer app. Would this be viable, or would some other format be better for this type of thing?
Thanks
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThanks
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI've been extremely busy the past few weeks, so my apologies for being absent on this thread.
I will create another tutorial that covers viewing a PDF after creation, and will try to have it up either Saturday or Sunday of this week.
Dan
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeCardSnap, C
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeAny ideas on how to wrap the text? Thanks.
Sunny
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeI have around 30 fields to display in the PDF file one by one. So could you please tell me how I can insert a newline character in the content...
thanks,
Ramesh.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeIf you have this solution, could you please share it with me...
thanks,
Ramesh.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[email]chaseacton@gmail.com[/email]
Freelance Inquiries: amnesiapps.com/contact
My Apps: AppStore.com/ChaseActon
I sell source code, email me.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome[NSString drawInRect:]
to get what you want. Just use the PDF context you are drawing to, and you have to perform a coordinate conversion, but if you make the rect high enough (you can calc this using [NSString sizeWithFont], all wrapping is done for you.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeThere is another tutorial that I wrote that shows exactly how to do this. :) You'll find it a little further down in the tutorials section.
Thanks,
Dan
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeHave you actually done what you are suggesting successfully or just basing your response on documentation provided by Apple? If you have, it would be greatly appreciated if you post your solution with a working example here and I will add it as a part of the tutorial with appropriate credit to you. :)
My experience with [NSString drawInRect:] in a PDFContext has been that it will not draw, citing an "invalid context". Had that not been the case I would have been using that all along.
Thanks,
Dan
*EDIT* Figured out how to use this, refer to post #25.
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like AwesomeSo, the above code block pushes the context onto the stack, reverses the coordinates so that the text is drawn correctly, and then uses the drawInRect: withFont: method to draw the text, and finally calls the UIGraphicsPopContext() method.
It's important to note that each time you call UIGraphicsPushContext(context); you must also call the pop context method, otherwise you'll be left with nothing.
Thanks to decay for pushing me to investigate this more and enjoy everyone!
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome