Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Just out of curiosity i would like to know if it possible to divide a file such as pdf or a video file into two file files? If yes than how? (asp.net and c#)
Posted

It depends on what do you mean by "divide". If you mechanically split the file itself into two parts, chances are the two results would be invalid, for both PDF and video. For video, in particular, it depends on the video format and codes used, but here is what usually happens: first part (second in not recognized, of course, because there is no header) actually even plays, but, as the file metadata shows wrong length, navigation fails, so the player can even hangs; it actually depends on the player. I think the reason of it is pretty obvious.

If you don't split, but, say, simply create two separate PDF files, and then copy part of content in one file and the rest in another, you will get two valid PDFs. How to do that? Well, there are enough products, Adobe or open-source, and libraries.

To work with PDF, use iText, or its .NET port, iTextSharp:
http://en.wikipedia.org/wiki/IText[^],
http://itextpdf.com/[^],
http://sourceforge.net/projects/itextsharp/[^].

In included the reference to Java iText site as well, because most documentation is there. If you understand C#, it would not be difficult to understand Java-bases API documentation.


With video, the best utility I know is ffMpeg or related libavcodec. Please see:
http://en.wikipedia.org/wiki/Ffmpeg[^],
http://en.wikipedia.org/wiki/Libavcodec[^],
http://ffmpeg.org/[^],
http://libav.org/[^].

Now, how to use it programmatically in a .NET application? First, you can use the available utility by running it using System.Diagnostics.Process.Start:
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx[^].

If this is not good enough, you can wrap the library in a .NET assembly by yourself or find appropriate wrapper. Please see:
http://www.ffmpeg-csharp.com/[^],
http://sourceforge.net/projects/sharpffmpeg/[^],
http://vbffmpegwrapper.codeplex.com/[^].

After all, try to find some more: http://bit.ly/VpboUJ[^].

If you wish to work at such wrapper by yourself but don't know how, ask a question, I'll give you the basic ideas (using P/Invoke or C++/CLI "mixed-mode" project).

Good luck,
—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900