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

Free Support Forum - aspose.com

PageSetup Borders not drawn correctly

When I set the border of the PageSetup like this:


s.PageSetup.Borders.LineStyle = LineStyle.Single;
s.PageSetup.Borders.LineWidth = 1;
s.PageSetup.Borders.Color = colors.Text;
s.PageSetup.BorderDistanceFrom = PageBorderDistanceFrom.PageEdge;
s.PageSetup.Borders.DistanceFromText = 0;

the border left and top are rendered with 1px distance to the original border.

Please see example image in attachments.
Is there any way do avoid this?

Thanks in advance.

Hi Dirk,


Please try using the following code:

Document doc = new Document();

Section s = doc.FirstSection;

s.PageSetup.Borders.LineStyle = LineStyle.Single;

s.PageSetup.Borders.LineWidth = 1;

s.PageSetup.Borders.Color = Color.Red;

s.PageSetup.BorderDistanceFrom = PageBorderDistanceFrom.PageEdge;

s.PageSetup.Borders.DistanceFromText = 24;

doc.Save(MyDir + @"16.11.0.docx");


Best regards,
Thank your for your response.
What I actually wanted is that every page has a border. This border should be 1px thick and at the very edge of the page. With your solution the border is 24 units from the page border but it has to be 0.
It is working quite well however you can see at the top and the left there is a 1px black space and the corners are not drawn correctly as there is a pixel standing out.

I hope I could make it clearer.
Hi Dirk,

I have produced attached document using the following code.

Document doc = new Document();

Section s = doc.FirstSection;

s.PageSetup.Borders.LineStyle = LineStyle.Single;

s.PageSetup.Borders.LineWidth = 1;

s.PageSetup.Borders.Color = Color.Red;

s.PageSetup.BorderDistanceFrom = PageBorderDistanceFrom.PageEdge;

s.PageSetup.Borders.DistanceFromText = 0;

doc.Save(MyDir + @"16.11.0.docx");


Do you see the same problem? What MS Word version are you using and at what Zoom level? Please also attach your expected document here for our reference. We will investigate the structure of your expected document as to how you want your final output be generated like. You can create expected document using MS Word 2016.

Best regards,

I have to admit I never saved the document as docx. That way everything works fine. What I am doing exactly is to save every page as an image. So maybe the conversion is the problem.

Here the code for the conversion with setting page border:

var options = new ImageSaveOptions(SaveFormat.Png)
{
PageCount = 1
};

foreach (Section s in doc)
{
s.PageSetup.Borders.LineStyle = LineStyle.Single;
s.PageSetup.Borders.LineWidth = 1;
s.PageSetup.Borders.Color = Color.Yellow;
s.PageSetup.BorderDistanceFrom = PageBorderDistanceFrom.PageEdge;
s.PageSetup.Borders.DistanceFromText = 0;
}

for (var i = 0; i < doc.PageCount; i++)
{
options.PageIndex = i;

using (var imageStream = new MemoryStream())
{
	doc.Save(imageStream, options);
	var ic = new ImageConverter();
	var image = Image.FromStream(imageStream, true);
	var imageAsBytes = (byte[])ic.ConvertTo(image, typeof(byte[]));
	File.WriteAllBytes("D:\\temp\\test" + i + ".png", buffer);
}

}


I also saved the entire document as .docx just to be sure it works as mentioned above.

Hi Dirk,


Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document
  • Aspose.Words generated output document (DOCX) and image files showing the undesired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip them and Click ‘Reply’ button that will bring you to the ‘reply page’ and there at the bottom you can include any attachments with that post by clicking the ‘Add/Update’ button.

Best regards,
The input word document is in the project directory in "Resources".
Any output is in "Resources/Converted".

Thank you very much.
Hi Dirk,

Thanks for your inquiry. For the sake of any correction, we have logged this problem in our issue tracking system as WORDSNET-14491. Our product team will further look into the details of this problem and we will keep you updated on the status of correction. We apologize for your inconvenience.

Best regards,

Hi Dirk,


Problems with border may be related to low resolution of output images.
Please increase resolution. Besides, your code has a lot of overhead. This is simplified code that produces good enough output:

var document = new Document(MyDir + “Lorem
ipsum.docx”
);

// draw a red border around every page

foreach (Section s in document)

{

s.PageSetup.Borders.LineStyle = LineStyle.Single;

s.PageSetup.Borders.LineWidth = 1;

s.PageSetup.Borders.Color = Color.Red;

s.PageSetup.BorderDistanceFrom = PageBorderDistanceFrom.PageEdge;

s.PageSetup.Borders.DistanceFromText = 0;

}

// save document with border

document.Save(MyDir + "BorderDoc.docx");

// conversion

var options = new ImageSaveOptions(SaveFormat.Png)

{

PageCount = 1,

Resolution = 200

};

for (var i = 0; i < document.PageCount; i++)

{

options.PageIndex = i;

document.Save(MyDir + "page-{i}.png", options);

}


Hope, this helps.

Best regards,

That’s a workaround I can live with.

Thank you.
Hi Dirk,

Regarding WORDSNET-14491, our product team has completed the work on your issue and has come to a conclusion that this is not a bug in Aspose.Words. Your issue (WORDSNET-14491) has now been closed with 'Not a Bug' resolution. Please use the workaround mentioned in my previous post.

Best regards,