Save HTML as PDF
Jackson, Adam
Hi,
xpa 2.5
Is there a way of programmatically saving an HTML page as PDF? I have a pdf document that has links to other documents in it. I have those links stored in data so I want to produce a list of hyperlinks with friendly names and merge it with the main document. The references to the linked documents in the main document cannot be hyperlinks so I have gone down the route of generating HTML document of hyperlinks and then using COM to save it as a PDF. If I do it manually it all works but my COM commands are not quite right. It generates a PDF file with the correct name and extension but I get errors when I try to open it.
Open word Get Documents object Using Documents object’s Open method I open HTML file – I get a convert dialogue which I need to get rid of programmatically but I also get this when I do it manually SaveAs2 – I set FileName argument as required. I have also played around with setting file format argument. I have tried wdFormatPDF and I have tried to use various trick with File Converters and FileConverter objects but pretty much get same result. Close document Quit Word
I think the file format argument on the SaveAs method is probably the key to this but I am not sure what to put in it.
Has anyone managed to do something similar or can see what I might be doing wrong?
TIA
Adam
The contents of this e-mail are confidential and for the exclusive use of the intended recipient. If you are not the intended recipient you should not read, copy, retransmit or disclose its contents. If you have received this email in error please delete it
from your system immediately and notify us either by email or telephone. The views expressed in this communication may not necessarily be the views held by McLaren Racing Limited. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Craig Martin
You might have more success with an alternate approach using https://wkhtmltopdf.org/index.html
If you use python, it's easy to script with the pdfkit library - I've seen c# examples but never implemented it that way but I bet you could build a few lines of c# snippets in Magic to do your thing.
COM programming is so late Nineties.
From: main@magicu-l.groups.io <main@magicu-l.groups.io> on behalf of Jackson, Adam <adam.jackson@...>
Sent: Friday, March 3, 2023 5:59 AM To: magicu-l@groups.io <magicu-l@groups.io> Subject: [magicu-l] Save HTML as PDF Hi,
xpa 2.5
Is there a way of programmatically saving an HTML page as PDF? I have a pdf document that has links to other documents in it. I have those links stored in data so I want to produce a list of hyperlinks with friendly names and merge it with the main document. The references to the linked documents in the main document cannot be hyperlinks so I have gone down the route of generating HTML document of hyperlinks and then using COM to save it as a PDF. If I do it manually it all works but my COM commands are not quite right. It generates a PDF file with the correct name and extension but I get errors when I try to open it.
Open word Get Documents object Using Documents object’s Open method I open HTML file – I get a convert dialogue which I need to get rid of programmatically but I also get this when I do it manually SaveAs2 – I set FileName argument as required. I have also played around with setting file format argument. I have tried wdFormatPDF and I have tried to use various trick with File Converters and FileConverter objects but pretty much get same result. Close document Quit Word
I think the file format argument on the SaveAs method is probably the key to this but I am not sure what to put in it.
Has anyone managed to do something similar or can see what I might be doing wrong?
TIA
Adam
The contents of this e-mail are confidential and for the exclusive use of the intended recipient. If you are not the intended recipient you should not read, copy, retransmit or disclose its contents. If you have received this email in error please delete it
from your system immediately and notify us either by email or telephone. The views expressed in this communication may not necessarily be the views held by McLaren Racing Limited. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- download from wkhtmltopdf (I downloaded the "7z Archive (XP/2003 or later)", and extracted it to "d:\temp\wkhtmltox"
- Make "D:\TEMP\wkhtmltox\bin" your current directory (cd D:\TEMP\wkhtmltox\bin) - Run: wkhtmltopdf.exe https://www.google.com google.pdf - See attached PDF. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Adrian Wick
If you have devexpress:
Easier to use c# than to use evaluate to do actions ... But it could also be done with evaluate.
Regards, A |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|