Use macro to click "Save as PDF" for online location

Q A. shared this question 6 months ago
Answered

Hi all,


I got a quite big project (9000+ references) which contains online locations. I need all of those as downloaded PDF locations which is not practical to be done by hand.

Workflow would be: select reference, show preview of location, click "Save as PDF".

Thus I created a macro to do this for me, but I am stuck at the "Save as PDF" part. I did explore quite a lot of options already but with no real API (is there any?) and only low C# knowledge I am currently lost.

I attached my current efforts -- can anyone help me to automate this? Any hints appreciated!


Cheers,

Q.

(edit: Some more meta information: Citavi 6.3.0.0, Win7, Cloud Project)

Comments (5)

photo
1

Dear Q.,

Thank you very much for your message.

My colleague who creates macros for Citavi, will be back in the office on Monday.

Then, he will have a look at your file.

Thank you for your patience!

Kind regards,

Jana

photo
1

Hi Q,

the Citavi method that triggers the HTML to PDF conversion can't be called from a macro. However, it should be easy implementing a similar procedure in a macro using a web service that provides HTML to PDF conversion, e.g. https://www.html2pdfrocket.com/ (this is not a recommendation, just one of many alternatives).

You can get the URI in string format for the reference like so:

if (location.LocationType == LocationType.ElectronicAddress)
{
	if (location.Address.LinkedResourceType == LinkedResourceType.RemoteUri)
	{
		string uriString = location.Address.UriString;
		// pass uriString to API (e.g. with a WebRequest) and save the result to a file
	}
Once you have the file, you'll need to create a new Location for the reference in Citavi and add it to that reference.

Does this help?

Best regards

Sebastian

photo
1

Hi Sebastian,


thanks for your pointer. I did eventually think of this way but was unable to include required dlls int the macro editor. From what I can see I would need Microsoft.AspNet.WebApi.Core:

https://www.nuget.org/packages/Microsoft.AspNet.WebApi.Core/

But with the Citavi Macro editor not being a full IDE, all my efforts to add the DLL version via Tools->References did not succeed. Adding some code as described by html2pdfrocet:


string apiKey = "ABCD-1234";
string value = "http://www.google.com";; // a url starting with http or an HTML string
using (var client = new WebClient())
{
    NameValueCollection options = new NameValueCollection();
    options.Add("apikey", apiKey);
    options.Add("value", value);
	byte[] result = client.UploadValues("http://api.html2pdfrocket.com/pdf";, options);

    System.IO.File.WriteAllBytes(System.Web.HttpContext.Current.Server.MapPath(Path.Combine("~/", @"c:\temp\mypdf.pdf")), result);
}
will result in errors pointing out that the 'HttpContext' namespace is missing in 'System.Web', even with the correct DLLs references added. Is there any other way to add dependencies/dlls? Am I doing something completely wrong here?

Best,

Q

photo
1

Hi, Q

There are two assembly references missing, one for the NameValueCollection and one for writing the output to disk:

using System.Collections.Specialized;
using System.IO; 

As there is no server, it suffices to write the output like this:

System.IO.File.WriteAllBytes(@"C:\heres\my\folder\", result);

Best regards

Sebastian

photo
photo
1

Dear Sebastian,

thanks for the help. I managed to get it working. For future reference I attached my current version of the macro for whoever needs it some day.


But a fair warning: DO NOT simply apply this macro. Read and adapt to your needs first.

Cheers

Q.

photo
1

Dear Q

Thanks for sharing this with us,

Best regards

Sebastian