dotnet / core

.NET news, announcements, release notes, and more!
https://dot.net
MIT License
21.03k stars 4.9k forks source link

Pdf generation and manipulation library in Net Core 2 with permissive license #888

Closed guylando closed 7 years ago

guylando commented 7 years ago

The ITextSharp library has the AGPL license which is problematic for commercial use. The pdfsharp library does not have a maintained support for net core yet: https://github.com/empira/PDFsharp/issues/6

Are there any plans to build some pdf handling package by the core team or by the net foundation team?

Anybody is aware of some pdf manipulation library in net core 2 with permissive license for commercial use?

This is currently a major issue for our company which prevents us converting our projects to netcoreapp2.0 and forces us to keep compiling for net461.

richlander commented 7 years ago

We don't have any plans to provide a PDF library. I'm also not aware of one to recommend. Hopefully the community will work more of PDFSharp.

aqibgatoo commented 6 years ago

@guylando though late to the party but here is a good one for pdf generation Rotativa .NetCore

Phyrom commented 6 years ago

@aqibgatoo, can we convert a .doc file to pdf using Rotativ .NetCore?

aqibgatoo commented 6 years ago

@Phyrom i don't think so . You can generate images and pdf files from it. The pdf generator that i ended using up is a slighlty modifed running version of it with the package reference as. <PackageReference Include="RotativaCore" Version="2.1.1" />

guylando commented 6 years ago

@aqibgatoo we are looking to generate a pdf document describing a list of objects (a page for each object) including inserting text, images, styling, bullets. Rotative can be used for that? (basically export objects to pdf)

aqibgatoo commented 6 years ago

@guylando yes, it has different ActionResults available which you can easily use. For the example below you have to just design your view and pass the model accordingly.

public ActionResult TestViewWithModel(string id)
{
    var model = new TestViewModel {DocTitle = id, DocContent = "This is a test"};
    return new ViewAsPdf(model);
}

link to the one that i am using.

ValentinaNelson commented 6 years ago

hey , you can try zetpdf.com.. By using it you can edit , view and manipulate PDF easily.

jnm2 commented 5 years ago

I'm just starting to look into this myself, and it looks like the SkiaSharp library can generate PDFs.

https://docs.microsoft.com/en-us/dotnet/api/SkiaSharp.SKDocument.CreatePdf https://www.nuget.org/packages/SkiaSharp https://github.com/mono/SkiaSharp

guylando commented 5 years ago

@jnm2 the pdf abilities of SkiaSharp as far as I understand are more for exporting images into pdf and not for normal pdf textual documents creation. And the documentation and examples online are very poor. It is not made for pdf's and do not provide the desired abilities as good as libraries like pdfsharp which specialize in pdf.

jnm2 commented 5 years ago

@guylando I'm getting nice vectors and text out of it with a simple sample. This is what I expected because the drawing commands provide the information to generate the PDF properly.

I'm sure Skia does some advanced things that aren't representable in a PDF except as raster graphics. The documentation for the dpi parameter of CreatePdf says, "The DPI (pixels-per-inch) at which features without native PDF support will be rasterized."

Found https://skia.org/dev/design/pdftheory which might also help.

guylando commented 5 years ago

@jnm2 It might be possible but I mean we try to avoid using things which we will be of the few who use it for the use-case and will have a lot of overhead over using some popular library for the use-case and I get the feeling that SkiaSharp is not popular for this use case. The basic google search shows that the pdf related code of SkiaSharp is mostly dealing with drawing on canvas. So yes you can draw text on canvas however that is far from the simple methods such as "AddPage" available in pdfsharp if we want to create a multi page pdf export of some data. I can also write pdf generator myself in C if I put enough time into it but that is not the goal :) So we are looking not only at the fact of whether it is possible or not.

jnm2 commented 5 years ago

@guylando SkiaSharp has BeginPage/EndPage and lets you set PDF metadata. It's pretty high level, nothing like if you wrote a PDF generator yourself. I do understand that it's not a PDF-centric library; we still need something that can manipulate PDFs. But for folks looking to generate, this may be one of the easiest options depending on your use cas.

guylando commented 5 years ago

@jnm2 Thanks, I will check this out when I get to the conversion to net core (which will be a must when asp.net 3 is out since it only supports net core from what I understood). The apis we use in pdfsharp are:

  1. Set document title
  2. AddPage
  3. AddSection
  4. AddParagraph including the ability to declare space after and space before (in cm or similar)
  5. AddImage
  6. AddText
  7. fonts, font sizes, margins
  8. DrawString
  9. GetTextHeight
guylando commented 5 years ago

@jnm2 Note however that pdfsharp already has some net standard ports (and even a claim that it works as is in net core 2.2) as written in the final comments here https://github.com/empira/PDFsharp/issues/6 but they are not official (unless the claim it works with net core 2.2 is true) and not as well supported as SkiaSharp which turns SkiaSharp into a better option probably