Forum Discussion
It looks like there are three scenarios that we are dealing with. First, I needed to switch-off the Adobe Acrobat Chrome Extension:
1. Direct Path to PDF generated on web server
Solution: Use Java IO Buffered Intput Stream.
//var url = JavaClasses.java_net.URL.newInstance("http://pathToServer/ServerName?&reportname=Custom_Bol_##########&type=pdf&fileextn=.pdf,Custom_Bol_WM011111111111");
var url = JavaClasses.java_net.URL.newInstance("http://pathToPDF/PDFile.pdf");
var inputStream = url.openStream();
var fileParse = JavaClasses.java_io.BufferedInputStream.newInstance(inputStream);
var docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_3(fileParse);
var textStripperObj = JavaClasses.org_apache_pdfbox_text.PDFTextStripper.newInstance()
outputString = textStripperObj.getText(docObj);
docObj.close();
Log.Message("Output PDF String = " +outputString)
2. PDF loaded using a long URL and displayed in non-preview mode
Solution: In this scenerio, I can type 'CTRL S', and save via the Open File Dialog to the folder I need. This I'm still working on find a reliable method to wait for the PDF file to load in Chrome (Other than a static wait). After downloaded, I can use the following code:
var firstPDF = ProjectSuite.Path + "\pathToPDF\\BOL_Test.pdf";
var outputString = "";
var orderNumber = "60022500"
var browser = Aliases.browser;
browser.pageReportserv.Keys("^s");
var dlgSaveAs = browser.dlgSaveAs;
var comboBox = dlgSaveAs.DUIViewWndClassName.Explorer_Pane.FloatNotifySink.ComboBox;
comboBox.SetText(firstPDF);
dlgSaveAs.btnSave.ClickButton();
var doc = JavaClasses.java_io.File.newInstance(firstPDF)
var docObj = JavaClasses.org_apache_pdfbox_pdmodel.PDDocument.load_2(doc);
var textStripperObj = JavaClasses.org_apache_pdfbox_text.PDFTextStripper.newInstance()
outputString = textStripperObj.getText(docObj);
docObj.close();
Log.Message("Output PDF String = " +outputString)
// Run a basic test to find a string of text
if (aqString.Find(outputString, orderNumber) != -1)
Log.Message("Found Order #: " +orderNumber)
else
Log.Error("Didn't find Order # in search string.");
3. PDF Generated in Preview Mode (Read Only)
Solution: I'm still working on a way to either download using CTRL 'S' or Buffered Input Stream. The URL is also lond a has many special characters (for spaces, etc.).
I also want to be able to control where the downloaded file gets put, so that I can locate and run a comparison or test text content. I don't want all files downloading to the same Chrome Download folder. I want to set this programatically, since we run these via Jenkin's pipeline jobs.
Related Content
- 4 years ago
- 12 years ago
Recent Discussions
- 2 days ago
- 2 days ago
- 5 days ago