1use core::ffi::*;
4use core::ptr::NonNull;
5use objc2::__framework_prelude::*;
6#[cfg(feature = "objc2-app-kit")]
7#[cfg(target_os = "macos")]
8use objc2_app_kit::*;
9#[cfg(feature = "objc2-core-graphics")]
10use objc2_core_graphics::*;
11use objc2_foundation::*;
12
13use crate::*;
14
15#[repr(transparent)]
18#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
19pub struct PDFPrintScalingMode(pub NSInteger);
20impl PDFPrintScalingMode {
21 #[doc(alias = "kPDFPrintPageScaleNone")]
22 pub const PageScaleNone: Self = Self(0);
23 #[doc(alias = "kPDFPrintPageScaleToFit")]
24 pub const PageScaleToFit: Self = Self(1);
25 #[doc(alias = "kPDFPrintPageScaleDownToFit")]
26 pub const PageScaleDownToFit: Self = Self(2);
27}
28
29unsafe impl Encode for PDFPrintScalingMode {
30 const ENCODING: Encoding = NSInteger::ENCODING;
31}
32
33unsafe impl RefEncode for PDFPrintScalingMode {
34 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
35}
36
37#[repr(transparent)]
40#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
41pub struct PDFDocumentPermissions(pub NSInteger);
42impl PDFDocumentPermissions {
43 #[doc(alias = "kPDFDocumentPermissionsNone")]
44 pub const None: Self = Self(0);
45 #[doc(alias = "kPDFDocumentPermissionsUser")]
46 pub const User: Self = Self(1);
47 #[doc(alias = "kPDFDocumentPermissionsOwner")]
48 pub const Owner: Self = Self(2);
49}
50
51unsafe impl Encode for PDFDocumentPermissions {
52 const ENCODING: Encoding = NSInteger::ENCODING;
53}
54
55unsafe impl RefEncode for PDFDocumentPermissions {
56 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
57}
58
59extern "C" {
60 pub static PDFDocumentDidUnlockNotification: &'static NSNotificationName;
62}
63
64extern "C" {
65 pub static PDFDocumentDidBeginFindNotification: &'static NSNotificationName;
67}
68
69extern "C" {
70 pub static PDFDocumentDidEndFindNotification: &'static NSNotificationName;
72}
73
74extern "C" {
75 pub static PDFDocumentDidBeginPageFindNotification: &'static NSNotificationName;
77}
78
79extern "C" {
80 pub static PDFDocumentDidEndPageFindNotification: &'static NSNotificationName;
82}
83
84extern "C" {
85 pub static PDFDocumentDidFindMatchNotification: &'static NSNotificationName;
87}
88
89extern "C" {
90 pub static PDFDocumentDidBeginWriteNotification: &'static NSNotificationName;
92}
93
94extern "C" {
95 pub static PDFDocumentDidEndWriteNotification: &'static NSNotificationName;
97}
98
99extern "C" {
100 pub static PDFDocumentDidBeginPageWriteNotification: &'static NSNotificationName;
102}
103
104extern "C" {
105 pub static PDFDocumentDidEndPageWriteNotification: &'static NSNotificationName;
107}
108
109extern "C" {
110 pub static PDFDocumentFoundSelectionKey: &'static NSString;
112}
113
114extern "C" {
115 pub static PDFDocumentPageIndexKey: &'static NSString;
117}
118
119pub type PDFDocumentAttribute = NSString;
122
123extern "C" {
124 pub static PDFDocumentTitleAttribute: &'static PDFDocumentAttribute;
126}
127
128extern "C" {
129 pub static PDFDocumentAuthorAttribute: &'static PDFDocumentAttribute;
131}
132
133extern "C" {
134 pub static PDFDocumentSubjectAttribute: &'static PDFDocumentAttribute;
136}
137
138extern "C" {
139 pub static PDFDocumentCreatorAttribute: &'static PDFDocumentAttribute;
141}
142
143extern "C" {
144 pub static PDFDocumentProducerAttribute: &'static PDFDocumentAttribute;
146}
147
148extern "C" {
149 pub static PDFDocumentCreationDateAttribute: &'static PDFDocumentAttribute;
151}
152
153extern "C" {
154 pub static PDFDocumentModificationDateAttribute: &'static PDFDocumentAttribute;
156}
157
158extern "C" {
159 pub static PDFDocumentKeywordsAttribute: &'static PDFDocumentAttribute;
161}
162
163pub type PDFDocumentWriteOption = NSString;
166
167extern "C" {
168 pub static PDFDocumentOwnerPasswordOption: &'static PDFDocumentWriteOption;
170}
171
172extern "C" {
173 pub static PDFDocumentUserPasswordOption: &'static PDFDocumentWriteOption;
175}
176
177extern "C" {
178 pub static PDFDocumentAccessPermissionsOption: &'static PDFDocumentWriteOption;
180}
181
182extern "C" {
183 pub static PDFDocumentBurnInAnnotationsOption: &'static PDFDocumentWriteOption;
185}
186
187extern "C" {
188 pub static PDFDocumentSaveTextFromOCROption: &'static PDFDocumentWriteOption;
190}
191
192extern "C" {
193 pub static PDFDocumentSaveImagesAsJPEGOption: &'static PDFDocumentWriteOption;
195}
196
197extern "C" {
198 pub static PDFDocumentOptimizeImagesForScreenOption: &'static PDFDocumentWriteOption;
200}
201
202#[repr(transparent)]
205#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
206pub struct PDFAccessPermissions(pub NSUInteger);
207impl PDFAccessPermissions {
208 #[doc(alias = "PDFAllowsLowQualityPrinting")]
209 pub const AllowsLowQualityPrinting: Self = Self(1 << 0);
210 #[doc(alias = "PDFAllowsHighQualityPrinting")]
211 pub const AllowsHighQualityPrinting: Self = Self(1 << 1);
212 #[doc(alias = "PDFAllowsDocumentChanges")]
213 pub const AllowsDocumentChanges: Self = Self(1 << 2);
214 #[doc(alias = "PDFAllowsDocumentAssembly")]
215 pub const AllowsDocumentAssembly: Self = Self(1 << 3);
216 #[doc(alias = "PDFAllowsContentCopying")]
217 pub const AllowsContentCopying: Self = Self(1 << 4);
218 #[doc(alias = "PDFAllowsContentAccessibility")]
219 pub const AllowsContentAccessibility: Self = Self(1 << 5);
220 #[doc(alias = "PDFAllowsCommenting")]
221 pub const AllowsCommenting: Self = Self(1 << 6);
222 #[doc(alias = "PDFAllowsFormFieldEntry")]
223 pub const AllowsFormFieldEntry: Self = Self(1 << 7);
224}
225
226unsafe impl Encode for PDFAccessPermissions {
227 const ENCODING: Encoding = NSUInteger::ENCODING;
228}
229
230unsafe impl RefEncode for PDFAccessPermissions {
231 const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
232}
233
234extern_class!(
235 #[unsafe(super(NSObject))]
237 #[derive(Debug, PartialEq, Eq, Hash)]
238 pub struct PDFDocument;
239);
240
241extern_conformance!(
242 unsafe impl NSCopying for PDFDocument {}
243);
244
245unsafe impl CopyingHelper for PDFDocument {
246 type Result = Self;
247}
248
249extern_conformance!(
250 unsafe impl NSObjectProtocol for PDFDocument {}
251);
252
253impl PDFDocument {
254 extern_methods!(
255 #[unsafe(method(init))]
256 #[unsafe(method_family = init)]
257 pub unsafe fn init(this: Allocated<Self>) -> Retained<Self>;
258
259 #[unsafe(method(initWithURL:))]
260 #[unsafe(method_family = init)]
261 pub unsafe fn initWithURL(this: Allocated<Self>, url: &NSURL) -> Option<Retained<Self>>;
262
263 #[unsafe(method(initWithData:))]
264 #[unsafe(method_family = init)]
265 pub unsafe fn initWithData(this: Allocated<Self>, data: &NSData) -> Option<Retained<Self>>;
266
267 #[unsafe(method(documentURL))]
268 #[unsafe(method_family = none)]
269 pub unsafe fn documentURL(&self) -> Option<Retained<NSURL>>;
270
271 #[cfg(feature = "objc2-core-graphics")]
272 #[unsafe(method(documentRef))]
273 #[unsafe(method_family = none)]
274 pub unsafe fn documentRef(&self) -> Option<Retained<CGPDFDocument>>;
275
276 #[unsafe(method(documentAttributes))]
277 #[unsafe(method_family = none)]
278 pub unsafe fn documentAttributes(&self) -> Option<Retained<NSDictionary>>;
279
280 #[unsafe(method(setDocumentAttributes:))]
288 #[unsafe(method_family = none)]
289 pub unsafe fn setDocumentAttributes(&self, document_attributes: Option<&NSDictionary>);
290
291 #[unsafe(method(majorVersion))]
292 #[unsafe(method_family = none)]
293 pub unsafe fn majorVersion(&self) -> NSInteger;
294
295 #[unsafe(method(minorVersion))]
296 #[unsafe(method_family = none)]
297 pub unsafe fn minorVersion(&self) -> NSInteger;
298
299 #[unsafe(method(isEncrypted))]
300 #[unsafe(method_family = none)]
301 pub unsafe fn isEncrypted(&self) -> bool;
302
303 #[unsafe(method(isLocked))]
304 #[unsafe(method_family = none)]
305 pub unsafe fn isLocked(&self) -> bool;
306
307 #[unsafe(method(unlockWithPassword:))]
308 #[unsafe(method_family = none)]
309 pub unsafe fn unlockWithPassword(&self, password: &NSString) -> bool;
310
311 #[unsafe(method(allowsPrinting))]
312 #[unsafe(method_family = none)]
313 pub unsafe fn allowsPrinting(&self) -> bool;
314
315 #[unsafe(method(allowsCopying))]
316 #[unsafe(method_family = none)]
317 pub unsafe fn allowsCopying(&self) -> bool;
318
319 #[unsafe(method(allowsDocumentChanges))]
320 #[unsafe(method_family = none)]
321 pub unsafe fn allowsDocumentChanges(&self) -> bool;
322
323 #[unsafe(method(allowsDocumentAssembly))]
324 #[unsafe(method_family = none)]
325 pub unsafe fn allowsDocumentAssembly(&self) -> bool;
326
327 #[unsafe(method(allowsContentAccessibility))]
328 #[unsafe(method_family = none)]
329 pub unsafe fn allowsContentAccessibility(&self) -> bool;
330
331 #[unsafe(method(allowsCommenting))]
332 #[unsafe(method_family = none)]
333 pub unsafe fn allowsCommenting(&self) -> bool;
334
335 #[unsafe(method(allowsFormFieldEntry))]
336 #[unsafe(method_family = none)]
337 pub unsafe fn allowsFormFieldEntry(&self) -> bool;
338
339 #[unsafe(method(accessPermissions))]
340 #[unsafe(method_family = none)]
341 pub unsafe fn accessPermissions(&self) -> PDFAccessPermissions;
342
343 #[unsafe(method(permissionsStatus))]
344 #[unsafe(method_family = none)]
345 pub unsafe fn permissionsStatus(&self) -> PDFDocumentPermissions;
346
347 #[unsafe(method(string))]
348 #[unsafe(method_family = none)]
349 pub unsafe fn string(&self) -> Option<Retained<NSString>>;
350
351 #[unsafe(method(delegate))]
352 #[unsafe(method_family = none)]
353 pub unsafe fn delegate(&self) -> Option<Retained<ProtocolObject<dyn PDFDocumentDelegate>>>;
354
355 #[unsafe(method(setDelegate:))]
359 #[unsafe(method_family = none)]
360 pub unsafe fn setDelegate(
361 &self,
362 delegate: Option<&ProtocolObject<dyn PDFDocumentDelegate>>,
363 );
364
365 #[unsafe(method(dataRepresentation))]
366 #[unsafe(method_family = none)]
367 pub unsafe fn dataRepresentation(&self) -> Option<Retained<NSData>>;
368
369 #[unsafe(method(dataRepresentationWithOptions:))]
373 #[unsafe(method_family = none)]
374 pub unsafe fn dataRepresentationWithOptions(
375 &self,
376 options: &NSDictionary,
377 ) -> Option<Retained<NSData>>;
378
379 #[unsafe(method(writeToFile:))]
380 #[unsafe(method_family = none)]
381 pub unsafe fn writeToFile(&self, path: &NSString) -> bool;
382
383 #[unsafe(method(writeToFile:withOptions:))]
387 #[unsafe(method_family = none)]
388 pub unsafe fn writeToFile_withOptions(
389 &self,
390 path: &NSString,
391 options: Option<&NSDictionary<PDFDocumentWriteOption, AnyObject>>,
392 ) -> bool;
393
394 #[unsafe(method(writeToURL:))]
395 #[unsafe(method_family = none)]
396 pub unsafe fn writeToURL(&self, url: &NSURL) -> bool;
397
398 #[unsafe(method(writeToURL:withOptions:))]
402 #[unsafe(method_family = none)]
403 pub unsafe fn writeToURL_withOptions(
404 &self,
405 url: &NSURL,
406 options: Option<&NSDictionary<PDFDocumentWriteOption, AnyObject>>,
407 ) -> bool;
408
409 #[cfg(feature = "PDFOutline")]
410 #[unsafe(method(outlineRoot))]
411 #[unsafe(method_family = none)]
412 pub unsafe fn outlineRoot(&self) -> Option<Retained<PDFOutline>>;
413
414 #[cfg(feature = "PDFOutline")]
415 #[unsafe(method(setOutlineRoot:))]
417 #[unsafe(method_family = none)]
418 pub unsafe fn setOutlineRoot(&self, outline_root: Option<&PDFOutline>);
419
420 #[cfg(all(feature = "PDFOutline", feature = "PDFSelection"))]
421 #[unsafe(method(outlineItemForSelection:))]
422 #[unsafe(method_family = none)]
423 pub unsafe fn outlineItemForSelection(
424 &self,
425 selection: &PDFSelection,
426 ) -> Option<Retained<PDFOutline>>;
427
428 #[unsafe(method(pageCount))]
429 #[unsafe(method_family = none)]
430 pub unsafe fn pageCount(&self) -> NSUInteger;
431
432 #[cfg(feature = "PDFPage")]
433 #[unsafe(method(pageAtIndex:))]
434 #[unsafe(method_family = none)]
435 pub unsafe fn pageAtIndex(&self, index: NSUInteger) -> Option<Retained<PDFPage>>;
436
437 #[cfg(feature = "PDFPage")]
438 #[unsafe(method(indexForPage:))]
439 #[unsafe(method_family = none)]
440 pub unsafe fn indexForPage(&self, page: &PDFPage) -> NSUInteger;
441
442 #[cfg(feature = "PDFPage")]
443 #[unsafe(method(insertPage:atIndex:))]
444 #[unsafe(method_family = none)]
445 pub unsafe fn insertPage_atIndex(&self, page: &PDFPage, index: NSUInteger);
446
447 #[unsafe(method(removePageAtIndex:))]
448 #[unsafe(method_family = none)]
449 pub unsafe fn removePageAtIndex(&self, index: NSUInteger);
450
451 #[unsafe(method(exchangePageAtIndex:withPageAtIndex:))]
452 #[unsafe(method_family = none)]
453 pub unsafe fn exchangePageAtIndex_withPageAtIndex(
454 &self,
455 index_a: NSUInteger,
456 index_b: NSUInteger,
457 );
458
459 #[unsafe(method(pageClass))]
460 #[unsafe(method_family = none)]
461 pub unsafe fn pageClass(&self) -> &'static AnyClass;
462
463 #[cfg(feature = "PDFSelection")]
464 #[unsafe(method(findString:withOptions:))]
465 #[unsafe(method_family = none)]
466 pub unsafe fn findString_withOptions(
467 &self,
468 string: &NSString,
469 options: NSStringCompareOptions,
470 ) -> Retained<NSArray<PDFSelection>>;
471
472 #[unsafe(method(beginFindString:withOptions:))]
473 #[unsafe(method_family = none)]
474 pub unsafe fn beginFindString_withOptions(
475 &self,
476 string: &NSString,
477 options: NSStringCompareOptions,
478 );
479
480 #[unsafe(method(beginFindStrings:withOptions:))]
481 #[unsafe(method_family = none)]
482 pub unsafe fn beginFindStrings_withOptions(
483 &self,
484 strings: &NSArray<NSString>,
485 options: NSStringCompareOptions,
486 );
487
488 #[cfg(feature = "PDFSelection")]
489 #[unsafe(method(findString:fromSelection:withOptions:))]
490 #[unsafe(method_family = none)]
491 pub unsafe fn findString_fromSelection_withOptions(
492 &self,
493 string: &NSString,
494 selection: Option<&PDFSelection>,
495 options: NSStringCompareOptions,
496 ) -> Option<Retained<PDFSelection>>;
497
498 #[unsafe(method(isFinding))]
499 #[unsafe(method_family = none)]
500 pub unsafe fn isFinding(&self) -> bool;
501
502 #[unsafe(method(cancelFindString))]
503 #[unsafe(method_family = none)]
504 pub unsafe fn cancelFindString(&self);
505
506 #[cfg(feature = "objc2-app-kit")]
507 #[cfg(target_os = "macos")]
508 #[unsafe(method(printOperationForPrintInfo:scalingMode:autoRotate:))]
509 #[unsafe(method_family = none)]
510 pub unsafe fn printOperationForPrintInfo_scalingMode_autoRotate(
511 &self,
512 print_info: Option<&NSPrintInfo>,
513 scale_mode: PDFPrintScalingMode,
514 do_rotate: bool,
515 mtm: MainThreadMarker,
516 ) -> Option<Retained<NSPrintOperation>>;
517
518 #[cfg(feature = "PDFSelection")]
519 #[unsafe(method(selectionForEntireDocument))]
520 #[unsafe(method_family = none)]
521 pub unsafe fn selectionForEntireDocument(&self) -> Option<Retained<PDFSelection>>;
522
523 #[cfg(all(feature = "PDFPage", feature = "PDFSelection"))]
524 #[unsafe(method(selectionFromPage:atPoint:toPage:atPoint:))]
525 #[unsafe(method_family = none)]
526 pub unsafe fn selectionFromPage_atPoint_toPage_atPoint(
527 &self,
528 start_page: &PDFPage,
529 start_point: NSPoint,
530 end_page: &PDFPage,
531 end_point: NSPoint,
532 ) -> Option<Retained<PDFSelection>>;
533
534 #[cfg(all(feature = "PDFPage", feature = "PDFSelection"))]
535 #[unsafe(method(selectionFromPage:atPoint:toPage:atPoint:withGranularity:))]
536 #[unsafe(method_family = none)]
537 pub unsafe fn selectionFromPage_atPoint_toPage_atPoint_withGranularity(
538 &self,
539 start_page: &PDFPage,
540 start_point: NSPoint,
541 end_page: &PDFPage,
542 end_point: NSPoint,
543 granularity: PDFSelectionGranularity,
544 ) -> Option<Retained<PDFSelection>>;
545
546 #[cfg(all(feature = "PDFPage", feature = "PDFSelection"))]
547 #[unsafe(method(selectionFromPage:atCharacterIndex:toPage:atCharacterIndex:))]
548 #[unsafe(method_family = none)]
549 pub unsafe fn selectionFromPage_atCharacterIndex_toPage_atCharacterIndex(
550 &self,
551 start_page: &PDFPage,
552 start_character: NSUInteger,
553 end_page: &PDFPage,
554 end_character: NSUInteger,
555 ) -> Option<Retained<PDFSelection>>;
556 );
557}
558
559impl PDFDocument {
561 extern_methods!(
562 #[unsafe(method(new))]
563 #[unsafe(method_family = new)]
564 pub unsafe fn new() -> Retained<Self>;
565 );
566}
567
568extern_protocol!(
569 pub unsafe trait PDFDocumentDelegate: NSObjectProtocol {
571 #[optional]
572 #[unsafe(method(documentDidUnlock:))]
573 #[unsafe(method_family = none)]
574 unsafe fn documentDidUnlock(&self, notification: &NSNotification);
575
576 #[optional]
577 #[unsafe(method(documentDidBeginDocumentFind:))]
578 #[unsafe(method_family = none)]
579 unsafe fn documentDidBeginDocumentFind(&self, notification: &NSNotification);
580
581 #[optional]
582 #[unsafe(method(documentDidEndDocumentFind:))]
583 #[unsafe(method_family = none)]
584 unsafe fn documentDidEndDocumentFind(&self, notification: &NSNotification);
585
586 #[optional]
587 #[unsafe(method(documentDidBeginPageFind:))]
588 #[unsafe(method_family = none)]
589 unsafe fn documentDidBeginPageFind(&self, notification: &NSNotification);
590
591 #[optional]
592 #[unsafe(method(documentDidEndPageFind:))]
593 #[unsafe(method_family = none)]
594 unsafe fn documentDidEndPageFind(&self, notification: &NSNotification);
595
596 #[optional]
597 #[unsafe(method(documentDidFindMatch:))]
598 #[unsafe(method_family = none)]
599 unsafe fn documentDidFindMatch(&self, notification: &NSNotification);
600
601 #[cfg(feature = "PDFSelection")]
602 #[optional]
603 #[unsafe(method(didMatchString:))]
604 #[unsafe(method_family = none)]
605 unsafe fn didMatchString(&self, instance: &PDFSelection);
606
607 #[optional]
608 #[unsafe(method(classForPage))]
609 #[unsafe(method_family = none)]
610 unsafe fn classForPage(&self) -> &'static AnyClass;
611
612 #[optional]
613 #[unsafe(method(classForAnnotationType:))]
614 #[unsafe(method_family = none)]
615 unsafe fn classForAnnotationType(&self, annotation_type: &NSString) -> &'static AnyClass;
616
617 #[deprecated]
621 #[optional]
622 #[unsafe(method(classForAnnotationClass:))]
623 #[unsafe(method_family = none)]
624 unsafe fn classForAnnotationClass(&self, annotation_class: &AnyClass) -> &'static AnyClass;
625 }
626);