Any feedback would be greatly appreciated. Generate PDF from the string: The following script. omfile ('micropyramid.html', 'micro.pdf') 3. The code I use to generate the 36"-wide PDF, in case it's important, is: kit = PDFKit.new(html, Generate PDF from file: The following script gives us the pdf file from a HTML file. No matter what settings I adjust, the printer always tries to print it on a single piece of paper: What I can't figure out - and I'm not sure if I need to adjust wkhtmltopdf's properties or my printer's - is how to print this 36"-wide PDF page across multiple sheets of paper. I was able to generate the same timeline on a single 36" wide page: I've been experimenting with the options in PDFKit (which uses wkhtmltopdf behind the scenes) to adjust the page size in the hope that it would allow me to print it across multiple sheets of paper. I Expect the result printed in pdf landscape mode, but I don't know how to make it landscape with this situation, the result now is only a portrait PDF.I run a web-based timeline maker and one of the most requested features is to allow users to print their timeline across multiple sheets of paper instead of squeezing it onto a single sheet.įor example, right now when a user exports his or her timeline to a PDF, it gets compressed onto a single page with landscape orientation so it can be easily printed: "document.title='' window.print() ".format(course_name)ĭriver.find_element_by_xpath('//a[normalize. Webdriver.ActionChains(driver).send_keys(Keys.ESCAPE).perform() Main_window_handle = driver.current_window_handleĭriver.find_element_by_xpath( '/html/body/div/div/div/div/div/div/div/div/div/div/input').click()ĭriver.switch_to.window(print_window_handle) S3.select_by_value(class.get_attribute('value')) List_class = driver.find_element_by_name('class')Ĭlass = S3 = Select(driver.find_element_by_name('class')) S2.select_by_value(mk.get_attribute('value')) S2 = Select(driver.find_element_by_name('course_id')) Mk = Ĭourse_name = course_name.replace(' ', '_') Create PDF files with Python and pdfkit pdfkit was the first library I learned for creating PDF files. This post will cover two packages used to create PDF files with Python, including pdfkit and ReportLab. Select_box = driver.find_element_by_name('course_id') In a previous article we talked about several ways to read PDF files with Python. S1 = Select(driver.find_element_by_name('year_id_combo')) 'fault_directory': download_path,Ĭhrome_options = webdriver.ChromeOptions()Ĭhrome_options.add_experimental_option('prefs', profile)Ĭhrome_options.add_argument('-kiosk-printing')ĭriver = webdriver.Chrome("D:\\master\\chromedriver\\2.45\\chromedriver.exe",ĭriver.find_element_by_id('username').send_keys('username')ĭriver.find_element_by_id ('password').send_keys('pass')ĭriver.find_element_by_name('login').click()ĭriver.get(' driver.find_element_by_name('year_id_combo') 'printing.print_preview_sticky_settings.appState': json.dumps(appState), Even though what I need is in landscape mode from selenium import webdriverįrom import Keysįrom import Selectĭownload_path = os.path.join(curr_dir, 'dl') I try to used pdfkit with "fromstring" with selenium "driver.getsource" but the portrait mode not so good result and finally I choose to use print PDF from chromedriver and I've succeeded make a PDF file that I want with good result but stuck in only portrait mode. I've been succeeding to print and download pdf with my script above, but I have a problem how to print/download pdf with selenium python in a LANDSCAPE mode output.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |