Landscape setup problems

Hello,


I’m using Aspose 10.3.0 to create Word-documents.

A typical document I’m generating consists of one page in portrait-mode and one in landscape-mode.

I’ve got a few problems with the landscape-setup:
- Whenever I setup a page to be landscape, an extra (portrait)-page is added in front of the landscape-oriented page. This does not happen when the page is in portrait-mode.
This also prevents me from printing the landscape page only; nothing happens. When I print both the extra generated page AND the third page, they are being sent to the printer.
Code I use:

pageUren.PageInfo.IsLandscape = true;


- Whenever I setup a page to be landscape, and set it up to be A4-size, MS Word does not recognise it as being A4. This does not happen when the page is in portrait-mode. Width and height are simply flipped (20.99 x 27.4 cm), but the paper size is set to ‘custom’. This way, the page is not being printed because of not being A4. When manually setting the page size to A4 in word, the problem is solved.

Code I use:
pageUren.PageInfo.Width = Aspose.Pdf.Generator.PageSize.A4Width;
pageUren.PageInfo.Height = Aspose.Pdf.Generator.PageSize.A4Height;


- Finally, it also seems that the margins created by Aspose, are interpreted by MS Word as being 0 in every direction. While the text is on the right place, the margins of the page aren’t.

Code I’m using for the page margins:
Aspose.Pdf.Page page = document.Pages.Add();
Aspose.Pdf.MarginInfo marginInfo = new Aspose.Pdf.MarginInfo();
marginInfo.Top = 20d;
marginInfo.Left = 20d;
marginInfo.Right = 20d;
marginInfo.Bottom = 20d;
page.PageInfo.Margin = marginInfo;

Code I’m using for the header margins:
Aspose.Pdf.HeaderFooter hfHeader = new Aspose.Pdf.HeaderFooter();
hfHeader.Margin.Top = 30d;
hfHeader.Margin.Left = 20d;
hfHeader.Margin.Right = 20d;
hfHeader.Margin.Bottom = 20d;
Aspose.Pdf.Text.TextFragment titletext = new Aspose.Pdf.Text.TextFragment(doctitle);
titletext.HorizontalAlignment = Aspose.Pdf.HorizontalAlignment.Right;
hfHeader.Paragraphs.Add(titletext);
page.Header = hfHeader;

Attached are portrait and landscape examples.

Thanks in advance,

Peter

Hi Peter,


Thanks for your inquiry. As your query is related to Aspose.Pdf, I am moving your request in Aspose.Pdf forum where you’ll be guided appropriately.

Best regards,

Thanks Awais.


After upgrading Aspose to the current version, one of the problems got fixed:
A white page is no longer created in between the two pages; The second page can still only be printed together with the first. Printing only the second does nothing.

Hi Peter,


Thanks for contacting support.

Can you please share if you are generating MS Word files by converting PDF documents to DOCX format using Aspose.Pdf for .NET and also you are setting the page orientation/dimensions in PDF document instead specifying the information in MS DOCX file.

Also please share if you are facing issue while printing MS Word files or facing problem while printing PDF documents and if you printing the documents using our API’s or printing them directly through printers from operating system.

Please share the details, so we may reply accordingly.

Hi Nayyer,

To your second question: I’m printing the Word-document via MS-Word to a system printer; not via the Aspose API.

The first question I can’t answer directly; I think I’m converting PDF to Word.

I use:

Aspose.Pdf.Document document = new Document();

document.Save(fileName, SaveFormat.DocX);

Within this Aspose.pdf.document, I set a page orientation, as mentioned before:

Aspose.Pdf.Page pageUren = document.Pages.Add();

[//pageUren.PageInfo.IsLandscape](https://pageuren.pageinfo.islandscape/) = true;

[//pageUren.PageInfo.Width](https://pageuren.pageinfo.width/) = Aspose.Pdf.Generator.PageSize.A4Width;

[//pageUren.PageInfo.Height](https://pageuren.pageinfo.height/) = Aspose.Pdf.Generator.PageSize.A4Height;

If you need more details, please let me know.

Hi Peter,

Thanks for sharing the details.

Do you face issues when printing MS Word files using Aspose.Words ? i.e. Extra page being printed or margin not being honored.

It appears that you have created PDF documents using Aspose.Pdf and have set the margin information which is being treated as 0 when viewing the MS Word file created by Aspose.Pdf in MS Word. If so is the case, then please share the complete code snippet to generate PDF file using Aspose.Pdf and in case you are manipulating any existing PDF file, please share the resource PDF document.

In order to change page orientation, you may consider using following suggestions. Please note Rotation property changes orientation of entire page including its contents. In order to change page size you can set MediaBox of the page in the following way.

Document doc = new Document("PdfWithText.pdf");
foreach (Page page in doc.Pages)
{
    Aspose.Pdf.Rectangle r = page.MediaBox;
    double newHeight = r.Width;
    double newWidth = r.Height;
    double newLLX = r.LLX;
    //we must to move page upper in order to compensate changing page size (lower edge of the page is 0,0 and information is usually placed from the top of the page. That’s why we move lover edge upper on difference between old and new height.
    double newLLY = r.LLY + (r.Height - newHeight);
    page.MediaBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
    //sometimes we also need to set CropBox (if it was set in original file)
    page.CropBox = new Aspose.Pdf.Rectangle(newLLX, newLLY, newLLX + newWidth, newLLY + newHeight);
}
doc.Save("36115.pdf");

Please note that in that case you can cut some contents of the document (because we decrease height)
in order to avoid this you can increase width proportionally and leave height intact as following:

Aspose.Pdf.Rectangle r = page.MediaBox;
//new height the same
double newHeight = r.Height;
//new width is expanded proportionally to make orientation landscape (we assume that previous orientation is portrait)
double newWidth = r.Height * r.Height / r.Width;

Other option is to use PdfPageEditor facade (it can apply zoom to page contents)

Document doc = new Document("PdfWithText.pdf");
Aspose.Pdf.Rectangle r = doc.Pages[1].Rect;
PdfPageEditor ppe = new PdfPageEditor();
ppe.BindPdf("PdfWithText.pdf");
ppe.Zoom = (float)(r.Width / r.Height);
ppe.PageSize = new Aspose.Pdf.PageSize((float)r.Height, (float)r.Width);
ppe.Save("36115-1.pdf");

Hi Nayyer,


Thanks for your response.

To be clear: My goal is to generate Word-documents, NOT PDF.
Since Aspose PDF can do this, (apart from the couple of errors) , this was the solution i used.

I’ll try to work out my solution in Aspose Words, to see if I get less trouble.

I wouldn’t be surprised if all problems can be solved by doing so.

I’ll keep you updated.

Peter

Hi Peter,


Sure. Please continue using our API’s and should you have any further query, please feel free to contact.

Hi,


Another problem I’m facing:

When I create a table with many rows, I want it to continue on the next page when it gets over a certain height.

Thus, I check with :
if (double.Parse(tableUren.GetHeight().ToString()) > 120) {
(create new page, table etc)
}

However, from the moment I take the table height (tableUren.GetHeight()) , my cellstyling (font, padding etc) change.

Creating table via:
Aspose.Pdf.Table tableUren = new Aspose.Pdf.Table();
tableUren.ColumnWidths = “5%”;
tableUren.DefaultCellTextState.Font = FontRepository.FindFont(font);
tableUren.DefaultCellTextState.FontSize = 8;
tableUren.DefaultCellTextState.FontStyle = FontStyles.Regular;

Adding row via : Aspose.Pdf.Row hourRow = tableUren.Rows.Add();

I’ve added examples of document with and without the problem.

Anyone got an idea?

Thanks!

Peter85:
Hi,

Another problem I’m facing:

When I create a table with many rows, I want it to continue on the next page when it gets over a certain height.

Thus, I check with :
if (double.Parse(tableUren.GetHeight().ToString()) > 120) {
(create new page, table etc)
}

However, from the moment I take the table height (tableUren.GetHeight()) , my cellstyling (font, padding etc) change.

Creating table via:
Aspose.Pdf.Table tableUren = new Aspose.Pdf.Table();
tableUren.ColumnWidths = “5%”;
tableUren.DefaultCellTextState.Font = FontRepository.FindFont(font);
tableUren.DefaultCellTextState.FontSize = 8;
tableUren.DefaultCellTextState.FontStyle = FontStyles.Regular;

Adding row via : Aspose.Pdf.Row hourRow = tableUren.Rows.Add();

I’ve added examples of document with and without the problem.

Anyone got an idea?

Thanks!
Hi Peter,

I have tested the scenario and I am able to
notice the same problem. For the sake of correction, I have logged this problem
as PDFNEWNET-39378 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.