Hullo, I'm using ASPOSE Total for .NET and we've a simple requirement to convet the PDF to Word. But We're having to face rough sledding, figuring out the margins.
I am using following code snippet for preparing the demo:
string filePath = @"C:\Data\AdobeXMLFormsSamples.pdf";
if (File.Exists(filePath))
{
Aspose.Pdf.License license = new Aspose.Pdf.License();
license.SetLicense("Aspose.Total.Lic");
Aspose.Words.License wordLicense = new Aspose.Words.License();
wordLicense.SetLicense("Aspose.Total.Lic");
Aspose.Pdf.Document pdf_doc = new Aspose.Pdf.Document(filePath);
filePath = Path.ChangeExtension(Path.GetFullPath(filePath), ".doc");
if (File.Exists(filePath))
File.Delete(filePath);
pdf_doc.Save(filePath, Aspose.Pdf.SaveFormat.Doc);
Aspose.Words.Document word_doc = new Aspose.Words.Document(filePath);
foreach (Section sec in word_doc)
{
sec.PageSetup.LeftMargin = 144.00f;
sec.PageSetup.RightMargin = 144.00f;
}
word_doc.Save(filePath);
Please suggest a way out from this issue, we're having to deal with hundrads of such pop-ups.
Alternatively I could not levarage Microsft.Office.Interop.Word which aspose seem to be using coherently (just a rough guess, I could be wrong here)
object nothing = System.Reflection.Missing.Value;
string filePath = @"C:\data\b0e.doc";
if (File.Exists(filePath))
{
Microsoft.Office.Interop.Word.Application app = new Application();
app.Visible = false;
Microsoft.Office.Interop.Word.Document doc = app.Documents.Open(filePath, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing, nothing);
float left, top, bottom, right;
left = top = bottom = 50.00f;
right = 72.00f;
doc.PageSetup.TopMargin = doc.PageSetup.BottomMargin = doc.PageSetup.LeftMargin = left;
doc.PageSetup.RightMargin = right;
string s = "";
for (int i = 0; i < doc.Sections.Count; i++)
{
try
{
//doc.Sections[i].PageSetup.LeftMargin = left;
//doc.Sections[i].PageSetup.RightMargin = right;
//doc.Sections[i].PageSetup.PaperSize = WdPaperSize.wdPaperLetter;
doc.Sections[i].PageSetup.GutterStyle = WdGutterStyleOld.wdGutterStyleBidi;
}
catch (Exception)
{
continue;
}
}
filePath = Path.GetFileNameWithoutExtension(filePath) + 2 + ".doc";
dll
C:\Program Files (x86)\Aspose\Aspose.Pdf for .NET\Bin\net4.0\Aspose.Pdf.dll ( Runtime Version = v4.0.30319 & Version 7.9.0.0)
C:\Program Files (x86)\Aspose\Aspose.Words for .NET\bin\net2.0\Aspose.Words.dll (Runtime Version v2.0.50727 & Version 13.3.0.0)