cp79shark / Shark.PdfConvert

Simple .NET Core wrapper for WkHTMLToPDF tool.
MIT License
33 stars 13 forks source link

Handle multiple pages #4

Closed N30NF15H closed 6 years ago

N30NF15H commented 6 years ago

Library has worked well for me so far, is there any plan to support multiple urls for a combination into a single PDF?

I've been using the following method which requires some specific ordering of parameters to get the required outcome for multiple web pages.

var config = new Shark.PdfConvert.PdfConversionSettings { Title = "Combined PDF", ContentUrl = "thirdurlrequired" //Will render as last pages in PDF }

var customArgs = new List(); customArgs.Add("--javascript-delay 1000"); customArgs.Add("--print-media-type"); customArgs.Add(string.Format("page \"{0}\" ", "firsturlrequired")); //Additional pages must come as last args, first url will render as first doc etc customArgs.Add(string.Format("page \"{0}\" ", "secondurlrequired")); config.CustomWkHtmlArgs = string.Join(" ", customArgs);

cp79shark commented 6 years ago

I added a ContentUrls option to PdfConversionSettings and a quick test for it. Seems to work. You can pull from source if you want to try it right away. I'll posted an updated NuGet package and it should be visible in a little while.

N30NF15H commented 6 years ago

Dude that was fast, appreciate it. Just gave it a test, getting an error about assignment only. Had a look at the property and it only has a get function, am I assigning it incorrectly?

public ICollection ContentUrls { get; }

cp79shark commented 6 years ago

No problem, needed a quick distraction from the day job.

See Sample 6 on the main page. It's a collection.

settings.ContentUrls.Add(your_url); settings.ContentUrls.Add(your_other_url);

or if you're using Linq

settings.ContentUrls.AddRange(my_url_collection);

Anything else on this, then I can re-open.