0

I need to draw some text on existing PDF file pages in objective-c without losing any existing document attributes and outlines. I know we can create new document and draw pages from existing one, but that will not copy all the document attributes and outlines to the new PDF document automatically. I need a way to just modify the PDF page without losing its original content, outlines and properties.

Thanks,

AmitSri
  • 1,209
  • 1
  • 20
  • 48

1 Answers1

0

You can't using Quartz. The PDF is essentially read-only. You will have to build a new PDF asked on the old one.

Jonathan Grynspan
  • 43,286
  • 8
  • 74
  • 104
  • Thanks for your valuable suggestion, but my concern is to retain the PDF document attributes and outlines. How that will be done using Quartz or cocoa itself? I am able to generate new PDF using Quartz, but missing the code to set source PDF document attributes and outlines to newly generated PDF. Let me know, if there is any code which will help me to achieve above. – AmitSri May 29 '12 at 04:51
  • Quartz will generate a PDF that is not identical to the original no matter what you do. However, if you take a look at the documentation for `CGPDFContext`, there are some functions that manipulate some of its metadata. – Jonathan Grynspan May 29 '12 at 12:39
  • Hi, thanks again, i got things working by modifying the newly created PDF document using PDFDocument class and modified its attributes and outlines. Now,the only thing which i want to change is the "Producer" attribute of new PDF Document. Currently it is showing "Mac OS X 10.6.8 Quartz PDFContext". – AmitSri May 29 '12 at 12:50
  • When creating the `CGPDFContext`, pass a dictionary as the third argument of `CGPDFContextCreate()`. In that dictionary, use the key `kCGPDFContextCreator` and specify the value as an `NSString` or `CFString`. – Jonathan Grynspan May 29 '12 at 19:51
  • Hi,Thanks,the key kCGPDFContextCreator will only change the creator attribute not the producer attribute [PDFDocumentProducerAttribute]. – AmitSri May 30 '12 at 05:14
  • It's the closest you'll get with Quartz. Sorry. – Jonathan Grynspan May 30 '12 at 13:09