Skip to main content
Known Participant
September 12, 2022
Question

Include Image in Adobe PDF Services API

  • September 12, 2022
  • 1 reply
  • 701 views

Hi 

How to Include Image while downloading as pdf using Adobe PDF Services API.I'm using .NET SDK.

Can someone help me to overcome this ? I'm getting image as empty eventhough its present in the repective folder.

 

    This topic has been closed for replies.

    1 reply

    Raymond Camden
    Community Manager
    Community Manager
    September 12, 2022

    Hi, I need a lot more detail to help you out. Can you explain how you are using the PDF Services API? I assume you are generating a PDF from something, but you need to provide more information. 

    Known Participant
    September 13, 2022

    Hi Im using .net sdk . Here I'm trying to export pdf by generating my own HTML by clicking the Export button, Iam able to export the pdf with data which is genearted by HTML.Everything works perfect but Im not able to add imags in the pdf

    Credentials credentials = Credentials.ServiceAccountCredentialsBuilder().WithClientId("Client Id")
    .WithClientSecret("Secret") // using Environmental variables from azure key vault
    .WithPrivateKey("PrivateKey")
    .WithOrganizationId("orgId")
    .WithAccountId("AccountId")
    .Build();
    //Create an ExecutionContext using credentials and create a new operation instance.
    Adobe.PDFServicesSDK.ExecutionContext executionContext = Adobe.PDFServicesSDK.ExecutionContext.Create(credentials);
    CreatePDFOperation htmlToPDFOperation = CreatePDFOperation.CreateNew();

    string ExportData = ExportDatatableToHtml(dssample.Tables[0]);
    byte[] exportArray = Encoding.UTF8.GetBytes(ExportData);


    MemoryStream stream = new MemoryStream(exportArray);

    htmlToPDFOperation.SetInput(FileRef.CreateFromStream(stream, CreatePDFOperation.SupportedSourceFormat.HTML.GetMediaType()));

    SetCustomOptions(htmlToPDFOperation);

    // Execute the operation.
    var result = htmlToPDFOperation.Execute(executionContext);
    using (MemoryStream outputStream = new MemoryStream())
    {

    result.SaveAs(outputStream);

    return File(outputStream.ToArray(),
    "application/pdf", "Sample");
    }

    ExportDatatableToHtml
    =================================

    StringBuilder strHTMLBuilder = new StringBuilder();
    strHTMLBuilder.Append("<html>");
    strHTMLBuilder.Append("<head>");
    strHTMLBuilder.Append("</head>");
    strHTMLBuilder.Append("<body>");

    strHTMLBuilder.Append("<table width='100%' align='right'><tr><td align='right'><img src='"+ sPath + "/assets/mylogo.png' ></img></td></tr></table>");

    strHTMLBuilder.Append("<body>");
    strHTMLBuilder.Append("</head>");
    strHTMLBuilder.Append("<head>");
    strHTMLBuilder.Append("<html>");

    Raymond Camden
    Community Manager
    Community Manager
    September 13, 2022

    According to the docs, when you do HTML to PDF, you send in a zip of the HTML + asserts. It's hard to read your code above, but you appear to be sending just an HTML string. See the .Net example here - https://developer.adobe.com/document-services/docs/overview/pdf-services-api/howtos/create-pdf/#create-a-pdf-from-static-html