We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Save doc as pdf with images

I am using Aspose.Words (v17.7) and the below code to insert a barcode image (.bmp) onto the bottom of each page of a Word doc, then save it as a pdf. The output pdf does not display the images that were inserted into the Word doc, however, if I save the document as a word file then the images are there if I open it in Microsoft Word. What should be done differently?

            string inputWordDoc = @"C:\Temp\test\Doc_Input.doc";
            string outputPdf = @"C:\Temp\test\Doc_Output_With_Images.pdf";

            Document doc = new Document(inputWordDoc);
            DocumentBuilder builder = new DocumentBuilder(doc);

            List<int> pages = new List<int>();

            double bitmapWidth = ConvertUtil.InchToPoint(0.5f);
            double bitmapHeight = bitmapWidth;

            double top = (builder.PageSetup.PageHeight + builder.PageSetup.TopMargin + builder.PageSetup.BottomMargin) - ConvertUtil.InchToPoint(3.55f);
            double left = 340f;

           LayoutCollector layoutCollector = new LayoutCollector(doc);

            NodeCollection paragraphs = doc.GetChildNodes(NodeType.Paragraph, true);

            foreach (Paragraph para in paragraphs)
            {

                if (!pages.Exists(element => element == layoutCollector.GetStartPageIndex(para)))
                {
                    int pageIndex = layoutCollector.GetStartPageIndex(para);
                    pages.Add(pageIndex);
                    builder.MoveTo(para);
                    builder.InsertImage(
                        getBarcode(pageIndex), 
                        RelativeHorizontalPosition.Page, 
                        left, 
                        RelativeVerticalPosition.Page, 
                        top, 
                        bitmapWidth, 
                        bitmapHeight, 
                        WrapType.None);
                }
            }

            doc.Save(outputPdf);

@malcolmshaneharrison

Thanks for your inquiry. We will appreciate it if you please share your sample input Word document and output PDF document along with sample image. You may ZIP and attach documents to this post, we will look into these and will guide you accordingly.