Revisions
-
zooba revised this gist
Aug 26, 2020 . 1 changed file with 13 additions and 4 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,12 +1,18 @@ Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 10:03:53) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import os, time >>> PDF_FILENAME = input("Path to PDF: ") >>> OUT_FILE = os.path.abspath(input("Path to output PNG: ")) >>> >>> import winrt.windows.data.pdf as PDF >>> from winrt.windows.storage import StorageFile >>> op = StorageFile.get_file_from_path_async(PDF_FILENAME) >>> time.sleep(0.5) # should really await, but this is easier >>> in_file = op.get_results() >>> in_file <_winrt_Windows_Storage.StorageFile object at 0x00000222A4795D30> >>> op = PDF.PdfDocument.load_from_file_async(in_file) >>> time.sleep(0.5) >>> pdf = op.get_results() >>> pdf <_winrt_Windows_Data_Pdf.PdfDocument object at 0x00000222A4795D90> @@ -19,13 +25,16 @@ Type "help", "copyright", "credits" or "license" for more information. 816.0 >>> page.size.height 1056.0 >>> >>> from winrt.windows.storage import FileAccessMode, StorageOpenOptions >>> from winrt.windows.storage.streams import FileRandomAccessStream, FileOpenDisposition >>> op = FileRandomAccessStream.open_async(OUT_FILE, FileAccessMode.READ_WRITE, StorageOpenOptions.NONE, FileOpenDisposition.OPEN_ALWAYS) >>> time.sleep(0.5) >>> stream = op.get_results() >>> >>> op = page.render_to_stream_async(stream) >>> time.sleep(0.5) >>> op.get_results() >>> stream.close() >>> page.close() >>> os.startfile(OUT_FILE) -
zooba created this gist
Jul 24, 2020 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,31 @@ Python 3.7.8 (tags/v3.7.8:4b47a5b6ba, Jun 28 2020, 10:03:53) [MSC v.1916 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import winrt.windows.data.pdf as PDF >>> from winrt.windows.storage import StorageFile >>> op = StorageFile.get_file_from_path_async(PDF_FILENAME) >>> in_file = op.get_results() >>> in_file <_winrt_Windows_Storage.StorageFile object at 0x00000222A4795D30> >>> op = PDF.PdfDocument.load_from_file_async(in_file) >>> pdf = op.get_results() >>> pdf <_winrt_Windows_Data_Pdf.PdfDocument object at 0x00000222A4795D90> >>> pdf.page_count 10 >>> page = pdf.get_page(1) >>> page <_winrt_Windows_Data_Pdf.PdfPage object at 0x00000222A4795D70> >>> page.size.width 816.0 >>> page.size.height 1056.0 >>> from winrt.windows.storage import FileAccessMode, StorageOpenOptions, FileOpenDisposition >>> from winrt.windows.storage.streams import FileRandomAccessStream >>> op = FRAS.open_async(OUT_FILE, FileAccessMode.READ_WRITE, StorageOpenOptions.NONE, FileOpenDisposition.OPEN_ALWAYS) >>> stream = op.get_results() >>> op = page.render_to_stream_async(stream) >>> op.get_results() >>> stream.close() >>> page.close() >>> import os >>> os.startfile(OUT_FILE)