Skip to content
This repository has been archived by the owner on Sep 16, 2024. It is now read-only.

Commit

Permalink
feat(windows_data): add PdfDocument APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
halildurmus committed Oct 1, 2023
1 parent dbc4005 commit a1b366b
Show file tree
Hide file tree
Showing 13 changed files with 1,195 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/windows_data/lib/src/exports.g.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ export 'json/jsonerrorstatus.dart';
export 'json/jsonobject.dart';
export 'json/jsonvalue.dart';
export 'json/jsonvaluetype.dart';
export 'pdf/ipdfdocument.dart';
export 'pdf/ipdfpage.dart';
export 'pdf/ipdfpagedimensions.dart';
export 'pdf/ipdfpagerenderoptions.dart';
export 'pdf/pdfdocument.dart';
export 'pdf/pdfpage.dart';
export 'pdf/pdfpagedimensions.dart';
export 'pdf/pdfpagerenderoptions.dart';
export 'pdf/pdfpagerotation.dart';
export 'text/textsegment.dart';
export 'xml/dom/ixmlattribute.dart';
export 'xml/dom/ixmlcdatasection.dart';
Expand Down
107 changes: 107 additions & 0 deletions packages/windows_data/lib/src/pdf/ipdfdocument.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: constant_identifier_names, non_constant_identifier_names
// ignore_for_file: unnecessary_import, unused_import

import 'dart:async';
import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart'
hide DocumentProperties, WinRTStringConversion;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';

import 'pdfpage.dart';

/// @nodoc
const IID_IPdfDocument = '{ac7ebedd-80fa-4089-846e-81b77ff5a86c}';

class IPdfDocument extends IInspectable {
// vtable begins at 6, is 3 entries long.
IPdfDocument.fromPtr(super.ptr);

factory IPdfDocument.from(IInspectable interface) =>
interface.cast(IPdfDocument.fromPtr, IID_IPdfDocument);

PdfPage? getPage(int pageIndex) {
final pdfPage = calloc<COMObject>();

final hr = ptr.ref.vtable
.elementAt(6)
.cast<
Pointer<
NativeFunction<
HRESULT Function(VTablePointer lpVtbl, Uint32 pageIndex,
Pointer<COMObject> pdfPage)>>>()
.value
.asFunction<
int Function(VTablePointer lpVtbl, int pageIndex,
Pointer<COMObject> pdfPage)>()(
ptr.ref.lpVtbl, pageIndex, pdfPage);

if (FAILED(hr)) {
free(pdfPage);
throwWindowsException(hr);
}

if (pdfPage.isNull) {
free(pdfPage);
return null;
}

return PdfPage.fromPtr(pdfPage);
}

int get pageCount {
final value = calloc<Uint32>();

try {
final hr = ptr.ref.vtable
.elementAt(7)
.cast<
Pointer<
NativeFunction<
HRESULT Function(
VTablePointer lpVtbl, Pointer<Uint32> value)>>>()
.value
.asFunction<
int Function(VTablePointer lpVtbl, Pointer<Uint32> value)>()(
ptr.ref.lpVtbl, value);

if (FAILED(hr)) throwWindowsException(hr);

return value.value;
} finally {
free(value);
}
}

bool get isPasswordProtected {
final value = calloc<Bool>();

try {
final hr = ptr.ref.vtable
.elementAt(8)
.cast<
Pointer<
NativeFunction<
HRESULT Function(
VTablePointer lpVtbl, Pointer<Bool> value)>>>()
.value
.asFunction<
int Function(VTablePointer lpVtbl, Pointer<Bool> value)>()(
ptr.ref.lpVtbl, value);

if (FAILED(hr)) throwWindowsException(hr);

return value.value;
} finally {
free(value);
}
}
}
149 changes: 149 additions & 0 deletions packages/windows_data/lib/src/pdf/ipdfdocumentstatics.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
// Copyright (c) 2023, Dart | Windows. Please see the AUTHORS file for details.
// All rights reserved. Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

// THIS FILE IS GENERATED AUTOMATICALLY AND SHOULD NOT BE EDITED DIRECTLY.

// ignore_for_file: constant_identifier_names, non_constant_identifier_names
// ignore_for_file: unnecessary_import, unused_import

import 'dart:async';
import 'dart:ffi';

import 'package:ffi/ffi.dart';
import 'package:win32/win32.dart'
hide DocumentProperties, WinRTStringConversion;
import 'package:windows_foundation/internal.dart';
import 'package:windows_foundation/windows_foundation.dart';
import 'package:windows_storage/windows_storage.dart';

import 'pdfdocument.dart';

/// @nodoc
const IID_IPdfDocumentStatics = '{433a0b5f-c007-4788-90f2-08143d922599}';

class IPdfDocumentStatics extends IInspectable {
// vtable begins at 6, is 4 entries long.
IPdfDocumentStatics.fromPtr(super.ptr);

factory IPdfDocumentStatics.from(IInspectable interface) =>
interface.cast(IPdfDocumentStatics.fromPtr, IID_IPdfDocumentStatics);

Future<PdfDocument?> loadFromFileAsync(IStorageFile? file) {
final asyncInfo = calloc<COMObject>();

final hr =
ptr.ref.vtable
.elementAt(6)
.cast<
Pointer<
NativeFunction<
HRESULT Function(
VTablePointer lpVtbl,
VTablePointer file,
Pointer<COMObject> asyncInfo)>>>()
.value
.asFunction<
int Function(VTablePointer lpVtbl, VTablePointer file,
Pointer<COMObject> asyncInfo)>()(
ptr.ref.lpVtbl, file.lpVtbl, asyncInfo);

if (FAILED(hr)) {
free(asyncInfo);
throwWindowsException(hr);
}

final asyncOperation = IAsyncOperation<PdfDocument?>.fromPtr(asyncInfo,
creator: PdfDocument.fromPtr);
return asyncOperation.toFuture(asyncOperation.getResults);
}

Future<PdfDocument?> loadFromFileWithPasswordAsync(
IStorageFile? file, String password) {
final asyncInfo = calloc<COMObject>();

final hr =
ptr.ref.vtable
.elementAt(7)
.cast<
Pointer<
NativeFunction<
HRESULT Function(
VTablePointer lpVtbl,
VTablePointer file,
IntPtr password,
Pointer<COMObject> asyncInfo)>>>()
.value
.asFunction<
int Function(VTablePointer lpVtbl, VTablePointer file,
int password, Pointer<COMObject> asyncInfo)>()(
ptr.ref.lpVtbl, file.lpVtbl, password.toHString(), asyncInfo);

if (FAILED(hr)) {
free(asyncInfo);
throwWindowsException(hr);
}

final asyncOperation = IAsyncOperation<PdfDocument?>.fromPtr(asyncInfo,
creator: PdfDocument.fromPtr);
return asyncOperation.toFuture(asyncOperation.getResults);
}

Future<PdfDocument?> loadFromStreamAsync(IRandomAccessStream? inputStream) {
final asyncInfo = calloc<COMObject>();

final hr = ptr.ref.vtable
.elementAt(8)
.cast<
Pointer<
NativeFunction<
HRESULT Function(
VTablePointer lpVtbl,
VTablePointer inputStream,
Pointer<COMObject> asyncInfo)>>>()
.value
.asFunction<
int Function(VTablePointer lpVtbl, VTablePointer inputStream,
Pointer<COMObject> asyncInfo)>()(
ptr.ref.lpVtbl, inputStream.lpVtbl, asyncInfo);

if (FAILED(hr)) {
free(asyncInfo);
throwWindowsException(hr);
}

final asyncOperation = IAsyncOperation<PdfDocument?>.fromPtr(asyncInfo,
creator: PdfDocument.fromPtr);
return asyncOperation.toFuture(asyncOperation.getResults);
}

Future<PdfDocument?> loadFromStreamWithPasswordAsync(
IRandomAccessStream? inputStream, String password) {
final asyncInfo = calloc<COMObject>();

final hr = ptr.ref.vtable
.elementAt(9)
.cast<
Pointer<
NativeFunction<
HRESULT Function(
VTablePointer lpVtbl,
VTablePointer inputStream,
IntPtr password,
Pointer<COMObject> asyncInfo)>>>()
.value
.asFunction<
int Function(VTablePointer lpVtbl, VTablePointer inputStream,
int password, Pointer<COMObject> asyncInfo)>()(
ptr.ref.lpVtbl, inputStream.lpVtbl, password.toHString(), asyncInfo);

if (FAILED(hr)) {
free(asyncInfo);
throwWindowsException(hr);
}

final asyncOperation = IAsyncOperation<PdfDocument?>.fromPtr(asyncInfo,
creator: PdfDocument.fromPtr);
return asyncOperation.toFuture(asyncOperation.getResults);
}
}
Loading

0 comments on commit a1b366b

Please sign in to comment.