Loading...

Standardize resolution of images in PDF

General discussions about GdPicture.NET.

Standardize resolution of images in PDF

Postby lbleicher » Fri Nov 04, 2011 9:52 pm

Hi All-

I have an application that must receive scanned documents at various resolutions, and I want to standardize (at 150dpi) the images. There is one image per page.

I have tried the following:
Code: Select all
        If InputPDF.LoadFromFile(pdfPath, False) = GdPicture.GdPictureStatus.OK Then
            For i As Integer = 1 To InputPDF.GetPageCount()
                'j2kPath = Mid(pdfPath, 1, Len(pdfPath) - 4) & "pg" & i & ".j2k"
                InputPDF.SelectPage(i)
                rastPage = InputPDF.RenderPageToGdPictureImage(150, False)
                Dim image_res_name As String = InputPDF.AddImageFromGdPictureImage(rastPage, False, False)
                myPage.ReleaseGdPictureImage(rastPage)
                executedGdPCmd = InputPDF.ClearPageContent()
                InputPDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
                InputPDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch)
                InputPDF.DrawImage(image_res_name, 0, 0, 8.5, 11)
                ' myPage.SaveAsJ2K(rastPage, j2kPath, 32)
            Next i
            InputPDF.SaveToFile(OutputFilePath)
        Else
            'report out reason for problem.
            Dim errCode As Integer = InputPDF.GetStat()
              ...
        End If
        InputPDF.CloseDocument()


However, this simply gives ma a blank PDF that is larger (in bytes on disk) than the original. What am I doing wrong?

I am able to write to disk the individual pages as j2ks, so the rasterization seems to work.

Thanks for your help,
Leo
lbleicher
 
Posts: 13
Joined: Fri Nov 04, 2011 4:51 am

Re: Standardize resolution of images in PDF

Postby Loïc » Sat Nov 05, 2011 7:34 pm

Hi Leo,

This problem will be solved in the next release.
Waiting for, a workaround consists to comment this line:

InputPDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)

With best regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4442
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Standardize resolution of images in PDF

Postby Loïc » Sat Nov 05, 2011 7:36 pm

Hi,

By the way, I suggest you to start a new PDF from scratch to reduce the output file size.

Kind regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4442
Joined: Tue Oct 17, 2006 10:48 pm
Location: France

Re: Standardize resolution of images in PDF

Postby lbleicher » Tue Nov 08, 2011 2:31 am

Hi Loic-

Thanks for the quick and helpful response.

I now have a working module:
Code: Select all
 executedGdPCmd = OutputPDF.NewPDF(True)  'Should make PDF/A file

        'get some info about the document
        If InputPDF.LoadFromFile(pdfPath, False) = GdPicture.GdPictureStatus.OK Then
            For i As Integer = 1 To InputPDF.GetPageCount()
                InputPDF.SelectPage(i)
                pageImages = InputPDF.GetPageImageCount()
                If pageImages = 1 Then
                    curPageImage = InputPDF.ExtractPageImage(1)
                    inPgPD = myPage.GetBitDepth(curPageImage)
                    inPgHP = myPage.GetHeight(curPageImage)
                    inPgHI = myPage.GetHeightInches(curPageImage)
                    inPgWP = myPage.GetWidth(curPageImage)
                    inPgWI = myPage.GetWidthInches(curPageImage)
                    myPage.ReleaseGdPictureImage(curPageImage)

                    hDPI = inPgHP / inPgHI
                    wDPI = inPgWP / inPgWI
                    curDPI = System.Math.Max(hDPI, wDPI)

                    newDPI = System.Math.Min(curDPI, 150)
                Else
                    newDPI = 150
                End If
                rastPage = InputPDF.RenderPageToGdPictureImage(newDPI, False)
                executedGdPCmd = myPage.ConvertTo1Bpp(rastPage)

                Dim image_res_name As String = OutputPDF.AddImageFromGdPictureImage(rastPage, False, False)
                myPage.ReleaseGdPictureImage(rastPage)
                ' NOT NEEDED InputPDF.SetOrigin(PdfOrigin.PdfOriginTopLeft)
                OutputPDF.SetMeasurementUnit(PdfMeasurementUnit.PdfMeasurementUnitInch)
                OutputPDF.NewPage(inPgWI, inPgHI)
                OutputPDF.DrawImage(image_res_name, 0, 0, inPgWI, inPgHI)
            Next i
            OutputPDF.SaveToFile(OutputFilePath)
        Else
            'report out reason for problem.
            Dim errCode As Integer = InputPDF.GetStat()
        End If
        InputPDF.CloseDocument()


However, I now have a new problem. Acrobat Professional v8 thinks that the resulting document '...is damaged and needs repair.'


The PDF/A report says the following:

Creation Date mismatch between Document Info and XMP metadata
Document is damaged and needs repair
PDF contains data after end of file marker
Document information
File name: "1013288_Compress.pdf"
Path: "D:\Clients\AcclerysServices\DuPont\TestDataSourceFolder\Confidential"
PDF version number: "1.4"
File size 246.06 KB (251968 Bytes)
Creator: "GdPicture Managed PDF Plugin"
Producer: "GdPicture Managed PDF Plugin Ver. 1.000014"
Created: "11/7/2011 4:06 PM"
Trapping: "Unknown"
Additional actions: Not present
Number of plates: 1
Names of plates: "(Black) "
Environment
Preflight, 8.1.0 (237)
Acrobat version: 8.10
Operating system: Microsoft Windows Home Edition (Build 7600)


Any idea what might cause all these PDF/A issues (in Acrobat's estimation) on a newly created file?

Thanks,
Leo
lbleicher
 
Posts: 13
Joined: Fri Nov 04, 2011 4:51 am

Re: Standardize resolution of images in PDF

Postby Loïc » Tue Nov 08, 2011 10:21 am

Hi Leo,

Please replace:

Code: Select all
OutputPDF.NewPage(inPgWI, inPgHI) 
OutputPDF.DrawImage(image_res_name, 0, 0, inPgWI, inPgHI)


by:

Code: Select all
OutputPDF.NewPage(inPgWI, inPgHI)
OutputPDF.SelectPage(i)
OutputPDF.DrawImage(image_res_name, 0, 0, inPgWI, inPgHI)


Also, you should check the return value of the function you are using, that will help you to catch error and get some useful information.

Kind regards,

Loïc
Loïc Carrère, support team.
www.orpalis.com
User avatar
Loïc
Site Admin
 
Posts: 4442
Joined: Tue Oct 17, 2006 10:48 pm
Location: France


Return to General discussions

Who is online

Users browsing this forum: No registered users and 1 guest