Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pdf render error #557

Open
hucong730 opened this issue Jan 17, 2024 · 14 comments
Open

pdf render error #557

hucong730 opened this issue Jan 17, 2024 · 14 comments
Labels
type: bug Existing feature doesn't work correctly

Comments

@hucong730
Copy link

hucong730 commented Jan 17, 2024

WX20240117-103314@2x

I used the demo and just replaced the Pdf file. There was a problem with the picture displayed after running.


// Load in an already created PDF
PDDocument document = PDDocument.load(assetManager.open("large.pdf"));

// Create a renderer for the document
PDFRenderer renderer = new PDFRenderer(document);

renderer.setDefaultDestination(RenderDestination.VIEW);

// Render the image to an RGB Bitmap
pageImage = renderer.renderImage(0, 1, ImageType.RGB);

@hucong730 hucong730 added the type: bug Existing feature doesn't work correctly label Jan 17, 2024
@Tlanglord
Copy link

@hucong730 Do you have the original pdf file?

@MikaReesu
Copy link

I got the same issue, while opening a pdf with password. I didn't get that with a pdf without password.

`val inputStream: InputStream = FileInputStream(file)

            // Load in an already created PDF
            val document: PDDocument = PDDocument.load(inputStream, "azerty")
            // Create a renderer for the document
            val renderer = PDFRenderer(document)
            // Render the image to an RGB Bitmap
            val pageImage = renderer.renderImage(0, 1F, ImageType.RGB)

            Handler(Looper.getMainLooper()).post {
                if(pageImage != null){
                    binding.pwdPDFView.setImageBitmap(pageImage)
                } else{
                    Toast.makeText(requireContext(), "Error BITMAP happened", Toast.LENGTH_SHORT).show()
                }
            }
            // Your code to password protect the document will go here
            document.close()`

@Tlanglord
Copy link

@MikaReesu I can try to solve it, can you provide the PDF file?

@MikaReesu
Copy link

MikaReesu commented Feb 2, 2024 via email

@Tlanglord
Copy link

Here the document : Password : azerty

On Fri, Feb 2, 2024, 10:10 LangLord @.> wrote: @MikaReesu https://github.com/MikaReesu I can try to solve it, can you provide the PDF file? — Reply to this email directly, view it on GitHub <#557 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/ATBTBWVSJHS4CN7WQ3BR2GTYRSUPJAVCNFSM6AAAAABB5ZLGHGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMYTSMRTGM3TQMRYHA . You are receiving this because you were mentioned.Message ID: @.>

No pdf found

@MikaReesu
Copy link

Didn't work from Gmail here the pdf.
single_password.pdf

@Tlanglord
Copy link

Didn't work from Gmail here the pdf. single_password.pdf

image

I'm getting a normal rendering here.

@Tlanglord
Copy link

Didn't work from Gmail here the pdf. single_password.pdf

image I'm getting a normal rendering here.

`try {
// Load in an already created PDF
// PDDocument document = PDDocument.load(new File(path),"hi");

        PDDocument document = PDDocument.load(assetManager.open("single_password.pdf"), "azerty");


        // Create a renderer for the document
        PDFRenderer renderer = new PDFRenderer(document);
        // Render the image to an RGB Bitmap
        pageImage = renderer.renderImage(0, 1, ImageType.RGB);

        // Save the render result to an image
        String path2 = root.getAbsolutePath() + "/decrypt_render.jpg";
        File renderFile = new File(path2);
        FileOutputStream fileOut = new FileOutputStream(renderFile);
        pageImage.compress(Bitmap.CompressFormat.JPEG, 100, fileOut);
        fileOut.close();
        tv.setText("Successfully rendered image to " + path2);
        // Optional: display the render result on screen
        displayRenderedImage();
    } catch (IOException e) {
        Log.e("PdfBox-Android-Sample", "Exception thrown while rendering file", e);
    }`

@Tlanglord
Copy link

use :
implementation "com.tom-roush:pdfbox-android:2.0.27.0" , render error
use:
implementation project(':library') (source code) , render fine

@MikaReesu
Copy link

What is that?
implementation project(':library') (source code) , render fine
It doesn't seem to be correct. If it's in gradle it leads to an error :
Project with path ':library' could not be found in project ':app'.
It will be a good idea to put the code directly in Kotlin and also directly in the readme.

I tried with a FILE and an InputStream but it was rendered like I previously showed. Not with all the letters of the text.

About your assetManager, how to initialise it ? In the sample I see a getAssets(), but I didn't find the function in the sample.
val assetManager: AssetManager = getAssets()
This gives an unresolved reference.

I'm getting the PDF from a DocumentPicker, so I can get the path with file.path. Not sure if that is gonna work with all the versions of Android.

@MikaReesu
Copy link

For library, I just found where to add, but why do I need to add the library that way?

implementation "com.tom-roush:pdfbox-android:2.0.27.0"

This should contain everything needed, normally.

Is there a particular reason why, we have to do add the folder library manually?

@Tlanglord
Copy link

What is that? implementation project(':library') (source code) , render fine It doesn't seem to be correct. If it's in gradle it leads to an error : Project with path ':library' could not be found in project ':app'. It will be a good idea to put the code directly in Kotlin and also directly in the readme.

I tried with a FILE and an InputStream but it was rendered like I previously showed. Not with all the letters of the text.

About your assetManager, how to initialise it ? In the sample I see a getAssets(), but I didn't find the function in the sample. val assetManager: AssetManager = getAssets() This gives an unresolved reference.

I'm getting the PDF from a DocumentPicker, so I can get the path with file.path. Not sure if that is gonna work with all the versions of Android.

WX20240207-170357@2x

@Tlanglord
Copy link

For library, I just found where to add, but why do I need to add the library that way?对于库,我刚刚找到了要添加的位置,但为什么我需要以这种方式添加库?

implementation "com.tom-roush:pdfbox-android:2.0.27.0"实现“com.tom-roush:pdfbox-android:2.0.27.0”

This should contain everything needed, normally.通常,这应该包含所需的一切。

Is there a particular reason why, we have to do add the folder library manually?有没有特别的原因,我们必须手动添加文件夹库?

I understand that "com.tom-roush:pdfbox-android:2.0.27.0" is buggy, you can build a new aar based on the master branch of "PDFBox-Android".

@MikaReesu
Copy link

Thank you. I'll be looking for another library. Seems too risky for production app.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug Existing feature doesn't work correctly
Projects
None yet
Development

No branches or pull requests

3 participants