12 Replies - 432 Views - Last Post: 21 August 2019 - 07:10 AM Rate Topic: -----

#1 fearfulsc2   User is offline

  • D.I.C Regular

Reputation: 16
  • View blog
  • Posts: 276
  • Joined: 25-May 16

Convert Byte Array to PDF

Posted 20 August 2019 - 12:48 PM

Hi everyone, I am working on a project where I am getting documents from a Database. They are stored as blobs in the database and we are converting them to byte arrays when we grab them from the db.

The issue I am facing right now is that I am trying to convert the byte arrays into PDF files using Aspose.PDF. If the file was already a pdf to begin with, there is no issue with trying to save/convert it as a pdf document to display/preview on the front-end.

The issue arises when we have a .txt or any other file that is not strictly a .pdf file. Has anyone been able to implement a solution that works well with Aspose.PDF?

Is This A Good Question/Topic? 0
  • +

Replies To: Convert Byte Array to PDF

#2 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,152
  • Joined: 12-June 08

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 12:57 PM

You should be storing the extensions of the files. That would alleviate confusion and allow you to correctly identify the best path to pulling out the file.

Side note, and I would be remiss if I didn't mention it, databases are a very poor choice as a file storage. It's not their intended use. The better option is to have the files stored in a known path and, instead, write the file name to the db.
Was This Post Helpful? 0
  • +
  • -

#3 fearfulsc2   User is offline

  • D.I.C Regular

Reputation: 16
  • View blog
  • Posts: 276
  • Joined: 25-May 16

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 01:02 PM

We do store the extensions as well. We have no issue in storing them or retrieving them for download. The problem arises when we want to "Preview" the file before downloading it. We can't find a viable way of displaying the contents of the file on the front-end. We can successfully do it for .txt files and .jpg/png/etc.. files but the others will be downloaded such as .docx, .xls, etc....

If we instead try to preview it as pdf, that works too but then we can't display the .txt files and the pictures and they are then downloaded (the front-end developer is having a hard time with that).

I figured that I could try playing with the bytes and convert them to a PDF file on the fly and send it back to the front-end so that we can always preview the file before the user decides to download it(in which case they will download it as the true file type that it is and not the converted pdf preview).

As for storing in the db, our architect has decided to store them all as blobs in a SQL server, so that is something we have already committed to doing.
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,152
  • Joined: 12-June 08

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 01:04 PM

You should throw a few dirt clods at your architect for being bullheaded.

Is this a WinForm? ASP.NET web form? Razor? WPF?
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver   User is offline

  • Code herder
  • member icon

Reputation: 7053
  • View blog
  • Posts: 23,972
  • Joined: 05-May 12

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 01:06 PM

I forgot where the analysis is at now, but there used to be a price per GB comparing storing files in a database vs. files in a NAS with a database pointing to the files. Granted at the time, the analysis was using database for which you needed to pay licensing fees for, but as I recall the pricing was still significant even if you were using a database for free.

Although the analysis was for pricing per GB, you would also need to take into account the throughput of how many bytes per second you can get out of a DB vs. out of a NAS.
Was This Post Helpful? 0
  • +
  • -

#6 fearfulsc2   User is offline

  • D.I.C Regular

Reputation: 16
  • View blog
  • Posts: 276
  • Joined: 25-May 16

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 01:07 PM

we are using Angular as the front-end and are using Rest Services using .NET Core to make calls to and from the database.

This post has been edited by fearfulsc2: 20 August 2019 - 01:08 PM

Was This Post Helpful? 0
  • +
  • -

#7 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,152
  • Joined: 12-June 08

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 01:15 PM

So.. MVC? Razor? *gag* Blazor?
Was This Post Helpful? 0
  • +
  • -

#8 fearfulsc2   User is offline

  • D.I.C Regular

Reputation: 16
  • View blog
  • Posts: 276
  • Joined: 25-May 16

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 01:18 PM

Angular6 front-end makes an API call to our REST service. It's pretty much a WebAPI application on the back-end. We use models and controllers. The views are defined from our Angular.

I'm not sure if I follow your question. We aren't using Razor or Blazor or any of the .NET front-end engines.
Was This Post Helpful? 0
  • +
  • -

#9 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,152
  • Joined: 12-June 08

Re: Convert Byte Array to PDF

Posted 20 August 2019 - 01:19 PM

Aaaaaaaaah. so this is not a webpage, but API shens.
Was This Post Helpful? 0
  • +
  • -

#10 fearfulsc2   User is offline

  • D.I.C Regular

Reputation: 16
  • View blog
  • Posts: 276
  • Joined: 25-May 16

Re: Convert Byte Array to PDF

Posted 21 August 2019 - 05:53 AM

Yes, our front-end developer was trying to make it work just by using the bytes but it only worked for PDFs essentially.

So I figured that I could get the bytes from the DB and then find a way to convert them into a PDF(which is easy to do if they were already from a PDF to begin with) but I found difficulty if they were uploaded from a docx file or anything that was not a pdf.

How have you manipulated the bytes to be a pdf if you have done so before?
Was This Post Helpful? 0
  • +
  • -

#11 modi123_1   User is online

  • Suitor #2
  • member icon



Reputation: 15262
  • View blog
  • Posts: 61,152
  • Joined: 12-June 08

Re: Convert Byte Array to PDF

Posted 21 August 2019 - 06:37 AM

It' not simply just a manipulation of random bytes.. you would need to convert what ever the file is into PDF. Does Aspose.PDF do that for you, or does it just handle existing PDFs?
Was This Post Helpful? 0
  • +
  • -

#12 fearfulsc2   User is offline

  • D.I.C Regular

Reputation: 16
  • View blog
  • Posts: 276
  • Joined: 25-May 16

Re: Convert Byte Array to PDF

Posted 21 August 2019 - 06:48 AM

"Aspose.PDF for .NET supports popular file formats such as PDF, XFA, TXT, HTML, PCL, XML, XPS, EPUB, TEX and image formats as well as allows to create PDF documents directly through the API or via XML templates and can create forms or manage form fields embedded in the PDF documents."

So I think I can convert for some types but I can't do it for Document files and excel and such.
Was This Post Helpful? 0
  • +
  • -

#13 andrewsw   User is offline

  • never lube your breaks
  • member icon

Reputation: 6818
  • View blog
  • Posts: 28,228
  • Joined: 12-December 12

Re: Convert Byte Array to PDF

Posted 21 August 2019 - 07:10 AM

A couple of random ideas. Perhaps you can use a separate, distinct, process of Office automation to open the original docs and save copies as pdf. Or perhaps create an image/screenshot/thumbnail depending on how much of a "preview" you want to provide.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1