I have previously embbeded images in documents using LinQ syntax. However I would like to know whether is it possible to do the same using another document.
Let’s assume we have a Word/PDF document instead of an image and we want our process to insert that document in the generated document. Is this possible?
This is the syntax I currently use in order to insert images:
<<image [imagePath] -fitSizeLim>>
I’m looking for something similar that works for any kind of compatible document.
@VictorMDiego Sure, you can insert another document into the report using LINQ Reporting Engine. Please see our documentation for more information:
https://docs.aspose.com/words/net/inserting-documents-dynamically/
1 Like
@alexey.noskov this is exactly what we were looking for. However we have found some documents are displayed in a weird way. We have some users that uploaded a PDF (paper file digitalization) and this document is broken when inserted in the generated file.
This is a preview of the PDF file (some text is censored with black boxes):
This is how it is viewed in the generated file - it is broken:
Is it possible to insert a document avoiding this issues?
@VictorMDiego Could you please attach your sample input documents here for testing? We will check the issue and provide you more information.
Also, please note, Aspose.Words is designed to work with MS Word documents. MS Word documents are flow documents and they have structure very similar to Aspose.Words Document Object Model. On the other hand PDF documents are fixed page format documents. While conversion PDF document to MS Word document Fixed Page Document structure into the Flow Document Object Model. Unfortunately, such conversion does not guaranty 100% fidelity. So it is not always possible to retain PDF document layout upon conversion it to MS Word document.
@alexey.noskov this is the file:
Would it be possible to internally convert the PDF to a image file (png/jpg) and then show that image in the generated file? This might help solve the issue with PDF files.
Botella inicio uso 29-9-23.pdf (36.9 KB)
@VictorMDiego Thank you for additional information. Actually your PDF document contains a single image. If insert it into an empty document using the following code, the image is inserted properly:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.Write("<<doc [documentPath]>>");
ReportingEngine engine = new ReportingEngine();
engine.BuildReport(doc, @"C:\Temp\in.pdf", "documentPath");
doc.Save(@"C:\Temp\out.docx");
You can use the following code to convert PDF to images using Aspose.Words:
Aspose.Words.Pdf2Word.FixedFormats.PdfFixedRenderer pdfRenderer = new Aspose.Words.Pdf2Word.FixedFormats.PdfFixedRenderer();
using (FileStream pdfStream = File.OpenRead(@"C:\Temp\in.pdf"))
{
IReadOnlyList<Stream> images = pdfRenderer.SavePdfAsImages(pdfStream);
for (int frameIdx = 0; frameIdx < images.Count; frameIdx++)
{
using (Stream imgStream = images[frameIdx])
using (FileStream imgFile = File.Create(string.Format(@"C:\Temp\out_{0}.png", frameIdx)))
{
imgStream.CopyTo(imgFile);
}
}
}
Also, you can use Aspose.PDF to convert PDF to image.
https://docs.aspose.com/pdf/net/convert-pdf-to-images-format/