Print PDF with specified margins in C# with Aspose.PDF - margins are not being applied correctly

@webmaster6b8e5

We regret to inform you that the ticket has not been resolved yet. We will try to schedule it soon and will inform you as soon as it will be resolved. We really appreciate your patience and comprehension.

2,5 years later. I purchased this product for printing PDF but I cannot print properly. Why is not this prioritized? Is there a misunderstanding?

@webmaster6b8e5

We really apologize for the inconvenience which has been faced.

We have raised the issue priority and will definitely consider your concerns during its investigation. We will soon try to share an ETA or some update regarding issue resolution with you. Please spare us some time.

We are sorry for the inconvenience.

Any ETA on this? I would like to renew but it makes no sense if you are not fixing issues.

@webmaster6b8e5

We would like to share with you that investigation against this issue is already underway and we will surely provide an update as soon as we have some. We really appreciate your patience and cooperation in this matter. Please spare us some time.

We really apologize for the inconvenience.

How is this going? I just renewed your product but no change in this basic feature.

@webmaster6b8e5

Regretfully - due to other high priority implementations - this issue could not get resolved. We apologize for the delay and inconvenience which have been faced. We have already logged your concerns and escalated the issue to next level. We will surely inform you as soon as we have some certain updates regarding its resolution. Please spare us some time.

We are sorry for the inconvenience.

It is related to this property:

viewer.AutoResize = True

When true, printout is too small. When false, printout is too large.

@webmaster6b8e5

Sure, we will surely investigate the ticket from this perspective and let you know about the updates as soon as there are some.

This is getting old and I have renewed hoping for a fix. I am not sure why it takes so much time.

@webmaster6b8e5

Please accept our humble apology for this delay in the resolution of reported issue. We have raised the issue priority while taking care of your concerns and its investigation is in progress. We will update you as soon as we have some news about ETA for its fix. Please spare us little time. We greatly appreciate your patience and cooperation in this matter.

We are sorry for the inconvenience caused.

Any news? This must be the slowest company fixing bugs.3 years later and I cannot print properly.

@webmaster6b8e5

We really regret to inform you that ticket is not yet resolved. As shared earlier, the investigation against the ticket is still underway and it requires more time to get fully analyzed. Along with that, we have also been working over implementing other enhancements and improvements to the API. Nevertheless, we do realize the severity and significance of the issue for you and will update you soon about its resolution ETA. Please give us little time.

We really apologize for the trouble and inconvenience being faced.

@webmaster6b8e5

The investigation against the ticket is completed. The observed behavior is correct, there is no bug. The PDF document page is being printed on the XPS Writer “paper” with no margins from the printer / PdfViewer. But the page itself has its own margins around the content.

If you want to print only the page content without empty spaces, the page should be cropped around its content beforehand, for example by setting its CropBox property. Please refer to the following code snippet:

' We will save the temporary document with cropped pages into this stream
Dim docStream As New System.IO.MemoryStream()

Dim doc As New Document("C:\Pdf\test81\Input.pdf")
Dim page As Page = doc.Pages(1)
' Crop the page by setting its CropBox equal to the bounding box of visible content
page.CropBox = page.CalculateContentBBox()
' Save the cropped document into a stream
doc.Save(docStream)

' Create a PdfViewer for the cropped document
Dim viewer As New PdfViewer()
viewer.BindPdf(docStream)
' You may consider setting AutoResize to True to make the printed content fill the paper
' viewer.AutoResize = True

' Do not produce the page number dialog when printing
' Create objects for printer and page settings and PrintDocument
Dim ps As New Aspose.Pdf.Printing.PrinterSettings()

' Set printer name
ps.PrinterName = "Microsoft XPS Document Writer"
ps.DefaultPageSettings.Margins.Bottom = 0
ps.DefaultPageSettings.Margins.Top = 0
ps.DefaultPageSettings.Margins.Left = 0
ps.DefaultPageSettings.Margins.Right = 0

' Print document using printer and page settings
viewer.PrintDocumentWithSettings(ps)

' Close the PDF file after printing
viewer.Close()