Is there a way to include external content (not images) in resulting PDF from HTML?

We are using Aspose Words for Java 15.7.0.0 and it doesn’t seem to load external content other than images in the resulting PDF file from HTML. We have tried using object, embed and iframe tags but it only seems to process them when the extension of the src or data attributes is an image. Is there a way to include external content like HTML or plain text in the resulting PDF file?

Thanks in advance

@jguijarro

We suggest you please try the latest version of Aspose.Words for Java 21.9 and let us know how it goes on your side. If you still face problem, please share the following resources here for testing:

  • Your input document.
  • Please attach the output file that shows the undesired behavior.
  • Please attach the expected output file that shows the desired behavior.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Thanks for your response Tahir. Unfortunately, we are not able to upgrade the library at this time. Could you please point to some resources that explain how to include external content that is not CSS or Images? I can’t seem to find any on the Internet, I’ve looked everywhere… Something similar to INCLUDETEXT or Altchunk in Word and iframes, objects and embed tags in HTML that would be processed from the library itself without adding any code, just by processing the input document and include the result in the output PDF.

@jguijarro

Please note that Aspose.Words mimics the behavior of MS Word. Aspose.Words does support INCLUDETEXT field. You can use it in your document.

It would be great if you please share the requested resources here for our reference. We will then provide you more information about your query.

Dear Tahir,

We are also processing HTML as part of the input documents. A sample input HTML document would be the following:

<html>
<body>
<iframe src="https://www.google.com/"></iframe>
</body>
</html>

We would expect to see the contents of google in the resulting PDF but they aren’t there. It only works when the source of the content is an image (i.e src="https://whatever.com/test.png"). I have also tried with object and embed without luck.

Could you please help us on this?

Thanks in advance!

@jguijarro

Please note that Aspose.Words mimics the behavior of MS Word. If you perform the same scenario using MS Word, you will get the same output.

Instead of iframe, we suggest you please insert the bookmark as shown below in your HTML document.

<html>
<body>
<p><a name=iframe></a>&nbsp;</p>
</body>
</html>

You can insert this HTML into empty or any MS Word document, move the cursor to the bookmark and insert the desired content. E.g. you can load the content of ‘https://www.google.com/’ into Aspose.Words’ DOM (document) and insert it to desired location. Following code example shows how to achieve it. Hope this helps you.

Document doc = new Document(MyDir + "bookmark.htm");
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveToBookmark("iframe");
             
Document google = new Document(@"https://www.google.com/");
builder.InsertDocument(google, ImportFormatMode.KeepSourceFormatting);

doc.Save(MyDir + "21.9.docx");

I have simplified the code we are using to convert documents to PDF so you can replicate it in your environment:

import com.aspose.words.Document;

public class ConvertToPdf
{
    public static void main(String args[]) {
        try {
            Document doc = new Document(args[0]);
            doc.save("./Document.pdf");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

We are processing HTML documents apart from Word documents, so the previous response doesn’t apply I think. In this setup iframes are not loading content when being processed by Aspose.Words.

Thanks in advance

@jguijarro

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word and HTML documents.
  • Please attach the output file that shows the undesired behavior.
  • Please attach the expected output file that shows the desired behavior.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.