This forum contains outdated content and is available for reading only. Please contact technical support if you have any questions.

Notification

Icon
Error

Options
Go to last post Go to first unread
enicolasgomez  
#1 Posted : Saturday, November 29, 2014 6:39:13 AM(UTC)
enicolasgomez

Rank: Member

Groups: Guest
Joined: 11/19/2014(UTC)
Posts: 10

Thanks: 4 times
Hello,

wrote the following code to produce text. This is a module in a MVC controller which is called from a webpage that sends all of those parameters using ajax and renders back to a Canvas element. I have two problems with the following approach:

  • Using PdfWriter (which is the only vector based graphic interface) so I need to convert it to SVG before sending back to Canvas

  • Writes to an actual physicall file which makes the process slow, would like to know if I can do this in a memory stream or any other similar in-memory data structure

Is there any way to improve this approach?

Code:
var aFont = "Arial";
var aFontSize = 24f;
var aText = "Graphics Mill by Aurigma";
var aColor = System.Drawing.Color.Blue;
 
System.Drawing.RectangleF blackBox;
 
var dpi = 150f;
using (var bitmap = new Bitmap(1, 1, PixelFormat.Format24bppRgb))
{
    bitmap.DpiX = dpi; 
    bitmap.DpiY = dpi;
    using (var lGraphics = bitmap.GetAdvancedGraphics())
    {
        var lFont = lGraphics.CreateFont(aFont, aFontSize);
        var lBrush = new SolidBrush(aColor);
        var lText = new PlainText(aText, lFont, lBrush);
        lText.Position = new System.Drawing.PointF(0f, 0f);
        blackBox = lText.GetBlackBox();
    }
}
 
 
using (var lPdfWriter = new PdfWriter(@"c:\eps\out.pdf"))
using (var lGraphics = lPdfWriter.GetGraphics())
{
    lPdfWriter.AddPage((int)Math.Ceiling(blackBox.Width), (int)Math.Ceiling(blackBox.Height), dpi, dpi);
    {
        var lFont = lGraphics.CreateFont(aFont, aFontSize);
        var lBrush = new SolidBrush(aColor);
        var lText = new PlainText(aText, lFont, lBrush)
        {
            Position = new System.Drawing.PointF(0, - blackBox.Y)
        };
        lGraphics.DrawText(lText);
    }
}
Fedor  
#2 Posted : Monday, December 1, 2014 4:31:10 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Quote:
Using PdfWriter (which is the only vector based graphic interface) so I need to convert it to SVG before sending back to Canvas

Do you need to send it to HTML5 Canvas or to Ajax Vector Objects Canvas? Can you send a raster image instead of SVG?

Quote:
Writes to an actual physicall file which makes the process slow, would like to know if I can do this in a memory stream or any other similar in-memory data structure

You can pass an instance of the type System.IO.Stream to the constructor of reader or writer:

Quote:
using(var memStream = new MemoryStream())

using (var lPdfWriter = new PdfWriter(memStream ))

Best regards,

Fedor Skvortsov

thanks 1 user thanked Fedor for this useful post.
enicolasgomez on 12/1/2014(UTC)
enicolasgomez  
#3 Posted : Monday, December 1, 2014 4:41:16 AM(UTC)
enicolasgomez

Rank: Member

Groups: Guest
Joined: 11/19/2014(UTC)
Posts: 10

Thanks: 4 times
Originally Posted by: Fedor Go to Quoted Post
Quote:
Using PdfWriter (which is the only vector based graphic interface) so I need to convert it to SVG before sending back to Canvas

Do you need to send it to HTML5 Canvas or to Ajax Vector Objects Canvas? Can you send a raster image instead of SVG?

I need to send a bunch of vectors as user will be able to manipulate it and then send this commands to a cutter. So 2nd option is the one I'm looking for, Ajax Vector Objects Canvas.

Edited by moderator Monday, December 1, 2014 4:46:57 AM(UTC)  | Reason: Not specified

Fedor  
#4 Posted : Monday, December 1, 2014 5:03:33 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Quote:
I need to send a bunch of vectors as user will be able to manipulate it and then send this commands to a cutter. So 2nd option is the one I'm looking for, Ajax Vector Objects Canvas.

Well, it seems you need to recreate the graphics using the API of Ajax Vector Objects. I don't see a robust way to use the same API for writing of PDF file and building of Ajax Vector Objects' graphics.

Probably you could build your graphics using Ajax Vector Objects and than export to PDF.

http://www.graphicsmill.com/doc...and-rendering-canvas.htm

If it doesn't fit your needs please describe your requirements in details. Probably I could offer you some workaround.

Best regards,

Fedor Skvortsov

thanks 1 user thanked Fedor for this useful post.
enicolasgomez on 12/1/2014(UTC)
enicolasgomez  
#5 Posted : Monday, December 1, 2014 5:14:17 AM(UTC)
enicolasgomez

Rank: Member

Groups: Guest
Joined: 11/19/2014(UTC)
Posts: 10

Thanks: 4 times
Originally Posted by: Fedor Go to Quoted Post
Quote:
I need to send a bunch of vectors as user will be able to manipulate it and then send this commands to a cutter. So 2nd option is the one I'm looking for, Ajax Vector Objects Canvas.

Well, it seems you need to recreate the graphics using the API of Ajax Vector Objects. I don't see a robust way to use the same API for writing of PDF file and building of Ajax Vector Objects' graphics.

Probably you could build your graphics using Ajax Vector Objects and than export to PDF.

http://www.graphicsmill.com/doc...and-rendering-canvas.htm

If it doesn't fit your needs please describe your requirements in details. Probably I could offer you some workaround.

Well, I'm not interested in PDF at all. I'm just using it beacuse it's the only interface that I've found for creating text and that would output vectors, if I had a SvgWritter I would have used it with a memory stream and send back to Canvas.

Does it make sense?

Fedor  
#6 Posted : Monday, December 1, 2014 5:36:13 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Quote:
Well, I'm not interested in PDF at all. I'm just using it beacuse it's the only interface that I've found for creating text and that would output vectors, if I had a SvgWritter I would have used it with a memory stream and send back to Canvas.

Thank you for your explanation.

Why don't you create vector graphics using the API of Ajax Vector Objects?

http://www.graphicsmill....working-with-objects.htm

Best regards,

Fedor Skvortsov

thanks 1 user thanked Fedor for this useful post.
enicolasgomez on 12/1/2014(UTC)
enicolasgomez  
#7 Posted : Monday, December 1, 2014 5:44:44 AM(UTC)
enicolasgomez

Rank: Member

Groups: Guest
Joined: 11/19/2014(UTC)
Posts: 10

Thanks: 4 times
Awesome, that looks exactly what I'm looking for.

But it looks like CurvedText is the only option and I'm very interested in all the other effects like brige, is that possible?

Fedor  
#8 Posted : Monday, December 1, 2014 5:51:26 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Originally Posted by: enicolasgomez Go to Quoted Post
Awesome, that looks exactly what I'm looking for.

But it looks like CurvedText is the only option and I'm very interested in all the other effects like brige, is that possible?

Currently it is not possible. I will discuss it with our engineers and will let you know.

Best regards,

Fedor Skvortsov

enicolasgomez  
#9 Posted : Monday, December 1, 2014 5:57:31 AM(UTC)
enicolasgomez

Rank: Member

Groups: Guest
Joined: 11/19/2014(UTC)
Posts: 10

Thanks: 4 times
OK, that's bad news.

Can you let me know which is the best to accomplish my requirement from the performance point of view? Saving a PDF locally and using a 3rd party tool for converting to SVG, reading the file and sending SVG commands back to canvas is very slow.

enicolasgomez  
#10 Posted : Monday, December 1, 2014 12:14:04 PM(UTC)
enicolasgomez

Rank: Member

Groups: Guest
Joined: 11/19/2014(UTC)
Posts: 10

Thanks: 4 times
Found a pretty neat solution by doing the following:

  • At server side, using PdfWriter with a MemoryStream instance instead of a file.

  • In my MVC class serializing the MemoryStream to a base64 string and sending this to the client

  • On the client side I use Fabric.js for Canvas plus Mozilla's PDF.JS with PDF2JS module (http://pramodhkp.github.io/pdf2svg/)

This decreased the process time from 3111 milliseconds to just 14, so I increased the overall efficency 222 times. :D

Fedor  
#11 Posted : Wednesday, December 3, 2014 8:53:36 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Originally Posted by: enicolasgomez Go to Quoted Post
Awesome, that looks exactly what I'm looking for.

But it looks like CurvedText is the only option and I'm very interested in all the other effects like brige, is that possible?

We have discussed it with our developers. We will implement in January 2015.

Best regards,

Fedor Skvortsov

Fedor  
#12 Posted : Wednesday, December 3, 2014 8:54:14 AM(UTC)
Fedor

Rank: Advanced Member

Groups: Guest
Joined: 7/28/2003(UTC)
Posts: 1,660

Thanks: 5 times
Was thanked: 76 time(s) in 74 post(s)
Originally Posted by: enicolasgomez Go to Quoted Post
Found a pretty neat solution by doing the following:

  • At server side, using PdfWriter with a MemoryStream instance instead of a file.

  • In my MVC class serializing the MemoryStream to a base64 string and sending this to the client

  • On the client side I use Fabric.js for Canvas plus Mozilla's PDF.JS with PDF2JS module (http://pramodhkp.github.io/pdf2svg/)

This decreased the process time from 3111 milliseconds to just 14, so I increased the overall efficency 222 times. :D

Great! I will recommend this approach to our users.

Best regards,

Fedor Skvortsov

Users browsing this topic
Guest (9)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.