Welcome Guest! To enable all features, please Login or Register.

Notification

Icon
Error

Options
View
Last Go to last post Unread Go to first unread post
#1 Posted : Thursday, October 1, 2020 9:33:59 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Dear Team,

I have a 5MB PDF. I'm loading this using RasterCodecs and saving the same PDF to my disk. And if I notice the saved PDF, the size changes to 350MB.

Here is the code I'm using:

Code:

using (RasterCodecs codecs = new RasterCodecs())
{
    codecs.Options.Load.AllPages = true;
    using CodecsImageInfo info = codecs.GetInformation(file, true);
    RasterImage image = codecs.Load(file);
    codecs.Save(image, @$"{currentPath}\pdf2pdf.pdf", RasterImageFormat.RasPdfLzw, info.BitsPerPixel);
    image.Dispose();
}


Please use the PDF from the following link https://edutechlearners....ithms-3rd%20Edition.pdf. This is the PDF that I have used. Please assist on what I'm missing and how to reduce 1:70 ratio..



Thanks,
Abdul Rahman
 

Try the latest version of LEADTOOLS for free for 60 days by downloading the evaluation: https://www.leadtools.com/downloads

Wanna join the discussion? Login to your LEADTOOLS Support accountor Register a new forum account.

#2 Posted : Friday, October 2, 2020 10:01:05 AM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

Was thanked: 3 time(s) in 3 post(s)

Hello Abdul,

I took a look at the source PDF file and notice that it is a vector PDF(searchable). Since you are using RasterCodecs, the output PDF file is going to be a raster PDF, which will increase the file size by a lot. The 5MB vector PDF converting to ~350MB raster PDF is expected behavior. Typically, the only way that you can reduce the file size would be the compression type, which you are already using the best for this file format, the physical size (height & width), or the bits per pixel (currently saving as 24 BPP). Is there a reason that you are wanting to rasterize the PDF file? What is your use-case?

Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
#3 Posted : Friday, October 2, 2020 10:06:18 AM(UTC)
Abdul Rahman

Groups: Registered
Posts: 60


Dear Matt,

My use case is that I have PDF files stored in my file system. And annotations were stored separately in database. If the file has annotations then I need to rasterize the pdf to burn annotations. If not I just need to return the original file. So how to programmatically identify of the file is vector PDF and is there any other way to load/compress vector PDF? Also how to burn annotations if the PDF is a vector PDF?

Thanks,
Abdul Rahman
 
#4 Posted : Friday, October 2, 2020 1:59:59 PM(UTC)
Matthew Bresson

Groups: Registered, Tech Support, Administrators
Posts: 98

Was thanked: 3 time(s) in 3 post(s)

Hello Abdul,

Unfortunately, there is no direct function to call that will tell you if your PDF file is searchable or not. However with that said I do have a pipeline that you can use that should indicate if the PDF is vector or not. First load your file as a PDFDocument.
https://www.leadtools.co.../dh/pdf/pdfdocument.html
Then you will want to call the ParsePages method, but only call the ParsePages method on the first page.
https://www.leadtools.co...document-parsepages.html
Now you will check the PDFDocumentPage.Objects collection.
https://www.leadtools.co...ocumentpage-objects.html
If the collection has more than 1 object, then typically this means it is a vector PDF. Collections with only one object and the ObjectType being Image, typically means it is a raster PDF. Note that is the PDFDocumentPage.Objects returns 1 object and it being an SVG object that means it could be a vector PDF.
https://www.leadtools.co...ocumentpage-objects.html

The best way to load your vector PDF and export the vector PDF with the best compression, you can use the DocumentConverter class, since the Document Converter uses Raster, SVG, and OCR engines to convert the data with the best possible output file format and compression.
https://www.leadtools.co...c/documentconverter.html

Regarding burning annotations to your vector PDF, you will need to load your annotation files and their AnnContainers into an AnnContainer[] array.
https://www.leadtools.co...v20/dh/ac/anncodecs.html
Then you will need to load your vector PDF as a LEADDocument. Then you will need to use the SetAnnotations method to set the AnnContainer[] array to the pages of the LEADDocument.
https://www.leadtools.co...ions-setannotations.html
Once you have done this, you can then "finalize" the document by running it through the Document Converters. Ensure that you set the AnnotationsMode to Embed, as this will embed the annotation containers to the vector PDF file.
https://www.leadtools.co...ata-annotationsmode.html

If you have any questions please let me know as I am aware I sent you a lot of information above and many documentation links.

Thanks
Matt Bresson
Developer Support Engineer
LEAD Technologies, Inc.
LEADTOOLS
 
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.

Powered by YAF.NET | YAF.NET © 2003-2024, Yet Another Forum.NET
This page was generated in 0.205 seconds.