Example #1
0
    def test_print_to_pdf(self, library):
        testfile = RESOURCE_DIR / "browser_docs.html"
        library.open_available_browser(f"file://{testfile}", headless=True)
        with temp_filename() as tmp_file:
            library.print_to_pdf(tmp_file)
            text = PDF().get_text_from_pdf(tmp_file)

            assert "Please explicitly use either RPA.Browser.Selenium" in text[1]
Example #2
0
    def test_print_to_pdf_different_from_start_page(self, library):
        startpage = RESOURCE_DIR / "alert.html"
        testfile = RESOURCE_DIR / "browser_docs.html"
        library.open_available_browser(f"file://{startpage}", headless=True)
        with temp_filename() as tmp_file:
            library.go_to(f"file://{testfile}")
            library.print_to_pdf(output_path=tmp_file)
            text = PDF().get_text_from_pdf(tmp_file)

            assert "Please explicitly use either RPA.Browser.Selenium" in text[1]
Example #3
0
def library():
    return PDF()
Example #4
0
def export_the_table_as_a_pdf():
    sales_results_html = browser.get_property(selector="css=#sales-results",
                                              property="outerHTML")
    pdf = PDF()
    pdf.html_to_pdf(sales_results_html, "output/sales_results.pdf")
Example #5
0
        "Rate/Price: %s"
        % library.find_text("text:Rate/Price", direction="down")
    )
    LOGGER.info("Total: %s" % library.find_text("text:Total"))


def get_text_from_pdf():
    regex = r".*\@.*\..*"
    pages = library.get_text_from_pdf(details=True)
    for page in pages:
        for item in pages[page]:
            matches = re.findall(regex, item.text)
            if len(matches) > 0:
                LOGGER.info(matches)


def main():
    filename = Path(__file__).parent / "invoice.pdf"
    library.open_pdf_document(filename)
    get_values_from_box()
    get_values_by_label()
    get_text_from_pdf()


if __name__ == "__main__":
    library = PDF()
    try:
        main()
    finally:
        library.close_all_pdf_documents()
Example #6
0
 def extract_data(path_to_pdf_file: str):
     pdf = PDF()
     return pdf.get_text_from_pdf(path_to_pdf_file)
Example #7
0
def open_and_complete_form(url: str, constitutional_response: str,
                           csv_filename: str):
    try:
        browser = Browser.Browser()
        browser.new_browser(headless=False)
        browser.new_page(url)
        button_response = "text=" + constitutional_response
        browser.click(selector=button_response)
        pdf = PDF()
        fileSystem = FileSystem()
        print(csv_filename)
        with open(csv_filename) as csv_file:
            csv_reader = csv.reader(csv_file, delimiter=',')
            line_count = 0
            if not os.path.exists(run_archive_filepath):
                os.makedirs(run_archive_filepath)
            else:
                fileSystem.empty_directory(run_archive_filepath)
            for row in csv_reader:
                if line_count == 0:
                    line_count += 1
                else:
                    try:
                        print("Completing order " + row[0])
                        #browser.click(selector="id=head")
                        #time.sleep(2)
                        #browser.keyboard_key(action="press", key="ArrowDown")
                        #browser.keyboard_key(action="press", key="Enter")
                        #browser.press_keys('id=head', "Arrowdown 2", "Enter")
                        #browser.click(selector='xpath=//select/option[@value="'+row[1]+'"]')
                        browser.click(
                            selector=
                            'xpath=//form/div/div/div/label[@for="id-body-' +
                            row[2] + '"]')
                        browser.fill_text(
                            selector=
                            'xpath=//div/input[@placeholder="Enter the part number for the legs"]',
                            txt=row[3])
                        browser.fill_text(selector="id=address", txt=row[4])
                        browser.select_options_by("id=head",
                                                  SelectAttribute["value"],
                                                  str(row[1]))
                        browser.click(selector="id=preview")
                        browser.click(selector="id=order")
                        receipt_html_text = browser.get_text(
                            selector="id=receipt")
                        robot_previous_filepath = run_archive_filepath + "\\robot_preview_image_" + str(
                            row[0]) + ".png"
                        browser.wait_for_elements_state(
                            selector="id=robot-preview-image")
                        browser.take_screenshot(
                            selector="id=robot-preview-image",
                            filename=robot_previous_filepath,
                            fullPage=True)
                        receipt_file_path = run_archive_filepath + "\\receipt_file_" + str(
                            row[0])
                        pdf.html_to_pdf(receipt_html_text,
                                        receipt_file_path + ".pdf")
                        browser.click(selector="id=order-another")
                        fileSystem.wait_until_created(robot_previous_filepath)
                        browser.click(selector=button_response)
                        pdf.add_watermark_image_to_pdf(
                            image_path=robot_previous_filepath,
                            output_path=receipt_file_path + "_robot_image.pdf",
                            source_path=receipt_file_path + ".pdf")
                        fileSystem.wait_until_created(path=receipt_file_path +
                                                      "_robot_image.pdf")
                        print("Order complete")
                    except Exception as errorMessage:
                        try:
                            error_message = browser.get_text(
                                selector=
                                'xpath=//div[@class="alert alert-danger"]')
                        except:
                            error_message = errorMessage
                        finally:
                            print("Failed to process order: " +
                                  str(error_message))
                            browser.playwright.close()
                            browser.new_browser(headless=False)
                            browser.new_page(url)
                            button_response = "text=" + constitutional_response
                            browser.click(selector=button_response)

                    finally:
                        print("Getting next order...")

    finally:
        try:
            browser.playwright.close()
        finally:
            print("all orders complete")
Example #8
0
import logging
import os
from pathlib import Path
import shutil
import sys

from RPA.Archive import Archive
from RPA.Browser import Browser
from RPA.FileSystem import FileSystem
from RPA.PDF import PDF
from RPA.Robocloud.Secrets import Secrets
from RPA.Robocloud.Items import Items

archive = Archive()
browser = Browser()
pdf = PDF()
secretmanager = Secrets()
workitems = Items()
files = FileSystem()

output_dir = Path(".") / "output"
image_dir = output_dir / "images"
pdf_dir = output_dir / "pdfs"


def main():
    """Robot workflow actions."""
    all_steps_done = False
    try:
        clear_previous_run()  # this can be skipped
        open_page()