Comments (13)
If I check the fixes in 0.12.6 I can see that TOC is listed, perhaps 0.12.5 isn't properly working with TOC? It's always best to test your HTML with the native wkhtmltopdf command line tool to see if the issue is with wkhtmltopdf, or with this wrapper. That being said, I've tested to upgrade to 0.12.6, but I haven't had a chance to test it, feel free to try it out if you can, it's in this branch: test-0.12.6
. You'll find the NuGet package here: https://www.nuget.org/packages/Haukcode.WkHtmlToPdfDotNet/1.3.0-test-0.12.6
I'm not sure why you load the managed library directly in your code, have you looked at the WebServer sample in this repo?
from wkhtmltopdf-dotnet.
Hmm, thanks for the details. Unfortunately I don't know much about wkhtmltopdf itself, I just forked an existing wrapper and updated it and made it so it includes all binaries. I'm not sure I'm able to figure out a solution for this, we may need to depend on the community to see if someone can figure out what's going on. Maybe you can add a test method to the samples in this repo in a PR so it's easy for someone to test the scenario?
from wkhtmltopdf-dotnet.
Ah, good catch. I've changed the unit test to check the first generated file as well. Obviously that doesn't solve the actual problem, but at least we have a way to confirm.
from wkhtmltopdf-dotnet.
Does it work with other types of pages?
from wkhtmltopdf-dotnet.
Each of pages is worked as well, but table of content is exceptioned.
I ran my code on console app, it's good. But with ASP.NET (RESTful API), the issue is happened.
My config code for pdf configuration:
public static void ConfigPdfLibrary(this IServiceCollection services)
{
string fileName = GetPdfLibraryFileName();
CustomAssemblyLoadContext context = new CustomAssemblyLoadContext();
context.LoadUnmanagedLibrary(fileName);
ITools pdfTools = new PdfTools();
IConverter synchronizedConverter = new SynchronizedConverter(pdfTools);
services.AddSingleton<IConverter>(synchronizedConverter);
}
from wkhtmltopdf-dotnet.
Thank you for your updated.
I've updated my code and upgraded to new version. But the issue is still not resolved.
public void ConfigureServices(IServiceCollection services)
{
services.AddSingleton(typeof(IConverter), new SynchronizedConverter(new PdfTools()));
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
}
ConvertController.cs
[HttpGet]
public IActionResult Get()
{
var tableOfContents = new TableOfContentsSettings() { };
var doc = new HtmlToPdfDocument()
{
GlobalSettings = {
PaperSize = PaperKind.A4,
Orientation = Orientation.Landscape,
},
Objects = {
tableOfContents,
new ObjectSettings()
{
Page = "template.html",
}
}
};
byte[] pdf = _converter.Convert(doc);
return new FileContentResult(pdf, "application/pdf");
}
[Serializable]
public class TableOfContentsSettings : ObjectSettings
{
public TableOfContentsSettings()
{
ProduceTableOfContents = true;
UseDottedLines = true;
}
[WkHtml("isTableOfContent")]
internal bool ProduceTableOfContents { get; set; }
[WkHtml("toc.useDottedLines")]
public bool UseDottedLines { get; set; }
}
- First time:
- Next time
first_time.pdf
next_time.pdf
from wkhtmltopdf-dotnet.
Hi HakanL,
Thank you for your updated. I've created unit test project and test method to convert pdf file.
It's included table of contents settings. Pull request at: https://github.com/HakanL/WkHtmlToPdf-DotNet/pull/23
Test method:
[TestMethod]
public void ConvertToPdfTest()
{
for (int i = 1; i < 3; i++)
{
var pdf = GetPdf();
File.WriteAllBytes($"Test {i}.pdf", pdf);
Assert.IsNotNull(pdf);
}
}
private byte[] GetPdf(string templatePage = "")
{
if (string.IsNullOrEmpty(templatePage))
{
templatePage = "template.html";
}
var globalSettings = new GlobalSettings()
{
PaperSize = PaperKind.A4,
Orientation = Orientation.Portrait
};
var templateSettings = new ObjectSettings()
{
Page = templatePage,
};
var tableOfContentSettings = new TableOfContentsSettings()
{
IsTableOfContent = true
};
var doc = new HtmlToPdfDocument()
{
GlobalSettings = globalSettings,
Objects = { tableOfContentSettings, templateSettings }
};
byte[] pdf = _converter.Convert(doc);
return pdf;
}
You can run this test method and compare pdf file results.
from wkhtmltopdf-dotnet.
I merged in the PR and also did some refactoring in the code. The issue is that the unit test runs fine here. Can you test with the latest code in master
to confirm if it works for you as well?
from wkhtmltopdf-dotnet.
Thank HakanL, I can run your refactor code as well. But the issue with table of contents is not resolved.
I'm investigating it and try to find out the solution.
[TestMethod]
public void RepeatTableOfContents()
{
for (int i = 0; i < 2; i++)
{
byte[] pdf = GetPdfWithTableOfContents();
Assert.IsNotNull(pdf);
Assert.IsTrue(pdf.Length > 10000);
WriteToPdfFile(pdf);
}
}
private void WriteToPdfFile(byte[] pdf, string fileName = "")
{
if (!Directory.Exists("Files"))
{
Directory.CreateDirectory("Files");
}
if (string.IsNullOrEmpty(fileName))
{
fileName = $"{DateTime.UtcNow:yyyyMMddHHmmss}.pdf";
}
using (var stream = new FileStream(Path.Combine("Files", fileName), FileMode.Create))
{
stream.Write(pdf, 0, pdf.Length);
}
}
The table of contents page in file 2 still is blank
File1: 20201008023350.pdf
File2: 20201008023351.pdf
from wkhtmltopdf-dotnet.
from wkhtmltopdf-dotnet.
I'm using VS on Windows too. The unit test is not failed but the pdf file was not corrected.
from wkhtmltopdf-dotnet.
I attempted a refactoring of the converter to see if it would make a difference, but it doesn't. So if I run all unit tests then it's successful, but if I run just the repeat unit test then it fails. I tried to add a sleep just to see if something weird was going on, but it didn't help. I'm not sure what's going on here, very odd.
from wkhtmltopdf-dotnet.
I've checked the code and find out the root-cause. You can see the result in below capture
Green is result for all unit test in ConvertTest class
Red is result when i run RepeatTableOfContents test method only
When you run all of unit tests, the ConvertToPdf test method will be run in the first time. After that, it can't generate TOC in the next time (file size 13kb).
If we just run RepeatTableOfContents method only, it can generate TOC in the first time. The pdf file size is 23KB, after that it can't generate TOC again => the file size will be 13KB
from wkhtmltopdf-dotnet.
Related Issues (20)
- Table of content styling HOT 2
- Exclude runtimes folder from publish HOT 2
- libwkhtmltox using produceForms html form to pdf form does not work HOT 2
- Local file access HOT 1
- Gmail is detecting pdf generated by WkHtmlToPdf-DotNet as malware HOT 1
- creating pdf with .net6 in aws lambda HOT 4
- Not able to generate report once deployed to Kubernates HOT 1
- Execution time increases under load HOT 1
- I didn't use dependency injection. Using static creation would cause the thread to get stuck and new requests to keep getting stuck HOT 22
- % in the href attribute are still encoded to %25 HOT 2
- Not reading settings on alpine HOT 2
- HTML tags removed HOT 3
- Reporting a vulnerability HOT 1
- In Linux CentOS 7, there was an error: Unable to load native library. The platform may be missing native dependencies (libjpeg62, etc). Or the current platform is not supported. HOT 3
- Memory overflow HOT 2
- The wkhtmltopdf project that is used, is no longer maintained HOT 3
- Display flex is not working HOT 1
- Unable to load native library - Windows 10/11 HOT 16
- Add ability to process pdf generation on multiple threads HOT 1
- How can I set html code with css in header HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from wkhtmltopdf-dotnet.