Hi Aspose,
I am using version 14.12. (latest version)
I have created a document by docx - html - docx using.
When i open the document in word and print it from Word everything is perfect.
When i open the document in word and saveas PDF, everything is perfect.
When the document is loaded with Aspose.Words and then saved as PDF with Aspose.Words, the PDF is saved with extra left/right margins.
When the docx document is printed with Aspose.Words, then Aspose.Words makes the same extra margins on the left and right.
I have attached the following files,
- The converted docx file (convertedfiletest.docx)
- The converted docx file savedas PDF in word (convertedfiletest.pdf)
I have also added our code which saves the document as pdf and the code that print out the document with aspose.words.
The pdf code,
public byte[] GetDocumentAsPdf(byte[] data)
{
SetAsposeWordsLicense();
Aspose.Words.Document wordsDocument = CreateDocument(data);
return ConvertDocumentToBytes(wordsDocument, true, Aspose.Words.SaveFormat.Pdf);
}
public Aspose.Words.Document CreateDocument(byte[] documentFile, Aspose.Words.LoadOptions loadOptions = null)
{
Aspose.Words.Document wordsDocument;
using (var mStream = new MemoryStream(documentFile))
{
wordsDocument = (loadOptions != null) ? new Aspose.Words.Document(mStream, loadOptions) : new Aspose.Words.Document(mStream);
}
return wordsDocument;
}
private byte[] ConvertDocumentToBytes(Aspose.Words.Document mergedDocument, bool convertToPdf, Aspose.Words.SaveFormat saveFormat)
{
using (var ms = new MemoryStream())
{
mergedDocument.Save(ms, convertToPdf ? Aspose.Words.SaveFormat.Pdf : saveFormat);
byte[] documentBytes = ms.ToArray();
return documentBytes;
}
}
And the printing code,
public void PrintDocument(string FileName)
{
var doc = new Document(FileName);
var printDocument = new AsposeWordsPrintDocument(doc);
SetPrinterSettingsOnDocument(printDocument.PrinterSettings, settings);
if (printDocument.PrinterSettings.IsValid)
{
try
{
printDocument.Print();
}
catch (Exception ex)
{
Logger.Exception(ex); // not include in example
throw;
}
}
}
public void SetPrinterSettingsOnDocument(PrinterSettings documentPrinterSettings, PrinterSettings printerSettings)
{
documentPrinterSettings.Copies = printerSettings.Copies;
documentPrinterSettings.PrinterName = printerSettings.PrinterName;
documentPrinterSettings.DefaultPageSettings.Landscape = printerSettings.DefaultPageSettings.Landscape;
}
Best Regards,
Jakob Petersen
Team Lead
Edora A/S