We are experiencing issues converting docs to PDFs. For the most part they work but we have had isseus with:
Headers and Footers
Watermarks
Line Breaks.
I have attached some samples of the docs and the onverted PDFs. Here is the code being used:
Document doc = new Document(sourceFileFullPath);
// Declare Memory Streams
using(System.IO.MemoryStream xmlStream = new MemoryStream())
{
using(System.IO.MemoryStream pdfStream = new MemoryStream())
{
// Save the document in Aspose.Pdf.Xml format.
doc.SaveOptions.PdfExportImagesFolder = Path.GetTempPath();
doc.Save(xmlStream, SaveFormat.AsposePdf);
// Read the document in Aspose.Pdf.Xml format into Aspose.Pdf.
Aspose.Pdf.Pdf pdf = new Aspose.Pdf.Pdf();
pdf.BindXML(xmlStream, null);
// Instruct to delete temporary image files.
pdf.IsImagesInXmlDeleteNeeded = true;
// Produce the PDF file.
pdf.Save(destinationFileFullPath);
}
}
Thanks for your request. Currently Aspose.Words supports two ways of PDF conversion: direct conversion (without using Aspose.Pdf) and legacy conversion (Aspose.Words+Aspose.Pdf). See the following link for more information: https://docs.aspose.com/words/net/convert-a-document-to-pdf/
So, you can try using new method to convert your document to PDF. Here is the code:
Document doc = new Document("in.doc");
doc.SaveToPdf("out.pdf");
In this case the output PDF documents looks much better.
Best regards.
Thank you for additional information. Line breaks are missed because there are SmartTags in the paragraphs. I linked this thread to the appropriate issue.
As a workaround, you can try removing SmartTags from the document before converting to PDF. Here is code:
Document doc = new Document(@"Doc.doc");
RemoveSmartTags(doc);
doc.SaveToPdf(@"out.pdf");
///
/// Removes all SmartTYag nodes from the docuemnt, preserving content
///
/// Input document
private void RemoveSmartTags(Document doc)
{
// Get collection of SmartTags from the document
NodeCollection nodes = doc.GetChildNodes(NodeType.SmartTag, true, true);
// Loop while there is SmartTags in the document
while (nodes.Count> 0)
{
SmartTag tag = (SmartTag) nodes[0];
// Get parent node of smartTag.
// we should move all content from smatrTag to its parent to preserve documents content
CompositeNode parent = tag.ParentNode;
// Loop throuht all nodes inside smartTag and move its convent to parent node
while (tag.HasChildNodes)
parent.InsertBefore(tag.FirstChild, tag);
// Remove smartTag
tag.Remove();
}
}
Thanks for your inquiry. This code resolves the problem with address box.
There is also problem with text frame in the header. Currently, Aspose.Words does not fully support positioning of frames during rendering and converting to PDF.
As a workaround, you can try using textboxes instead of frames.
Best regards.
It destroys the format and it does not give roman page numbering correcly. Binding XML gives correct output but it is expensive in memory wise.
Is there any enhancement we can do with pdf’s XML binding?
Thanks for your inquiry. The only thing you can do is refactoring of your document.
IF you would like to improve performance, you can try setting IsTruetypeFontMapCached option of Aspose.Pdf. http://www.aspose.com/documentation/file-format-components/aspose.pdf-for-.net-and-java/aspose.pdf.pdf.istruetypefontmapcached.html
Best regards.
Thank’s,
But I have millions of documents, I can not change the existing document.
Is it possible to replace the frames by textboxes with the object nodes dynamically?
It’s really important, we are really interested in your product.
Best regards.
Thanks for your request. Unfortunately, there is no way to replace frames with text boxes programmatically. You can do this only manually in MS Word.
Best regards.
@Febinbabu As I can see your goal is simple Word to PDF conversion. There is no need to use Aspose.PDF for this. You can achieve this using the following simple code:
Aspose.Words.Document srcDoc = new Aspose.Words.Document(fileName);
srcDoc.Save(pdfOutPutStream, Aspose.Words.SaveFormat.Pdf);