Open StefH opened 4 years ago
That's an easy one. Like the Readme says, PdfSharpCore uses SixLabors ImageSharp for image handling. And that only supports the image formats stated here. And NB: PDF is not an image format at all.
@JHBonarius: True, but that is not entirely correct. PDF basically is a vector-graphics format. For example, you can open a svg in chrome, and save it as pdf. Then you can zoom-in ad infinitum, without losss of quality.
But what certainly is impossible is an automatic conversion from raster graphics to vector graphics. However, you could actually automatically convert a vector-graphic into a raster-graphic. Actually, using AI or other sophisticated algorithms, you might be able to convert a raster graphic into a vector graphics. But both directions certainly aren't supported by ImageSharp.
@StefH: You can actually embed a PDF into a PDF, but not as XImage. You can use XPdfForm to load the pdf, then gfx.DrawImage(form, PdfSettings.VwsDrawingSettings.rectForm) to draw it. VB.NET example (using PdfSharp - change Namespace):
Using form As PdfSharp.Drawing.XPdfForm = PdfSharp.Drawing.XPdfForm.FromStream(ms)
form.PageNumber = 1
' Max-Width
' Max-Height
Dim ActualDrawingSize As System.Drawing.Size = GetDrawingBoundingSize(form, PdfSettings.VwsDrawingSettings.Width, PdfSettings.VwsDrawingSettings.Height)
' Draw the page identified by the page number like an image
PdfSettings.VwsDrawingSettings.rectForm = New PdfSharp.Drawing.XRect(PdfSettings.VwsDrawingSettings.X, PdfSettings.VwsDrawingSettings.Y, ActualDrawingSize.Width, ActualDrawingSize.Height)
' Max-Width
' Max-Height
PdfSettings.VwsDrawingSettings.rectFormMaxSize = New PdfSharp.Drawing.XRect(PdfSettings.VwsDrawingSettings.X, PdfSettings.VwsDrawingSettings.Y, PdfSettings.VwsDrawingSettings.Width, PdfSettings.VwsDrawingSettings.Height)
' Centering
PdfSettings.VwsDrawingSettings.rectForm.X = PdfSettings.VwsDrawingSettings.rectForm.X + (PdfSettings.VwsDrawingSettings.rectFormMaxSize.Width - PdfSettings.VwsDrawingSettings.rectForm.Width) / 2.0
PdfSettings.VwsDrawingSettings.rectForm.Y = PdfSettings.VwsDrawingSettings.rectForm.Y + (PdfSettings.VwsDrawingSettings.rectFormMaxSize.Height - PdfSettings.VwsDrawingSettings.rectForm.Height) / 2.0
gfx.DrawImage(form, PdfSettings.VwsDrawingSettings.rectForm)
PdfSettings.Outline.[Do](gfx, PdfSettings.VwsDrawingSettings.rectForm)
PdfSettings.Outline.[Do](gfx, PdfSettings.VwsDrawingSettings.rectFormMaxSize, PdfSharp.Drawing.XColors.HotPink)
PdfSettings.VwsDrawingSettings.Outline(gfx, PdfSettings.VwsDrawingSettings.rectFormMaxSize)
End Using ' XPdfForm form
Code:
-->