We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Get Paper Size

Hi


I’m working with Aspose Cells and Words for .NET.

I’m writing a script that converts Excel and Word documents to PDF.

My problem is that some of the documents are pretty big, which means I need to take Paper Size (e.g. A4 and A3) into consideration and save the documents in the correct Paper Size.

Is that possible?

This is my code to convert the documents:

var docFiles = Directory.GetFiles(inputDir).Where(name => name.EndsWith(".docx") || name.EndsWith(".doc")).ToList();

for (int i = 0; i < docFiles.Count; i++)
{
String name = inputDir + “\cleanup\doc” + i + “.pdf”;
var doc = new Aspose.Words.Document(docFiles[i]);
doc.Save(name);
}

Thank you for your help,
Emil


Hi Emil,

Yes, you can do that. Please check Page Setup and Section Formatting section from http://www.aspose.com/docs/display/wordsnet/Specifying+Formatting for Aspose.Words and Page Setup and Printing Options for Aspose.Cells.

Best Regards,

How do I know which paper size to set? Is there a way to get the paper size or the size of the document?


My problem is that some of the documents are in A4 and some are in A3, so that is why I need to set the paper size dynamically.

Hi Emil,

You can use the same properties to get or set the paper size as you can see in the following code.

Document doc = new Document("Doc1.docx");

DocumentBuilder builder = new DocumentBuilder(doc);

<?xml:namespace prefix = "o" ns = "urn:schemas-microsoft-com:office:office" />

Console.WriteLine(builder.PageSetup.Orientation);

Console.WriteLine(builder.PageSetup.PaperSize);

if (builder.PageSetup.PaperSize == PaperSize.Letter)

{

builder.PageSetup.Orientation = Orientation.Landscape;

builder.PageSetup.LeftMargin = 50;

builder.PageSetup.PaperSize = PaperSize.Paper10x14;

}

Best Regards,

Thank you :slight_smile: