officefileapi-119894-word-processing-document-api-examples-export-how-to-export-an-image-to-pdf-format.md
Follow the steps below to use the RichEditDocumentServer to export an inline image to PDF format:
using (RichEditDocumentServer server = new RichEditDocumentServer())
{
//Insert an image
DocumentImage docImage = server.Document.Images.Append(DocumentImageSource.FromFile("Image.jpg"));
//Adjust the page width and height to the image's size
server.Document.Sections[0].Page.Width = docImage.Size.Width + server.Document.Sections[0].Margins.Right + server.Document.Sections[0].Margins.Left;
server.Document.Sections[0].Page.Height = docImage.Size.Height + server.Document.Sections[0].Margins.Top + server.Document.Sections[0].Margins.Bottom;
//Export the result to PDF
using (FileStream fs = new FileStream("result.pdf", FileMode.OpenOrCreate))
{
server.ExportToPdf(fs);
}
}
Using server As New RichEditDocumentServer()
'Insert an image
Dim docImage As DocumentImage = server.Document.Images.Append(DocumentImageSource.FromFile("Image.jpg"))
'Adjust the page width and height to the image's size
server.Document.Sections(0).Page.Width = docImage.Size.Width + server.Document.Sections(0).Margins.Right + server.Document.Sections(0).Margins.Left
server.Document.Sections(0).Page.Height = docImage.Size.Height + server.Document.Sections(0).Margins.Top + server.Document.Sections(0).Margins.Bottom
'Export the result to PDF
Using fs As New FileStream("result.pdf", FileMode.OpenOrCreate)
server.ExportToPdf(fs)
End Using
End Using