Chrome headless print-to-pdf for flattening PDF - pdf

I was wondering if I can use chrome's headless print-to-pdf functionality to flatten an existing PDF file.
This one works, webpage to PDF:
chrome --headless --print-to-pdf="D:\\fromPath\\x_flat.pdf" https://google.com
a PDF file named x is generated.
Am looking for something similar like below:(not working however)
chrome --headless --print-to-pdf="D:\\fromPath\\x_flat.pdf" "file:///D:/fromPath/x_UnFlat.pdf"
Is this available in the scope of headless functionality. Instead of passing a webpage, Can I pass an existing PDF file?
PS: other options with Adobe library, itextsharp, PDFSharp cannot be used because of certain security reason. So am forced to do flattening using "Print to PDF" methods such as Microsoft Print to PDF or chrome's.
Microsoft Print to PDF is just giving a blank document.

Related

how to upload file in headless mode without button tag

Is there any way to upload a file using rebot framework without tag and with the headless mode activated. I tried to use AutoIt and sikuliLibrary but they are not working .
best Regards
If you have an input element, you can use Choose File keyword :
Choose File id=input_id C://document/file.txt
Check the documentation : https://robotframework.org/SeleniumLibrary/SeleniumLibrary.html#Choose%20File
You can upload the file with Selenium by sending the file you want to upload to a special file.
This will work regardless to the headless or regular Selenium mode.
With Python language syntax it will be:
driver.find_element_by_xpath("//input[#type='file']").send_keys("the_full_path_to_your_file")
With other languages it will be similar, just with some syntax changes.

Converting docx to PDF/A with libre office writer

I am happily converting docx files to PDF via the command line (controlled via C# process calls) out of my service.
Unfortunately I could not find any internet search results on how to set the options for the output PDF that the GUI offers me. I am specifically looking for generating PDF/A and tagged PDF via the command line.
Anyone ever done this and knows how to do that?
EDIT:
Obviously getting a PDF/A can be done by using unoconv instead.
On windows one would use the following command line in a checked out unoconv repository:
python.exe .\unoconv -f pdf -eSelectPdfVersion=1 C:\temp\libre\renderingtest.docx
I did not find further information on how to select other things (tagged PDF etc.) and where to get a complete list of the options that are available.
EDIT: It seems as one could try the different options in the GUI. The settings get saved to C:\Users\<userName>\AppData\Roaming\LibreOffice\4\user\registrymodifications.xcu. Then one can look up the changed setting and provide that to unoconv as this:
python.exe .\unoconv -f pdf -eUseTaggedPDF=1 -eSelectPdfVersion=1 C:\temp\libre\renderingtest.docx
Still not sure if I am doing this correctly though.
The gotenberg project shows how that can be done using unocov.
$ curl --request POST 'http://localhost:3000/forms/libreoffice/convert' --form 'files=#"doc.docx"' --form 'nativePdfFormat="PDF/A-1a"' -o pdfA.pdf
Example PDF

Replacement PDFTK with ghostscript

We've just moved hosting to a new server and hosting company. After the moved we've noticed there's a function we've missed during testing. The function creates PDFs with pdftk:
exec('pdftk mypdf.pdf fill_form mydata.fdf output myoutput.pdf flatten', $output);
Problem is, there's no pdftk on the new server and we also couldn't get it. Only three PDF related tools are available.
PDF-Tools
HTMLDoc
Ghostscript
PDF-Tools and HTMLDoc doesn't work due to a lack of functions.
Is there a way to replace the command line we have at the moment we ghostscript or is there maybe a PHP Library i haven't found yet?

Handle Windows Open File dialog in Selenium

How can handle Window Open File dialog (set file path and import) using javascript (or some other way) in Selenium ?
If you are trying to upload a file, and the page in question uses the standard upload mechanisms provided by HTML, you can do this directly with Selenium itself. The standard HTML mechanism is with an <input type=‘file’> element. Once you’ve found that file upload element on the page, you can use element.sendKeys(“full/path/and/file/name/here”);. This is documented in Step 10 of the algorithm for the Element Send Keys command of the W3C WebDriver Specification, and is used in several file upload tests in the Selenium project’s test code (example).
//set file path
driver.findelelment(By.Xpath("//input[contains(#type,'file')]")).SendKeys(UploadFilePath);

Using Firefox HTML source viewer in VB.NET?

I want to view the HTML source of a web page, I've using ICSharpCode.TextEditor, Scintilla,... and they're all good. But, I have missed Firefox HTML source viewer.
I wonder if I can use Mozilla ActiveX Control to open the source viewer or is there a command line argument that make Firefox open it? Thanks!
You can do that from the command line like:
$> firefox view-source:http://stackoverflow.com
Or you can put something like this in the URL bar: "view-source:http://stackoverflow.com"
If you happen to want to open it in a new window:
$> firefox -new-window view-source:http://stackoverflow.com
There is a reference at mozillazine.org.