Download Webpage as PDF in as Few Steps as Possible

I understand that this has been asked before, but I’d like to know if its possible to save a webpage as PDF is as few steps as possible.

The whole Ctrl+P → Save as PDF → Save → Wait for Save as Dialog Box → Enter FilePath ->Save → Wait for Download takes anywhere from 15-25 seconds.

The styling is not important, so If I can just get the HTML and convert that into PDF that would work.

I understand that there is a custom activity that converts HTML to PDF, but that activity only works with Windows - Legacy.

Any help/insight into optimizing this process would be most appreciated - thanks in advance!

Kind Regards,
Ashwin A.K

TheCodingTheory

@ashwin.ashok

Can you try using http request and take the output ans save or give a pdf file in the response file fied and check if that works

Cheers

Hi @Anil_G ,

Thank you for your response - I’ve tried that before and it doesn’t work.
Unfortunately we can’t directly convert HTML to PDF like that.

I’d appreciate any other idea that has actually been tested, thanks!

Kind Regards,
Ashwin A.K

Try [ctrl]+[shift]+p instead of [ctrl]+p. A quicker and easier approach to your pdf printer.
If the pdf printer is your default printer all you have to do is bash print and enter the filename + path

Hi @ashwin.ashok

Try following the below steps in the workflow. Hope it may help you.

Sequence4.xaml (16.6 KB)

Regards,

1 Like

For Prototype:

And UiPath.DocumentUnderstanding.Digitizer

1 Like

Hi @ashwin.ashok

You can use the UiPath.PDF.Activities package, which provides activities for working with PDF files. This package includes the “Convert HTML to PDF” activity that allows you to convert HTML content to a PDF file. This activity works on both Windows and non-Windows platforms.

Thanks!!

This is interesting, Ill have a look and let you know if it helps out.
Thanks!

Kind Regards,
Ashwin A.K

Hi @Nitya1 ,

Thank you for your response, are you sure that this activity is present in the UiPath.PDF.Activities package or am I looking in the wrong area?
image

A screenshot would be really helpful, thanks!

Kind Regards,
AshwinA.K

@ashwin.ashok

I tried like this and giving the response properly please check this

first save the file response as html and then open the file using work document and save as pdf

Hope this helps

cheers

Sorry for the late response guys @ppr @Anil_G @nitya.tomar .
I managed to find a neat workaround which involves Chrome Command Switches.

--headless --disable-gpu --print-to-pdf="PDFFilePath" "file://HTMLFilePath"

This is a switch which converts HTML to PDF using Chrome in the background.

While there is a switch which enables us to directly download webpages as PDF, if the webpage in question requires authentication then we can’t convert it to PDF. It will retrieve and convert the login page to PDF instead - which is not what we want.

Also, we can’t pass headers so that is a bummer as well, so the workaround I employed was to create an HTML template, store it in Storage Bucket and pass it into the workflow as an in Argument which consisted of the header and footer with a placeholder for the DOM content.

The bot would navigate to each page, fetch the required sections of the DOM using either Find Children(Classic) or Get Attribute(Modern), replace it with the placeholder present in the HTML template and use the Chrome Command Switch to convert HTML to PDF:

image

There’s a bit more to it(maintaining CSS folder) but the approach is robust, works super fast with a 100% accuracy rate.
I hope you find this resourceful and that it will help you out one day!

Kind Regards,
Ashwin A.K

2 Likes

Dim filePath As String = in_htmlFile
Dim url As String = “file:///” & System.Uri.EscapeUriString(filePath.Replace(“”, “/”))
Console.WriteLine(url)
'Set the chrome.exe file path
Dim chromePath As String = “C:\Program Files (x86)\Google\Chrome\Application\chrome.exe”

If Not File.Exists(chromePath) Then
Dim userFolder As String = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)
chromePath = userFolder+“\AppData\Local\Google\Chrome\Application\chrome.exe”
End If
If Not File.Exists(chromePath) Then
Throw New Exception(“Unable to locate Chrome.exe”)
End If
Console.WriteLine(“saving”)
Using p As New Process()
p.StartInfo.FileName = chromePath
p.StartInfo.Arguments = “–headless --disable-gpu " &
“–run-all-compositor-stages-before-draw --print-to-pdf=””" & in_pdfFilePath & “”" “”" & url & “”“”
p.Start()
p.WaitForExit()
End Using

I just did it in Edge and it took about 10 seconds.