I have an application that receives a PDF document, and I’m trying to convert it to a Doc, and append to an existing document. It works, but not without some formatting issues.
Is there a way to ensure margins are set properly, on the merge?
Using code sample provided on your site.
WORDS.Document srcDoc = null;
WORDS.ImportFormatMode mode = WORDS.ImportFormatMode.KeepSourceFormatting;
string tempFileName = Path.GetTempFileName();
try
{
if( format == FileFormat.Pdf )
{
// Instantiate the Document object
PDF.Document document = new PDF.Document(stream);
// Create DocSaveOptions object
// Set the recognition mode as Flow
// Set the Horizontal proximity as 2.5
// Enable the value to recognize bullets during conversion process
DocSaveOptions saveOptions = new DocSaveOptions
{
Mode = DocSaveOptions.RecognitionMode.Flow,
RelativeHorizontalProximity = 2.5f,
RecognizeBullets = true
};
// Save the resultant DOC file
document.Save(tempFileName, saveOptions);
srcDoc = new WORDS.Document(tempFileName);
}
else
srcDoc = new WORDS.Document( stream);
// Loop through all sections in the source document.
// Section nodes are immediate children of the Document node so we can just enumerate the Document.
foreach( WORDS.Section srcSection in srcDoc )
{
// Because we are copying a section from one document to another,
// It is required to import the Section node into the destination document.
// This adjusts any document-specific references to styles, lists, etc.
//
// Importing a node creates a copy of the original node, but the copy
// Is ready to be inserted into the destination document.
WORDS.Node dstSection = _document.ImportNode( srcSection, true, mode );
// Now the new section node can be appended to the destination document.
_document.AppendChild( dstSection );
}
return Save( DocumentPath);
}
catch( Exception exception )
{
Console.WriteLine( exception );
throw;
}
finally
{
Utility.FileDelete(tempFileName);
}