Free Support Forum - aspose.com

Convert from Doc to PDF is not included the image

I download the last version of Aspose.Words for evaluation. I used the Temporary license for testing. I have the issue with the document which has the image on it, the image is in png format.

Here is the code to embed the image:

private Aspose.Words.Document FillInImage(DataRow[] drMergeField,Aspose.Words.Document master)

{

string strValue;

Aspose.Words.DocumentBuilder db = new Aspose.Words.DocumentBuilder(master);

for (int i=0; i<drMergeField.Length; i++)

{

strValue = drMergeField[i]["FieldValue"].ToString();

if (strValue != "" && strValue != null && strValue.Length != 0)

{

//System.Drawing.Bitmap img = new Bitmap(strValue);

Image img = Image.FromFile(strValue);

//img = resizeImage(img, new Size(700, 580));

MemoryStream memStream = new MemoryStream();

img.Save(memStream, System.Drawing.Imaging.ImageFormat.Bmp);

db.MoveToBookmark(drMergeField[i]["FieldName"].ToString());

db.InsertImage(memStream);

memStream.Close();

master.Range.Bookmarks.Remove(drMergeField[i]["FieldName"].ToString());

}

}

return master;

}

And then in the Main, I save the master as PDF as follow:

//save to PDF

master.Save(p_SavePath, Aspose.Words.SaveFormat.Pdf);

master.Save(p_SavePath + ".doc", Aspose.Words.SaveFormat.Doc);

The issue is that the PDF did not have the image on it, but the doc save after that is correct with image.

I attached the original doc file, the image and also 2 results (pdf and doc).

And I also have another issue, I have big doc with some word bookmarks on it. In the code I will replace those bookmarks with space. Like above, the pdf is the original doc convert to pdf, the command after that convert to doc is correct with those bookmarks are cleared and replace with space. Here is the part of code which replace the bookmarks with space:

if (master.Range.Bookmarks[bookmarkName] != null)

{

master.Range.Bookmarks[bookmarkName].Text = mergeText;

master.Range.Bookmarks.Remove(bookmarkName);

}

Thanks.

Tom.

Hi there,

Thanks for your inquiry.

1. It sounds like page layout is being called sometime before you insert the image. This means the document is rendered and stored in memory. When the image is inserted it appears in the DOCX output as expected but since the layout in memory is not updated the image does not appear in the PDF.

Please try calling the method below just before saving to PDF:

master.UpdateFields();

2. I'm afraid I didn't quite catch the issue with the bookmark, is there a problem with the spacing?

Thanks,

Thanks for answering my question. It fixed the issue. The second question is related with the first question, it is fixed too.