Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Export Images to PDF

I have a project that has to export images to PDF. Images and text alike are needed to be exported into pdf. is there a way to do this by using silverPDF.dll and PdfReader?

Code here.

 private void btnOutlook_Click(object sender, System.Windows.RoutedEventArgs e)
    {
        XBrush xbrush;
        SaveFileDialog savePDF = new SaveFileDialog();
        savePDF.Filter = "PDF file format | *.pdf";
        if (savePDF.ShowDialog() == true)
        {
            PdfDocument document = new PdfDocument();
            PdfPage page = document.AddPage();
            XGraphics gfx = XGraphics.FromPdfPage(page);
            XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);

            XFont font = new XFont("Huxtable", 20, XFontStyle.Bold, options);

            for (int x = 0; x < 10; x++)
            {
                if (x % 2 == 0)
                {
                    xbrush = XBrushes.Red;
                }
                else
                    xbrush = XBrushes.Black;
                gfx.DrawString(string.Format("{0}", stringArray[x]), font, xbrush, new XRect(0, (x * 20), page.Width, page.Height), XStringFormats.TopLeft);
            }

            document.Save(savePDF.OpenFile());
        }

    }

where in this code can I insert an Image that inserts it to pdf? Is there any way? Thanks for all replies.

like image 938
Nathan Avatar asked Nov 13 '22 11:11

Nathan


1 Answers

Does it need to be SilverPDF? As Iv'e done something similar before at my previous employer using the iTextSharp library (otherwise I would've pasted sample code)

iTextSharp-Working-with-images

Download Link

like image 81
Rohan Büchner Avatar answered Nov 16 '22 04:11

Rohan Büchner