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

Free Support Forum - aspose.com

Orientation not working when exporting to PDF using aspose.words

I was trying to export some data to PDF .I am using Aspose.words 15 .The page orientation and page size property set during design is not getting applied when exported to pdf.this is my code

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

            PageSetup ps = builder.PageSetup;
            ps.PaperSize = PaperSize.Legal;
            ps.Orientation = Aspose.Words.Orientation.Landscape;
            ps.TopMargin = ConvertUtil.InchToPoint(0.5);
            ps.BottomMargin = ConvertUtil.InchToPoint(0.69);
            ps.LeftMargin = ConvertUtil.InchToPoint(0.44);
            ps.RightMargin = ConvertUtil.InchToPoint(0.38);
            ps.HeaderDistance = ConvertUtil.InchToPoint(0.2);
            ps.FooterDistance = ConvertUtil.InchToPoint(0.002);





            builder.Font.ClearFormatting();
            builder.Font.Size = 12;
            builder.Font.Bold = true;
            builder.Font.Color = System.Drawing.Color.Black;
            builder.Font.Name = "Times New Roman";
            builder.CurrentParagraph.ParagraphFormat.Alignment = ParagraphAlignment.Center;
           



       Aspose.Words.Tables.Table  tableMain = builder.StartTable();

            BorderCollection borders = builder.CellFormat.Borders;
            borders.LineStyle = LineStyle.Single;
            borders.LineWidth = 1;
            borders.Color = Color.Black;

            builder.CurrentParagraph.ParagraphFormat.ClearFormatting();
            builder.CellFormat.LeftPadding = 0;
            builder.ParagraphFormat.Alignment = ParagraphAlignment.Center;

            
            builder.RowFormat.HeadingFormat = true;

          
                builder.CellFormat.Shading.BackgroundPatternColor = System.Drawing.Color.FromArgb(226, 239, 217);

                builder.Font.ClearFormatting();
                builder.Font.Size = 9;
                builder.Font.Bold = true;
                builder.Font.Color = System.Drawing.Color.Black;
                builder.Font.Name = "Times New Roman";


                builder.InsertCell();
                builder.CellFormat.Width = ConvertUtil.InchToPoint(Convert.ToDouble("3.5"));


                builder.Writeln("Colummn1");

                builder.InsertCell();
                builder.CellFormat.Width = ConvertUtil.InchToPoint(Convert.ToDouble("3.5"));


                builder.Writeln("Colummn1");

                builder.InsertCell();
                builder.CellFormat.Width = ConvertUtil.InchToPoint(Convert.ToDouble("3.5"));


                builder.Writeln("Colummn1");




                builder.EndRow();

                builder.RowFormat.HeadingFormat = false;

                builder.EndTable();
               
                doc.Save(this.Response, "test.pdf", ContentDisposition.Attachment, Aspose.Words.Saving.DocSaveOptions.CreateSaveOptions(SaveFormat.Pdf));

@AMammen,

Thanks for your inquiry. Please call Document.UpdatePageLayout method before saving document to PDF. This method is automatically invoked when you first convert a document to PDF, XPS, image or print it. However, if you modify the document after rendering and then attempt to render it again - Aspose.Words will not update the page layout automatically. In this case you should call UpdatePageLayout before rendering again.

i used like this.But still not working

doc.UpdatePageLayout();
doc.Save(this.Response, “test.pdf”, ContentDisposition.Attachment, Aspose.Words.Saving.DocSaveOptions.CreateSaveOptions(SaveFormat.Pdf));

@AMammen,

Thanks for your inquiry. We have tested the scenario using latest version of Aspose.Words for .NET 17.7 and have not found the shared issue. Please use Aspose.Words for .NET 17.7. We have attached the output PDF with this post for your kind reference. Out.pdf (14.3 KB)

Thanks for your reply.

Does that mean its a bug in 15.2 version of aspose.words which am using.

We have some limitations in upgrading the dll.Is there any alternative

@AMammen,

Thanks for your inquiry. Please call Document.UpdateTableLayout and Document.UpdatePageLayout method before saving the document. Hope this helps you.

doc.UpdateTableLayout();
doc.UpdatePageLayout();
doc.Save(MyDir + "output.pdf");

Thanks

This also didnt work.

I was trying to upgrade the aspose.words 17.7.But i couldnt find the httpresponse parameter in the save method.How can we create pdf from the response.Or am i missing something?

I tried with Aspose.words 17 .net 4.0 .Still the report is exported in portrait

@AMammen,

Thanks for your inquiry. Please make sure that you are using latest version of Aspose.Words for .NET 17.7. If you still face problem, please share the output PDF that shows the undesired behavior. We will then provide you more information about your query.