PDF Margins issue

Hi,


We are trying to retrieve Page margins for a pdf but every time we get the same margin details which is 72,72,90.90. I have created a file in Word with margins as 0.5 inch and also 1 inch, but on converting to pdf when we execute the below code we always get the same values.

As per the below code we are retrieving top, bottom, left and right margins but the value is always 72,72,90.90.

pdfDocument.getPages().get_Item(1).getPageInfo().getMargin().getTop();
pdfDocument.getPages().get_Item(1).getPageInfo().getMargin().getBottom();
pdfDocument.getPages().get_Item(1).getPageInfo().getMargin().getRight();
pdfDocument.getPages().get_Item(1).getPageInfo().getMargin().getLeft();

Can you please guide us how to retrieve the margins set in a pdf file.

Regards,

Hi Carol,


Thanks for contacting support.

Can you please share the input PDF files, so that we can test the scenario in our environment. We are sorry for this inconvenience.

Hi,


Attached is the document.

Regards,

Hi Carol,


Thanks for using our API’s.

I have tested the scenario and have managed to reproduce same problem. For the sake of correction, I have logged it as PDFJAVA-36496 in our issue tracking system. We will further look into the details of this problem and will keep you posted on the status of correction. Please be patient and spare us little time. We are sorry for this inconvenience.

Good afternoon,


I just wanted to add that I’m following this thread (albeit for the .NET version). We have a situation where a Word document is on an A4 papersize, but the margins are setup like a B5 (T:70.9, R:120.5, B:212.65, L:120.5), and we need to detect these margins in the generated PDF.

I have tried several suggestions in the forum (such as using PageSettings (Words) before Saving to PDF and using PdfFileEditor (PDF) on the generated PDF), but none seem to work. The margins always come out as 72,90,72,90 if the papersize is A4. The only way I was able to detect different margins was if I distilled the PDF (using Acrobat) first.

Are you able to provide a workaround sample for my scenario whilst we wait for a fix for the above?

I am using version 17.2.0.0 of both Aspose.Words and Aspose.Pdf (.NET).

Regards,

Nadaav


Nadsy:
Good afternoon,

I just wanted to add that I’m following this thread (albeit for the .NET version). We have a situation where a Word document is on an A4 papersize, but the margins are setup like a B5 (T:70.9, R:120.5, B:212.65, L:120.5), and we need to detect these margins in the generated PDF.

I have tried several suggestions in the forum (such as using PageSettings (Words) before Saving to PDF and using PdfFileEditor (PDF) on the generated PDF), but none seem to work. The margins always come out as 72,90,72,90 if the papersize is A4. The only way I was able to detect different margins was if I distilled the PDF (using Acrobat) first.

Are you able to provide a workaround sample for my scenario whilst we wait for a fix for the above?

I am using version 17.2.0.0 of both Aspose.Words and Aspose.Pdf (.NET).
Hi Nadaav,

Thanks for contacting support.

The issue reported in this thread is related to Aspose.Pdf for Java whereas you are facing problem while using Aspose.Pdf for .NET. Furthermore, we request you to please share your input files, so that we can test the scenario in our environment. We are sorry for your inconvenience.

Hi Nayyer,


Apologies… I added it here, because the symptom was the same. If you would like me to start a new job, please let me know.

In the meantime, I have attached the following files:

1. AsposeTestWord.DOCX: This is an A4 document with margins that simulate a B5;
2. AsposeTestCode.jpg: This is the code used to save the doc to pdf
3. AsposeTestWord.pdf: This is the output pdf of the above code;
4. AsposePdfOutput.jpg: This is the console output of the various properties.

As mentioned previously, I have tried to set the “PageSetup” of each Word section prior to saving to PDF. I have also tried using the “PdfFileEditor” api to “ResizeContents”. Neither of these seem to work.

Regards,

Nadaav.

Hi Nadaav,

Thanks for sharing sample file(s). I have tested the whole scenario at my end and observed that the generated PDF document shows different margin information that that of word. Moreover I have also tried to save your Word Document (AsposeTestWord.docx) as PDF from MS Word as well and checked the margin info of the saved PDF document. The document generated from MS Word also had different margin information. I am also attaching the generated document for your reference.

Please note that Aspose.Words API implements the same functionality as MS Word does which means if you convert a document using Aspose.Words API it will be almost similar as it was converted using Microsoft Word. So this behavior of the API is expected.

Furthermore I have tried to change the margin information of generated PDF document using following code snippet but I have noticed that change in margins was not reflected in the generated output.

Document document = new Document(dataDir + “AsposeTestWord.pdf”);

document.Pages[1].PageInfo.Margin.Top = 144;

document.Pages[1].PageInfo.Margin.Bottom = 144;

document.Pages[1].PageInfo.Margin.Right = 100;

document.Pages[1].PageInfo.Margin.Left = 100;

Therefore I have logged this issue as PDFNET-42376 in our issue tracking system for the sake of detailed investigation. We will further look into the details of this issue and keep you updated on the status of its resolution. Please be patient and spare us a little time. We are sorry for the inconvenience.

Best Regards,

Hi Asad,


Thanks for your response. One further point I wished to make was that if you ‘Printed’ to PDF from word (i.e. with Acrobat distiller), the margins DO show differently.

Not sure if this will help during the investigations, but thought I’d point it out.

Also, is there a way of tracking progress of a job with the job number you provided?

Regards,

Nadaav.

Hi Nadaav,


Thanks for sharing more details and pointing out. I have tried to print the document from MS Word using Adobe PDF printer and noticed the margin changes. For the detailed investigation I have also intimated the relevant team about it.

Nadsy:
is there a way of tracking progress of a job with the job number you provided?

As it is our internal issue logging/tracking system so I am afraid that you cannot keep track progress of the process. But I have associated the issue ID with this thread which means that you will be notified once it is resolved and we will definitely keep you updated about the status as well. Please be patient and spare us a little time.

We are sorry for the inconvenience.


Best Regards,

Hi,

Is there any update on PDFJAVA-36496

Regards,

@nihhhs

Thanks for your inquiry.

After further investigating earlier logged issue we have found it as not a bug in the API. Please note that PageInfo properties are used for PDF generation only (for convenience of API users). PDF format has not page margin as entity but for existing document, you can try to calculate what you need, by analysis such entities as Artbox, BleedBox, CropBox, MediaBox, TrimBox and Rect property.

Please, get more information and code snippets here: Get and Set Page Properties|Aspose.PDF for Java

Hi,

Attach is the pdf document but I am not sure how to calculate the margins since the values are same for the box objects.

ArtBox : Height = 832.0, Width = 682.0, LLX = 0.0, LLY = 0.0, URX = 682.0, URY = 832.0
BleedBox : Height = 832.0, Width = 682.0, LLX = 0.0, LLY = 0.0, URX = 682.0, URY = 832.0
CropBox : Height = 832.0, Width = 682.0, LLX = 0.0, LLY = 0.0, URX = 682.0, URY = 832.0
MediaBox : Height = 832.0, Width = 682.0, LLX = 0.0, LLY = 0.0, URX = 682.0, URY = 832.0
TrimBox : Height = 832.0, Width = 682.0, LLX = 0.0, LLY = 0.0, URX = 682.0, URY = 832.0
Rect : Height = 832.0, Width = 682.0, LLX = 0.0, LLY = 0.0, URX = 682.0, URY = 832.0

Can you please guide me what needs to be done to get the top, left,right and bottom margins.pdfresizer.com-pdf-crop.pdf (31.3 KB)
TestMargins.pdf (32.0 KB)

Regards,

@nihhhs

Thanks for sharing your feedback.

We have logged an investigation ticket as PDFJAVA-38023 to investigate scenario with your shared PDFs. As soon as we make some significant progress towards resolution of the ticket, we will surely share with you. Please spare us little time.

We are sorry for the inconvenience.

@nihhhs

We have investigated the logged ticket and found that for this particular document the ContentBBox could be used. It returns the rectangle containing contents without visible margins.

Rectangle contentBox = pdfPage.calculateContentBBox();
System.out.println("LLX = " + contentBox.getLLX() + ", LLY = " + contentBox.getLLY() + ", URX = " + contentBox.getURX() + ", URY = " + contentBox.getURY());
System.out.println("left = " + (contentBox.getLLX() - pdfPage.getRect().getLLX()) + ", bottom = " + (contentBox.getLLY() -pdfPage.getRect().getLLY()) + 
", right = " + (pdfPage.getRect().getURX() - contentBox.getURX()) + ", top = " + (pdfPage.getRect().getURY() - contentBox.getURY()));