allcolor / YaHP-Converter

YaHP is a Java library that allows you to convert an HTML document into a PDF document.
GNU Lesser General Public License v2.1
56 stars 23 forks source link

urlForBase must be a valid URI. #14

Closed sivasom closed 10 years ago

sivasom commented 10 years ago

Hi,

I am getting below error when trying to test YaHP sample

Initializing... Installing new URLStreamHandlerFactory... Installing new URLStreamHandlerFactory DONE. init time: 141 before conversion Destroying YAHP ClassLoader Tree org.allcolor.yahp.converter.IHtmlToPdfTransformer$CConvertException: urlForBase must be a valid URI. at org.allcolor.yahp.converter.CYaHPConverter.convertToPdf(CYaHPConverter.java:225) at org.allcolor.yahp.sample.CSimpleConversion.main(CSimpleConversion.java:93) An error occurs while converting '' to ''. Cause : urlForBase must be a valid URI. Exception in thread "AWT-Windows" java.lang.IllegalStateException: Shutdown in progress at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:50) at java.lang.Runtime.addShutdownHook(Runtime.java:204) at sun.awt.windows.WToolkit.run(WToolkit.java:277) at java.lang.Thread.run(Thread.java:736)

Below is my code

try {
File fout = new File("C:/Test/test.pdf"); List headerFooterList = new ArrayList(); FileOutputStream out = new FileOutputStream(fout); System.out.println("before conversion"); Map properties = new HashMap(); properties.put(IHtmlToPdfTransformer.PDF_RENDERER_CLASS, IHtmlToPdfTransformer.FLYINGSAUCER_PDF_RENDERER);

        String htmlContent = "<HTML><HEAD></HEAD><BODY><H1>Testing</H1><FORM>" +
                             "check : <INPUT TYPE='checkbox' checked=checked/><br/>"   +
                             "</FORM></BODY></HTML>";
        converter.convertToPdf(htmlContent,
            IHtmlToPdfTransformer.A1P, headerFooterList, "C:/Test/",out,
            properties);
        System.out.println("after conversion");
        out.flush();
        out.close();
    } // end try
    catch (final Throwable t) {
        t.printStackTrace();
        System.err.println("An error occurs while converting '" +
            /*url*/ "' to '"  /*outfile*/ + "'. Cause : " +
            t.getMessage());
        System.exit(-1);
    } // end catch
allcolor commented 10 years ago

Hi,

"C:/Test/" is not correct, you should put "file:///C:/Test/".

Regards, Quentin

2013/10/29 sivasom notifications@github.com

Hi,

I am getting below error when trying to test YaHP sample

Initializing... Installing new URLStreamHandlerFactory... Installing new URLStreamHandlerFactory DONE. init time: 141 before conversion Destroying YAHP ClassLoader Tree org.allcolor.yahp.converter.IHtmlToPdfTransformer$CConvertException: urlForBase must be a valid URI. at org.allcolor.yahp.converter.CYaHPConverter.convertToPdf(CYaHPConverter.java:225) at org.allcolor.yahp.sample.CSimpleConversion.main(CSimpleConversion.java:93) An error occurs while converting '' to ''. Cause : urlForBase must be a valid URI. Exception in thread "AWT-Windows" java.lang.IllegalStateException: Shutdown in progress at java.lang.ApplicationShutdownHooks.add(ApplicationShutdownHooks.java:50) at java.lang.Runtime.addShutdownHook(Runtime.java:204) at sun.awt.windows.WToolkit.run(WToolkit.java:277) at java.lang.Thread.run(Thread.java:736)

Below is my code

try {

File fout = new File("C:/Test/test.pdf"); List headerFooterList = new ArrayList(); FileOutputStream out = new FileOutputStream(fout); System.out.println("before conversion"); Map properties = new HashMap(); properties.put(IHtmlToPdfTransformer.PDF_RENDERER_CLASS, IHtmlToPdfTransformer.FLYINGSAUCER_PDF_RENDERER);

    String htmlContent = "<HTML><HEAD></HEAD><BODY><H1>Testing</H1><FORM>" +
                         "check : <INPUT TYPE='checkbox' checked=checked/><br/>"   +
                         "</FORM></BODY></HTML>";
    converter.convertToPdf(htmlContent,
        IHtmlToPdfTransformer.A1P, headerFooterList, "C:/Test/",out,
        properties);
    System.out.println("after conversion");
    out.flush();
    out.close();
} // end try
catch (final Throwable t) {
    t.printStackTrace();
    System.err.println("An error occurs while converting '" +
        /*url*/ "' to '"  /*outfile*/ + "'. Cause : " +
        t.getMessage());
    System.exit(-1);
} // end catch

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14 .

All those moments will be lost in time, like tears in rain.

sivasom commented 10 years ago

Hi Quentin,

Thanks for reply.

It is working now.

Can please explain what is the use of urlForBase?

But I am not able to open the PDF.

Thanks & Regards, Soma

allcolor commented 10 years ago

It is the base url to decode relative url.

Example if baseURL is file:/C:/Test/:

will translate to

Quentin

2013/10/29 sivasom notifications@github.com

Hi Quentin,

Thanks for reply.

It is working now.

Can please explain what is the use of urlForBase?

But I am not able to open the PDF.

Thanks & Regards, Soma

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27304366 .

All those moments will be lost in time, like tears in rain.

sivasom commented 10 years ago

Not able to open the generated PDF

It is showing error while opening the PDF.

Closed all the streams opened through program for generating the PDF

allcolor commented 10 years ago

I don't understand your question.

2013/10/29 sivasom notifications@github.com

Not able to open the generated PDF

It is showing error while opening the PDF.

Closed all the streams opened through program for generating the PDF

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27314603 .

All those moments will be lost in time, like tears in rain.

allcolor commented 10 years ago

What is the content of the file "test.pdf" ? (open it in a text reader like notepad).

2013/10/29 Quentin Anciaux allcolor@gmail.com

I don't understand your question.

2013/10/29 sivasom notifications@github.com

Not able to open the generated PDF

It is showing error while opening the PDF.

Closed all the streams opened through program for generating the PDF

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27314603 .

All those moments will be lost in time, like tears in rain.

All those moments will be lost in time, like tears in rain.

sivasom commented 10 years ago

By using Sample code I generated the PDF, but while trying to open the PDF it showing the message error while opening the PDF.

HTML conent:-

Soma

Opened in notepad it is showing some content.

sivasom commented 10 years ago

HTML content just printing one message like Soma

allcolor commented 10 years ago

Can you paste here the content of the file "test.pdf" which is generated. Open it in notepad.

2013/10/29 sivasom notifications@github.com

HTML content just printing one message like Soma

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27315142 .

All those moments will be lost in time, like tears in rain.

sivasom commented 10 years ago

error message

%PDF-1.5 %âãÏÓ 1 0 obj <</MediaBox[0 0 1678.31 2358]/Resources<</ProcSet[/PDF/Text/ImageB/ImageC/ImageI]/Font<</F1 2 0 R>>>>/Type/Page/Contents 3 0 R/Parent 4 0 R>> endobj 2 0 obj <</Encoding/WinAnsiEncoding/Type/Font/Subtype/Type1/BaseFont/Times-Bold>> endobj 3 0 obj <</Length 142/Filter/FlateDecode>>stream xœUŽ» A Eûû)µ‰É<t§´,b!,‹£¬¿ï¬IuOrÈí079+² CÂâg‘p´Û´Æn/ÔÀU,©.qRÊÐiv~ —©X}Éã? ×glq-Oú¹Ÿú:“¥’ dGè‹ùðvD9$²ŒÑæ–ck¿…k<Ê(– endstream endobj 4 0 obj <</Count 1/ITXT(2.1.7)/Type/Pages/Kids[1 0 R]>> endobj 5 0 obj <</Pages 4 0 R/Type/Catalog>> endobj 6 0 obj <</ModDate(D:20131029193707+05'30')/Producer(iText 2.1.7 by 1T3XT)/Title(\r\n )/unknown(YaHP Converter v1.3 §20111121 - http://www.allcolor.org/YaHPConverter/ - Flying Saucer Renderer (https://xhtmlrenderer.dev.java.net/\))/CreationDate(D:20131029193707+05'30')/Creator(YaHP Converter v1.3 §20111121)>> endobj xref 0 7 0000000000 65535 f 0000000015 00000 n 0000000172 00000 n 0000000261 00000 n 0000000470 00000 n 0000000533 00000 n 0000000578 00000 n trailer <</Size 7/Root 5 0 R/ID [<4d68dc36d8393f4b2a7113562e3d3b6b><20fb009a8ec1d0a47358b49d3fb109a1>]/Info 6 0 R>> startxref 900 %%EOF

sivasom commented 10 years ago

%PDF-1.5 %âãÏÓ 1 0 obj <</MediaBox[0 0 1678.31 2358]/Resources<</ProcSet[/PDF/Text/ImageB/ImageC/ImageI]/Font<</F1 2 0 R>>>>/Type/Page/Contents 3 0 R/Parent 4 0 R>> endobj 2 0 obj <</Encoding/WinAnsiEncoding/Type/Font/Subtype/Type1/BaseFont/Times-Bold>> endobj 3 0 obj <</Length 142/Filter/FlateDecode>>stream xœUŽ» A Eûû)µ‰É<t§´,b!,‹£¬¿ï¬IuOrÈí079+² CÂâg‘p´Û´Æn/ÔÀU,©.qRÊÐiv~ —©X}Éã? ×glq-Oú¹Ÿú:“¥’ dGè‹ùðvD9$²ŒÑæ–ck¿…k<Ê(– endstream endobj 4 0 obj <</Count 1/ITXT(2.1.7)/Type/Pages/Kids[1 0 R]>> endobj 5 0 obj <</Pages 4 0 R/Type/Catalog>> endobj 6 0 obj <</ModDate(D:20131029193707+05'30')/Producer(iText 2.1.7 by 1T3XT)/Title(\r\n )/unknown(YaHP Converter v1.3 §20111121 - http://www.allcolor.org/YaHPConverter/ - Flying Saucer Renderer (https://xhtmlrenderer.dev.java.net/\))/CreationDate(D:20131029193707+05'30')/Creator(YaHP Converter v1.3 §20111121)>> endobj xref 0 7 0000000000 65535 f 0000000015 00000 n 0000000172 00000 n 0000000261 00000 n 0000000470 00000 n 0000000533 00000 n 0000000578 00000 n trailer <</Size 7/Root 5 0 R/ID [<4d68dc36d8393f4b2a7113562e3d3b6b><20fb009a8ec1d0a47358b49d3fb109a1>]/Info 6 0 R>> startxref 900 %%EOF

allcolor commented 10 years ago

Or can you send it to me at quentin.anciaux@allcolor.org ?

2013/10/29 Quentin Anciaux allcolor@gmail.com

Can you paste here the content of the file "test.pdf" which is generated. Open it in notepad.

2013/10/29 sivasom notifications@github.com

HTML content just printing one message like Soma

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27315142 .

All those moments will be lost in time, like tears in rain.

All those moments will be lost in time, like tears in rain.

allcolor commented 10 years ago

Can you send me the generated file on my email...? seems it contains a pdf.

2013/10/29 sivasom notifications@github.com

%PDF-1.5 %âãÏÓ 1 0 obj <>>>/Type/Page/Contents 3 0 R/Parent 4 0 R>> endobj 2 0 obj <> endobj 3 0 obj <>stream xœUŽ» AEûû)µ‰É

Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27315799 .

All those moments will be lost in time, like tears in rain.

sivasom commented 10 years ago

PDF content sent

some content is there in PDF but not able to open the PDF above error message it is showing

My code

File fout = new File("C:/Test/test.pdf"); List headerFooterList = new ArrayList(); FileOutputStream out = new FileOutputStream(fout); System.out.println("before conversion"); Map properties = new HashMap(); properties.put(IHtmlToPdfTransformer.PDF_RENDERER_CLASS, IHtmlToPdfTransformer.FLYINGSAUCER_PDF_RENDERER);

        String htmlContent = "<html><body><h1>Soma</h1></body></html>";
        converter.convertToPdf(htmlContent,
            IHtmlToPdfTransformer.A1P, headerFooterList, "file:///C:/Test/",out,
            properties);
        System.out.println("after conversion");
        out.flush();
        out.close();
allcolor commented 10 years ago

That means that the file is open by another application.... maybe your JVM is not stopped. Because on windows it can happens it hangs on destroying the classloader. If it is the case, don't use the classloader (by use false as use classloader in the constructor, and put all the jar in the classpath) or kill the VM.

2013/10/29 sivasom notifications@github.com

PDF content sent

some content is there in PDF but not able to open the PDF above error message it is showing

My code

File fout = new File("C:/Test/test.pdf"); List headerFooterList = new ArrayList(); FileOutputStream out = new FileOutputStream(fout); System.out.println("before conversion"); Map properties = new HashMap(); properties.put(IHtmlToPdfTransformer.PDF_RENDERER_CLASS, IHtmlToPdfTransformer.FLYINGSAUCER_PDF_RENDERER);

    String htmlContent = "<html><body><h1>Soma</h1></body></html>";
    converter.convertToPdf(htmlContent,
        IHtmlToPdfTransformer.A1P, headerFooterList, "file:///C:/Test/",out,
        properties);
    System.out.println("after conversion");
    out.flush();
    out.close();

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27316411 .

All those moments will be lost in time, like tears in rain.

sivasom commented 10 years ago

I am able to open PDF in other machine.

I think because of JVM not stopped I am not able to open..

Can you please explain in detail don't use calssloader. I am not using classloader to load any class separately.

allcolor commented 10 years ago

You just have to create the converter like this:

new CYahpConverter(false) instead of new CYahpConverter(true), but that means also that all the jar must be in the classpath (it's the default usage of yahp 1.3 if you're using that version).

Quentin

2013/10/29 sivasom notifications@github.com

I am able to open PDF in other machine.

I think because of JVM not stopped I am not able to open..

Can you please explain in detail don't use calssloader. I am not using classloader to load any class separately.

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27317687 .

All those moments will be lost in time, like tears in rain.

sivasom commented 10 years ago

Thanks Quentin for your reply I am able to open the PDF now.

Few more information is required

1) How to pass the dynamic images like (Pie chart) to YahpConverter? There is no static path for image it will generate on the fly based on the user information

2) How to pass JSP URL to the YahpConverter?

allcolor commented 10 years ago

You have to generate them first on the filesystem for exemple and through templating give the path. I often use velocity as template engine.

So for example you generate your image in a temp directory, you set in your html:

and after the generation is done, you delete the image.

for 2), you can pass any valid URL to yahp.

Quentin

2013/10/30 sivasom notifications@github.com

Thanks Quentin for your reply I am able to open the PDF now.

Few more information is required

1) How to pass the dynamic images like (Pie chart) to YahpConverter? There is no static path for image it will generate on the fly based on the user information

2) How to pass JSP URL to the YahpConverter?

— Reply to this email directly or view it on GitHubhttps://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-27372807 .

All those moments will be lost in time, like tears in rain.

karshad928 commented 9 years ago

file:///C:/Test/ Due to this it throws FileNotFoundException . As well it generates 0 kb size pdf.

allcolor commented 9 years ago

I don't understand your question.

The base URL must of course be correct, why would you expect it to work if you give an invalid base URL ?

2015-09-09 11:03 GMT+02:00 karshad928 notifications@github.com:

file:///C:/Test/ Due to this it throws FileNotFoundException . As well it generates 0 kb size pdf.

— Reply to this email directly or view it on GitHub https://github.com/allcolor/YaHP-Converter/issues/14#issuecomment-138843432 .

All those moments will be lost in time, like tears in rain. (Roy Batty/Rutger Hauer)