Convert GdPicturePDF to SaveAsTiff

Discussions about image processing and document imaging.
Post Reply
SMOsama
Posts: 18
Joined: Tue Aug 10, 2021 8:17 pm

Convert GdPicturePDF to SaveAsTiff

Post by SMOsama » Thu Aug 26, 2021 12:18 pm

I have uploaded images from JavasScript using DocuViewareAPI.TwainAcquireToNewDocument and when I want to read that so I use DocuViewareAPI.PostCustomServerAction to read it at server side. At server side I use below code to read uploaded documents

using (GdPictureImaging gdpictureImaging = new GdPictureImaging())
{
GdPictureStatus status;
// First we need to know what kind of document we are dealing with
switch (e.docuVieware.GetDocumentType())
{
// If it is a PDF document...
case DocumentType.DocumentTypePDF:
status = e.docuVieware.GetNativePDF(out GdPicturePDF gdPicturePdf);
break;
}
return result;
}

Now, I want to convert gdPicturePdf object into TIFF File. But I am unable to do that. For my work around what I have done is:
1) First, I convert into pdf and store into local location using gdPicturePdf.ConvertToPDFA().
2) Second, I load from that local location using GdPictureDocumentConverter.
3) Third, I used SaveAsTIFF method of GdPictureDocumentConverter.

I want to do this in one step convert gdPicturePdf to TIFF file and save it in desired location. How can I achieve this? Below is the code of steps that I mentioned of my work around.

using (GdPictureDocumentConverter gdpictureDocumentConverter = new GdPictureDocumentConverter())
{
//First Step
GdPictureStatus status = gdPicturePdf.ConvertToPDFA(tempPdfPath, PdfConversionConformance.PDF_A_1b, true, true);
if (status == GdPictureStatus.OK)
{
//Second Step
status = gdpictureDocumentConverter.LoadFromFile(tempPdfPath, GdPicture14.DocumentFormat.DocumentFormatPDF);
if (status == GdPictureStatus.OK)
{
gdpictureDocumentConverter.RasterizationDPI = 300;
//Third Step
status = gdpictureDocumentConverter.SaveAsTIFF(path, TiffCompression.TiffCompressionAUTO);

User avatar
Fabio
Posts: 173
Joined: Thu Aug 27, 2020 9:57 am

Re: Convert GdPicturePDF to SaveAsTiff

Post by Fabio » Mon Aug 30, 2021 2:01 pm

Hello,

You can get your document as a TIFF instead of PDF at the TWAIN acquisition step using this property: https://www.docuvieware.com/guides/aspn ... ormat.html
You will save the load/save from the GdPictureDocumentConverter class.
After this step, you can save your image and manage the Tiff compression using the GdPictureImaging class: https://www.gdpicture.com/guides/gdpict ... sTIFF.html

Could you elaborate on the first step, please? I do no understand why you convert your PDF to a PDF/a to convert it later into a TIFF.

With best,
Fabio

SMOsama
Posts: 18
Joined: Tue Aug 10, 2021 8:17 pm

Re: Convert GdPicturePDF to SaveAsTiff

Post by SMOsama » Mon Aug 30, 2021 4:56 pm

I have done TwainAcquisitionFormat to "tiff" then using below line of code
e.docuVieware.GetNativeImage(out imageId);
only one page is extracted. But, my problem is that there are multiple pages in tiff file and that above line of code is extracting only one page. How can I extract multiPageTiff.

Sorry, I don't understand that why you have discuss GdPictureDocumentConverter.

Q)Could you elaborate on the first step, please? I do no understand why you convert your PDF to a PDF/a to convert it later into a TIFF?
Ans) Actually that is my question, how can I directly get multi page tiff without saving first it to some location using "gdPicturePdf.ConvertToPDFA(tempLocation)" and then use "gdpictureDocumentConverter.LoadFromFile(tempLocation)" to load and save it using "gdpictureDocumentConverter.SaveAsTIFF(location)". Now, you have tell that to use twainAcquisitionFormat to "tiff". Using that I am not able to extract all pages. Just receiving one page as mentioned above in code using GetNativeImage method. Can you please tell from which method I can extract all pages and save that as tiff file.

SMOsama
Posts: 18
Joined: Tue Aug 10, 2021 8:17 pm

Re: Convert GdPicturePDF to SaveAsTiff

Post by SMOsama » Wed Sep 01, 2021 11:41 am

Even in the DocuVieware folder which is inside of Samples folder there is a Demo app of "aspnet-mvc_razor_app". Kindly see method "HandleImageCleanupAction" in "ImageCleanupDemo.cs". In that method, "GetNativeImage" method is used to retrieve imageId and if we save that imageId using TiffSaveAsMultiPageFile method so it saves only 1 page not all pages of tiff file and as in the sample when the view is loaded we can see that 4 pages are loaded in docuVieware from multipage.tif in ImageCleanup.cshtml. How can we save all pages of tiff file?

Hope, I have cleared my question more now. Can you please give me the solution for this. This is a bit urgent and already we are late on this.

User avatar
Fabio
Posts: 173
Joined: Thu Aug 27, 2020 9:57 am

Re: Convert GdPicturePDF to SaveAsTiff

Post by Fabio » Thu Sep 02, 2021 10:38 am

Hello,

I talked about the GdPictureDocumentConversion class because the provided code snippet you:
- Convert a PDF to a PDF/a (thanks to the GdPicturePDF class)
- You load the output to the GdPictureDocumentConverter object
- Convert your PDF/a to a TIFF file
So basically your document does PDF -> PDF/a -> TIFF, and I wondered why you needed to convert it into a PDF/a before the TIFF conversion.

If you want to directly convert your document as a TIFF you can use this:
Get the loaded file as a stream: https://www.docuvieware.com/guides/aspn ... tData.html
Convert/Save the document as a TIFF: https://www.gdpicture.com/guides/gdpict ... sion).html

With best,
Fabio

SMOsama
Posts: 18
Joined: Tue Aug 10, 2021 8:17 pm

Re: Convert GdPicturePDF to SaveAsTiff

Post by SMOsama » Thu Sep 02, 2021 3:24 pm

I have used this method GetDocumentData() and then call SaveAsTIFF() and this is also saving one page as an image in tiff file and actual result should be to save all pages as an different images in one tiff file because multiple pages are scanned, here I am using twainAcquire method to scan pages that's why GetDocumentData() and SaveAsTIFF() is saving only one page as an image in tiff file.

If I load Multi Page tiff file on load and then use GetDocumentData() and then call SaveAsTIFF() so it works perfectly and it saves multi page tiff file.

My concern is, User will use twainAcquire button again and again to scan pages and at last user will use my custom button and that button will call PostServerAction call to server metho and there I will upload all that scan pages to my server. For that, I need to get/read all pages.

User avatar
Fabio
Posts: 173
Joined: Thu Aug 27, 2020 9:57 am

Re: Convert GdPicturePDF to SaveAsTiff

Post by Fabio » Fri Sep 03, 2021 9:52 am

If your user scans a page, then scans other pages using the option "add to the current document", the provided method should work.
Does your user do it like this or do they scan/save the pages iteratively?

Loading a multipage TIFF or scan multiple pages in the viewer should have the same impact regarding the save method server-side.

Could you explain to me exactly what your user does step by step?
I will check on my side and send you a code snippet that does the job.

With best,
Fabio

fdsosa
Posts: 7
Joined: Wed Apr 19, 2023 10:36 pm

Re: Convert GdPicturePDF to SaveAsTiff

Post by fdsosa » Mon May 15, 2023 6:57 pm

que pena fabio si uno solo quiere convertirlo y no guardarlo con SaveAsTIFF para poder interactuar con el documento cual es el metodo por que revisando solo se puede convertir es guardando el documento

Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest