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

Free Support Forum - aspose.com

Rectangle not drawn- no Error

I’ve tried adding a rectangle to a PDF file using Aspose.Pdf. I’ve tried multiple approaches [using floating box, graph etc.], but the rectanle is never drawn on the document and there are no error messages either.

Here are various code snippets I used, all of them either from the API documentation or support answers from this forum:

Using isoStream As IsolatedStorageFileStream = IsoStore.GetStream(“some path”)
Dim pdf As New Aspose.Pdf.Document(isoStream)
Dim pdfPage As Aspose.Pdf.Page = pdf.Pages(page)

’ with graph
Dim graph As New Aspose.Pdf.Drawing.Graph(CSng(pdfPage.PageInfo.Width), CSng(pdfPage.PageInfo.Height))
pdfPage.Paragraphs.Add(graph)

Dim rectangle As New Aspose.Pdf.Drawing.Rectangle(rect.X, CSng(pdfPage.PageInfo.Height - rect.Y), rect.Width, rect.Height)
rectangle.GraphInfo.FillColor = Aspose.Pdf.Color.Red
graph.Shapes.Add(rectangle)

’ with floating box
Dim box As New Aspose.Pdf.FloatingBox
box.Top = rect.Top
box.Left = rect.Left
pdfPage.Paragraphs.Add(box)
box.Width = rect.Width
box.Height = rect.Height
box.Border = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1, Aspose.Pdf.Color.Black)
box.Paragraphs.Add(New TextFragment(“test”))

pdf.Save()
End Using

Hi Sorin,


Thanks for your inquiry. I have tested your shared code and unable to notice any issue, please find attach sample output. Please share your source document here, so we will test the scenario and will guide you accordingly.

We are sorry for the inconvenience caused.

Best Regards,

It happens with all PDF documents I tried. attached is the last example I used.

Hi,


Thanks for sharing the resource file.

We are testing the scenario using latest file and will get back to you soon.

Hi Sorin,


Thanks for your patience.

I have tested the scenario using latest release of Aspose.Pdf for .NET 11.0.0 in VisualStudio 2015 running over Windows 8.1 Enterprise x64 and I am unable to notice any issue. As per my observations, the TextFragment added inside FloatingBox properly appears. For your reference, I have also attached the output generated over my end. Can you please try using the latest release and in case you still face any issue, please share some details regarding your working environment i.e. Operating System, VisualStudio version, .NET Framework version etc.

We are sorry for your inconvenience.

I downloaded the latest version, but the problem still persists. I’m using Visual Studio 2013 on Windows 7 and I’m developing with .NET 4.0.

Hi,


Thanks for the acknowledgement.

I have again tested the scenario using VisualStudio 2013 with .NET Framework 4.0, where my application is running over Windows 7 (x64) and I am still unable to notice any issue.

[VB.NET]

Dim pdf As New Aspose.Pdf.Document(“c:/pdftest/DB+BAHN±+Verbindungen±+Ihre+Auskunft.pdf_stamp…pdf”)<o:p></o:p>

Dim pdfPage As Aspose.Pdf.Page = pdf.Pages(1)

' with graph

Dim graph As New Aspose.Pdf.Drawing.Graph(CSng(pdfPage.PageInfo.Width), CSng(pdfPage.PageInfo.Height))

pdfPage.Paragraphs.Add(graph)

Dim rectangle As New Aspose.Pdf.Drawing.Rectangle(100, 100, 200, 200) 'rect.X, CSng(pdfPage.PageInfo.Height - rect.Y), rect.Width, rect.Height)

rectangle.GraphInfo.FillColor = Aspose.Pdf.Color.Red

graph.Shapes.Add(rectangle)

' with floating box

Dim box As New Aspose.Pdf.FloatingBox

box.Top = 210 'rect.Top

box.Left = 210 'rect.Left

pdfPage.Paragraphs.Add(box)

box.Width = 100 'rect.Width

box.Height = 100 'ect.Height

box.Border = New Aspose.Pdf.BorderInfo(Aspose.Pdf.BorderSide.All, 1, Aspose.Pdf.Color.Black)

box.Paragraphs.Add(New Aspose.Pdf.Text.TextFragment("test"))

pdf.Save("c:/pdftest/DB+BAHN+-+Verbindungen+-+Ihre+Auskunft.pdf_stamp_FloatingBox_Added.pdf")

Thanks for your answer.

I tried the code in a test project. Now there is a rectangle drawn, just like in your example PDF. However, the location is wrong. I tried using (0, 0) as coordinates, but there are always margin on the top/left side. This happens regardless of whether I use a Rectangle or FloatingBox, although the size of the margins seems to differ.

I have after some testing now realised the reason of it not working was the save operation. As you can see from my code, I open the file as a stream and then simply call Save() on the PDF file. This does not work. The document with the rectangle drawn on it is only saved if I save it in a new location, given as a path.

This is not the way my program operates, as I save all files in the isolated storage and thus can only access them via file streams.

AzraelSeraphin:
I have after some testing now realised the reason of it not working was the save operation. As you can see from my code, I open the file as a stream and then simply call Save() on the PDF file. This does not work. The document with the rectangle drawn on it is only saved if I save it in a new location, given as a path.

This is not the way my program operates, as I save all files in the isolated storage and thus can only access them via file streams.
Hi,

Thanks for sharing the details. I have tested the above scenario and have observed that when using blank Save(..) method, the FloatingBox or Rectangle object are not being displayed. However for the sake of correction, I have logged this problem as PDFNEWNET-39729 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.

However as a workaround, you can save the output in Stream instance where you can pass Stream object as argument to Save(..) method.

Thanks.

Do you have any suggestion on how to handle the coordinate issue? I’ve done some testing and it doesn’t seem to be a static value I can simply add/substract, so any documentation on how this works is appreciated.

AzraelSeraphin:
Do you have any suggestion on how to handle the coordinate issue? I've done some testing and it doesn't seem to be a static value I can simply add/substract, so any documentation on how this works is appreciated.
Hi,

Can you please share some details regarding above stated issue and if possible, please share some sample project/code snippet and resultant PDF generated at your end, so that we can further look into this matter. We are sorry for your inconvenience.

This is the code I use to draw the rectangle:

Dim pdfPage As Aspose.Pdf.Page = pdf.Pages(page)
Dim graph As New Aspose.Pdf.Drawing.Graph(CSng(pdfPage.PageInfo.Width), CSng(pdfPage.PageInfo.Height))
pdfPage.Paragraphs.Add(graph)
Dim rectangle As New Aspose.Pdf.Drawing.Rectangle(rect.X, CSng(pdfPage.PageInfo.Height - rect.Y), rect.Width, rect.Height)

The coordinates and size of rect are determined by mouseclicks on the page.

The
rectangle, however, is never drawn in the locations I clicked. Even
when I click a corner of the page and the coordinates are (0, 0), the
rectangle will be drawn somewhere towards the middle of the page.

In
the attached example file, I have marked roughly the whole page and
passed those coordinates to the function [(0, 6) with a size of
590x825]. As you can clearly see, the rectangle is drawn in a completely
different location. And it doesn’t seem to be simply mirrored or upside down, either.

AzraelSeraphin:
This is the code I use to draw the rectangle:

Dim pdfPage As Aspose.Pdf.Page = pdf.Pages(page)
Dim graph As New Aspose.Pdf.Drawing.Graph(CSng(pdfPage.PageInfo.Width), CSng(pdfPage.PageInfo.Height))
pdfPage.Paragraphs.Add(graph)
Dim rectangle As New Aspose.Pdf.Drawing.Rectangle(rect.X, CSng(pdfPage.PageInfo.Height - rect.Y), rect.Width, rect.Height)

The coordinates and size of rect are determined by mouseclicks on the page.

The rectangle, however, is never drawn in the locations I clicked. Even when I click a corner of the page and the coordinates are (0, 0), the rectangle will be drawn somewhere towards the middle of the page.

In the attached example file, I have marked roughly the whole page and passed those coordinates to the function [(0, 6) with a size of 590x825]. As you can clearly see, the rectangle is drawn in a completely different location. And it doesn't seem to be simply mirrored or upside down, either.
Hi,

Thanks for sharing the details. I have tested the scenario and have observed that Rectangle/FloatingBox are being rendered on different locations when even same coordinates are provided and also the objects are being rendered on location which is different from provided coordinates. For the sake of correction, I have logged it as PDFNEWNET-39741 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.