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, September 23, 2010 2:52:39 AM(UTC)
Karla Silveira

Groups: Registered
Posts: 1


My program opens a PDF file that has images that may or may not be compressed, for example TIFF with CCITT Group 4.

I can save the PDF with the compression I want.
But when I open the PDF, I can not know what was the compression used when saving.

Regardless of how the PDF was saved, the property in my case is RasPdfJpeg411 (152), but always returns RasPdf (146).

The version I'm using the LeadTools 16.5.
 

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 : Thursday, September 23, 2010 6:23:16 AM(UTC)

Adam Boulad  
Guest

Groups: Guests
Posts: 3,022

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

LEADTOOLS will load each page of the image as one RasterImage object, converting all text, bitmaps and drawing objects in that page to a single image during loading.
Therefore, LEADTOOLS will always treat the PDF page as a full-color image and will return the information of the PDF as 24-bit RasPdf file. If the page happened to contain a bitmap of a certain pixel depth or compression, there is no way of getting information about individual images or objects in the page.
 
#3 Posted : Wednesday, December 22, 2010 1:22:45 PM(UTC)

Kousay  
Kousay

Groups: Registered
Posts: 6


Hello, we added support for this recently with CodecsRasterPdfInfo and RasterCodecs.GetRasterPdfInfo.

Make sure you have the latest version of Leadtools.Codecs.dll: At least 16.5.5.22 or 17.0.0.9.

This example code is straight out of the documentation. It creates a multi-page PDF with several bits/pixel and compression value, then uses the above methods/classes to split the PDF into multiple single page files with original bits/pixel, resolution, size and compression.

private static void CodecsRasterPdfInfoExample()
{
string multiPageRasterPdfFileName = @"C:\Users\Public\Documents\LEADTOOLS Images\MultiPageRasterPdf.pdf";
string pagesPdfFileNames = @"C:\Users\Public\Documents\LEADTOOLS Images\Page{0}.pdf";
// Create a 4 pages PDF file
CreateMultiPageRasterPdfFile(multiPageRasterPdfFileName);

// Without prior information, we will split this multi-page PDF file into
// multiple single page PDF files with original size, resolution, bit-depth and compression
using(RasterCodecs codecs = new RasterCodecs())
{
// Enable using our own resolution when loading PDF files
codecs.Options.RasterizeDocument.Load.Enabled = true;

int pagesSaved = 0;

// Get the file information
using(CodecsImageInfo imageInfo = codecs.GetInformation(multiPageRasterPdfFileName, true))
{
Console.WriteLine(
"Information: Format:\n Format: {0}\n Pages: {1}\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}",
imageInfo.Format, imageInfo.TotalPages, imageInfo.BitsPerPixel, imageInfo.Width, imageInfo.Height, imageInfo.XResolution, imageInfo.YResolution);
Console.WriteLine("-----------------------");

// Now show the PDF specific information
// Notice: GetInformation will return RasPdf as the format for all PDF files
// regardless of the actual compression
if(imageInfo.Format == RasterImageFormat.RasPdf)
{
Console.WriteLine("Image is PDF, getting the specific info for each page");

for(int i = 0; i < imageInfo.TotalPages; i++)
{
int pageNumber = i + 1;

CodecsRasterPdfInfo pdfInfo = codecs.GetRasterPdfInfo(multiPageRasterPdfFileName, i + 1);
if(pageNumber == 1)
{
Console.WriteLine(" LEAD PDF?: {0}", pdfInfo.IsLeadPdf);
Console.WriteLine(" Version: {0}", pdfInfo.Version);
}

if(pdfInfo.IsLeadPdf)
{
Console.WriteLine(
"Page {0} of {1} info:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}\n Format: {7}",
pageNumber, imageInfo.TotalPages, pdfInfo.BitsPerPixel, pdfInfo.Width, pdfInfo.Height, pdfInfo.XResolution, pdfInfo.YResolution, pdfInfo.Format);
Console.WriteLine("-----------------------");

// Load this page with its original parameters
codecs.Options.RasterizeDocument.Load.XResolution = pdfInfo.XResolution;
codecs.Options.RasterizeDocument.Load.YResolution = pdfInfo.YResolution;
codecs.Options.Pdf.Load.DisplayDepth = pdfInfo.BitsPerPixel;

using(RasterImage pageImage = codecs.Load(multiPageRasterPdfFileName, 0, CodecsLoadByteOrder.BgrOrGray, pageNumber, pageNumber))
{
Console.WriteLine(
"Page {0} of {1} loaded:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}",
pageNumber, imageInfo.TotalPages, pageImage.BitsPerPixel, pageImage.Width, pageImage.Height, pageImage.XResolution, pageImage.YResolution);
Console.WriteLine("-----------------------");

// Setup the PDF save options
codecs.Options.Pdf.Save.UseImageResolution = true;
codecs.Options.Pdf.Save.Version = pdfInfo.Version;

// Save this page to a separate file
string pagePdfFileName = string.Format(pagesPdfFileNames, pageNumber);
codecs.Save(pageImage, pagePdfFileName, pdfInfo.Format, pdfInfo.BitsPerPixel);
pagesSaved++;
}
}
}
}
}

// We are done, now show the info of the generated files
for(int i = 0; i < pagesSaved; i++)
{
int pageNumber = i + 1;
string pagePdfFileName = string.Format(pagesPdfFileNames, pageNumber);

CodecsRasterPdfInfo pdfInfo = codecs.GetRasterPdfInfo(pagePdfFileName, 1);
Console.WriteLine(
"Page {0} of {1} info:\n Bits/Pixel: {2}\n Size: {3} by {4}\n Resolution: {5} by {6}\n Format: {7}",
pageNumber, pagesSaved, pdfInfo.BitsPerPixel, pdfInfo.Width, pdfInfo.Height, pdfInfo.XResolution, pdfInfo.YResolution, pdfInfo.Format);
Console.WriteLine("-----------------------");
}
}
}

private static void CreateMultiPageRasterPdfFile(string pdfFileName)
{
string sourceFile = @"C:\Users\Public\Documents\LEADTOOLS Images\Sample1.cmp";

// Delete the destination PDF file if exists
if(System.IO.File.Exists(pdfFileName))
{
System.IO.File.Delete(pdfFileName);
}

using(RasterCodecs codecs = new RasterCodecs())
{
// Save to PDF v1.4
codecs.Options.Pdf.Save.Version = CodecsRasterPdfVersion.V14;
// Save using image resolution
codecs.Options.Pdf.Save.UseImageResolution = true;

// Load the source file to use for each page
using(RasterImage pageImage = codecs.Load(sourceFile, 0, CodecsLoadByteOrder.BgrOrGray, 1, 1))
{
Console.WriteLine(
"Original image dimension:\n Size: {0} by {1}\n Resolution: {2} by {3}",
pageImage.Width, pageImage.Height, pageImage.XResolution, pageImage.YResolution);

// Array of bits/pixel and compression to use when saving the pages
int[] bitsPerPixel =
{
1,
8,
24
};
RasterImageFormat[] formats =
{
RasterImageFormat.RasPdfG4,
RasterImageFormat.RasPdfLzw,
RasterImageFormat.RasPdfJpeg422
};

int pageCount = bitsPerPixel.Length;
for(int i = 0; i < pageCount; i++)
{
// Append this page with given format
Console.WriteLine("Saving page {0} of {1} using {2} at {3}", i + 1, pageCount, bitsPerPixel[i], formats[i]);
codecs.Save(pageImage, pdfFileName, formats[i], bitsPerPixel[i], 1, 1, -1, CodecsSavePageMode.Append);
}
}

Console.WriteLine("-----------------------");
}
}
 
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-2020, Yet Another Forum.NET
This page was generated in 0.087 seconds.