I want show image in pdf from image url.
I Have image url
I want show image in pdf from image url.
I Have image url
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal YelveRank #178 · 13.6K reputationPosted Jan 19, 2023, 8:51 AM EST
Add add these 2 dll in solution.
Itextsharp.dll
itextsharp.pdfa.dll
add namespaces ----
using iTextSharp.text; using iTextSharp.text.pdf; using iTextSharp.text.html; using iTextSharp.text.html.simpleparser;protected void btnCreatePDF_Click(object sender, EventArgs e) { Document doc = new Document(PageSize.A4, 10f, 10f, 100f, 0f); string pdfFilePath = Server.MapPath(".") + "/PDFFiles"; PdfWriter writer = PdfAWriter.GetInstance(doc, new FileStream(pdfFilePath + "/Default.pdf", FileMode.Create)); doc.Open(); try { Paragraph paragraph = new Paragraph("Getting Started ITextSharp."); string imageURL = Server.MapPath(".") + "/image2.jpg"; iTextSharp.text.Image jpg = iTextSharp.text.Image.GetInstance(imageURL); //Resize image depend upon your need jpg.ScaleToFit(140f, 120f); //Give space before image jpg.SpacingBefore = 10f; //Give some space after the image jpg.SpacingAfter = 1f; jpg.Alignment = Element.ALIGN_LEFT; doc.Add(paragraph); doc.Add(jpg); } catch (Exception ex) { } finally { doc.Close(); } }Vishal JoshiRank #377 · 6.7K reputationPosted Jan 18, 2023, 12:25 AM EST
Hello Sandeep
Please check IronPDF nuget package.
Ref. https://ironpdf.com/examples/converting-a-url-to-a-pdf/
Thanks
Naimish MakwanaRank #324 · 7.7K reputationPosted Jan 18, 2023, 12:30 AM EST
Hello Sandeep,
As @Vishal suggested, we can do it with IronPDF.
Please refer below link which is giving brief use of IronPDF with example:
https://ironpdf.com/blog/using-ironpdf/how-to-add-images-in-pdf-using-csharp/
Thanks
Marvin ReidRank #1,963 · 746 reputationPosted Jan 19, 2023, 11:15 AM EST
You can add the image from the URL into a PDF using the DocumentEditor. Here is the documentation and code that highlights this.
addImage = () => { // Load file //Allows the user to input an image of their choosing for the specific file types allowed at the cursor location var input = document.createElement('input'); input.type = 'file'; input.style.display = 'none'; input.accept = '.png, .docx, .doc, .jpg, .pdf'; input.onchange = function (e) { var files = input.files; if (!files || !files.length) return; file = files[0]; var url = URL.createObjectURL(file); editor.engine.images.insertImage(url); }; input.click(); } exportAsPdf = () => { //exports the current document for saving var promise = editor.document.toFile("untitled", lt.Document.Writer.DocumentFormat.pdf); var err = null; promise.then(function (name: string) { }); promise.catch(function (err: string) { alert("There was an issue exporting the document. " + err); }); }https://www.leadtools.com/help/sdk/v22/dh/javascript/de/imageengine.html
https://www.leadtools.com/help/sdk/tutorials/html5-js-import-edit-save-documents-with-the-document-editor.html
Laxmidhar SahooRank #383 · 6.6K reputationPosted Jan 19, 2023, 12:08 PM EST
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using SelectPdf; namespace SelectPdf.Samples { public partial class convert_url_to_pdf : System.Web.UI.Page { protected void BtnCreatePdf_Click(object sender, EventArgs e) { // read parameters from the webpage string url = TxtUrl.Text; string pdf_page_size = DdlPageSize.SelectedValue; PdfPageSize pageSize = (PdfPageSize)Enum.Parse(typeof(PdfPageSize), pdf_page_size, true); string pdf_orientation = DdlPageOrientation.SelectedValue; PdfPageOrientation pdfOrientation = (PdfPageOrientation)Enum.Parse(typeof(PdfPageOrientation), pdf_orientation, true); int webPageWidth = 1024; try { webPageWidth = Convert.ToInt32(TxtWidth.Text); } catch { } int webPageHeight = 0; try { webPageHeight = Convert.ToInt32(TxtHeight.Text); } catch { } // instantiate a html to pdf converter object HtmlToPdf converter = new HtmlToPdf(); // set converter options converter.Options.PdfPageSize = pageSize; converter.Options.PdfPageOrientation = pdfOrientation; converter.Options.WebPageWidth = webPageWidth; converter.Options.WebPageHeight = webPageHeight; // create a new pdf document converting an url PdfDocument doc = converter.ConvertUrl(url); // save pdf document doc.Save(Response, false, "Sample.pdf"); // close pdf document doc.Close(); } } }